OpenAI Codex CLI builds its startup instruction chain by scanning $CODEX_HOME (~/.codex) and walking from the Git root to your working directory, selecting at most one file per folder in AGENTS.override.md → AGENTS.md → project_doc_fallback_filenames order until reaching the 32 KiB project_doc_max_bytes cap. Pair those layers with ~/.codex/<name>.config.toml profiles to isolate workspace overrides.
How Does OpenAI Codex CLI Discover AGENTS.md and AGENTS.override.md?
OpenAI Codex CLI constructs a single sequential instruction chain once at session startup by checking $CODEX_HOME first and then walking from the project root down to your current working directory. Inside every directory along that path, Codex CLI includes at most one non-empty instruction file in strict precedence order: AGENTS.override.md, then AGENTS.md, then any filenames listed in project_doc_fallback_filenames.
Because Codex CLI concatenates discovered files from the outer global directory inward toward the subdirectory where you launched the terminal, instructions closest to your working directory appear last in the compiled system context and override broader guidance above them. In the OpenAI Codex AGENTS.md configuration guide, OpenAI documents the cutoff rule explicitly: "Codex skips empty files and stops adding files once the combined size reaches the limit defined by project_doc_max_bytes (32 KiB by default)."
Two edge cases trip up engineers managing large monorepos in OpenAI Codex CLI:
- Empty files do not block fallback: If a directory contains a 0-byte
AGENTS.override.md, Codex CLI skips that empty file and falls through toAGENTS.mdor the fallback array rather than suppressing instructions. - Missing project root falls back to CWD only: Codex CLI locates the project root using Git markers or custom filenames defined in
project_root_markersinside~/.codex/config.toml. If no root marker exists above your terminal path, Codex CLI reads only the global file and the current directory.
Global vs. Repository Override Hierarchy and Fallback Filenames
An AGENTS.override.md file replaces only the AGENTS.md file inside the exact same directory level, leaving parent and child folders untouched. That per-directory replacement semantics lets engineers override root monorepo conventions inside a single microservice folder—or temporarily override personal defaults inside ~/.codex/AGENTS.override.md—without touching shared team files tracked in Git.
When legacy repositories already standardize on filenames such as TEAM_GUIDE.md or .agents.md, adding project_doc_fallback_filenames in ~/.codex/config.toml lets OpenAI Codex CLI read those existing documents only when neither AGENTS.override.md nor AGENTS.md exists in that directory:
~/.codex/
├── config.toml # Sets project_doc_max_bytes and fallback filenames
├── AGENTS.md # Personal defaults loaded across every repo
└── AGENTS.override.md # Temporary personal override (replaces ~/.codex/AGENTS.md)
my-monorepo/ (Git Root)
├── AGENTS.md # Loaded after global scope
├── TEAM_GUIDE.md # Ignored here because AGENTS.md exists in root
└── services/
└── billing/
├── AGENTS.md # Ignored because AGENTS.override.md is in billing/
└── AGENTS.override.md # Selected for billing/; appears last in Codex promptTo wire fallback filenames globally without renaming legacy files across 15 repositories, declare the ordered array in ~/.codex/config.toml and restart Codex CLI so the discovery list reloads:
# ~/.codex/config.toml
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536How Do ~/.codex/config.toml and --profile Files Layer Settings?
OpenAI Codex CLI resolves runtime settings across seven ordered configuration layers, placing standalone profile files ($CODEX_HOME/<name>.config.toml) above your base ~/.codex/config.toml and below trusted project .codex/config.toml files. Passing codex --profile review merges your named profile overlay without forcing you to edit global defaults or commit personal preferences into a shared repository.
As documented in the OpenAI Codex Config Basics documentation, profile files live directly beside config.toml inside $CODEX_HOME rather than inside inline TOML tables. Project trust also gates local overrides: "If you mark a project as untrusted, Codex skips project-scoped .codex/ layers, including project-local config, hooks, and rules. User and system config still load, including user/global hooks and rules."
| Priority | Configuration Layer | Canonical Path / Flag | Merge & Trust Scope |
|---|---|---|---|
| 1 (Highest) | CLI flags and --config (-c) overrides | codex -c project_doc_max_bytes=65536 | Applies for that single invocation; overrides TOML files in trusted and untrusted repos. |
| 2 | Project config files (closest directory wins) | <git-root>/.codex/config.toml ... $PWD/.codex/config.toml | Loaded from root down to CWD only when projects.<path>.trust_level is trusted. |
| 3 | Selected named profile overlay | $CODEX_HOME/<profile-name>.config.toml (--profile) | Standalone file next to config.toml; layers task-specific model, sandbox, or byte caps. |
| 4 | User base configuration | ~/.codex/config.toml (or $CODEX_HOME/config.toml) | Personal defaults across all repos; still loads when a repository is marked untrusted. |
| 5 | Cloud-managed workspace defaults | Signed-in workspace config.toml delivery | Organization-delivered defaults when signed in to a managed ChatGPT/Codex workspace. |
| 6 | System configuration (Unix) | /etc/codex/config.toml | Machine-wide administrator defaults beneath user and profile settings. |
| 7 (Lowest) | Built-in Codex CLI defaults | Codex binary defaults (e.g., 32 KiB project_doc_max_bytes) | Fallback values when no config layer sets the key. |
The OpenAI Codex Configuration Reference also notes that host-owned and provider keys—including profile, profiles, openai_base_url, and otel—are ignored inside project-local .codex/config.toml files. Keep model providers, telemetry, and reusable permission profiles (:read-only, :workspace, :danger-full-access, or custom [permissions.<name>] tables) inside user-level ~/.codex/config.toml or dedicated profile files such as ~/.codex/audit.config.toml:
# ~/.codex/audit.config.toml (invoke with: codex --profile audit)
approval_policy = "on-request"
default_permissions = ":read-only"
project_doc_max_bytes = 65536
project_doc_fallback_filenames = ["SECURITY.md", "TEAM_GUIDE.md"]Why Does project_doc_max_bytes Silently Drop Nested Codex CLI Rules?
Because project_doc_max_bytes caps the cumulative byte total of every loaded AGENTS.md and AGENTS.override.md at 32 KiB (32,768 bytes) by default, an oversized global or root file exhausts the budget before OpenAI Codex CLI reaches nested subdirectory overrides. Codex CLI halts chain assembly quietly once the ceiling hits, leaving your deepest service rules absent from the session without throwing an error (see our cross-agent diagnostic guide on why AI coding agents silently ignore rules files).
Developers routinely diagnose this failure by assuming AGENTS.override.md syntax is broken, when the actual fault is byte exhaustion higher up the tree. Run the POSIX audit script below from any subdirectory to trace the exact discovery chain OpenAI Codex CLI evaluates, see which single file wins each folder, and flag cumulative chains that exceed 32,768 bytes:
#!/usr/bin/env bash
set -euo pipefail
CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"
MAX_BYTES="${CODEX_MAX_BYTES:-32768}"
TOTAL_BYTES=0
pick_doc() {
local dir="$1"
for candidate in "AGENTS.override.md" "AGENTS.md"; do
local path="$dir/$candidate"
if [[ -f "$path" && -s "$path" ]]; then
echo "$path"
return 0
fi
done
}
echo "=== Codex CLI AGENTS.md Discovery Audit (cap: $MAX_BYTES bytes) ==="
if global_doc=$(pick_doc "$CODEX_DIR"); then
bytes=$(wc -c < "$global_doc" | tr -d ' ')
TOTAL_BYTES=$((TOTAL_BYTES + bytes))
printf " [global] %6d B %s\n" "$bytes" "$global_doc"
fi
ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
REL=${PWD#"$ROOT"}
CUR="$ROOT"
IFS='/' read -ra PARTS <<< "$REL"
for segment in "" "${PARTS[@]}"; do
[[ -n "$segment" ]] && CUR="$CUR/$segment"
if repo_doc=$(pick_doc "$CUR"); then
bytes=$(wc -c < "$repo_doc" | tr -d ' ')
TOTAL_BYTES=$((TOTAL_BYTES + bytes))
status="OK"
(( TOTAL_BYTES > MAX_BYTES )) && status="TRUNCATED/DROPPED"
printf " [repo] %6d B %s (%s)\n" "$bytes" "$repo_doc" "$status"
fi
done
echo "Total cumulative bytes: $TOTAL_BYTES / $MAX_BYTES"After trimming bloated prose or raising project_doc_max_bytes in ~/.codex/config.toml, verify the live compiled instruction chain directly inside OpenAI Codex CLI using non-interactive inspection and TUI logging:
# Confirm exact merged guidance from repository root or nested subdir
codex --cd services/billing --ask-for-approval never "List active instruction sources and headings."
# Capture plaintext TUI logs to verify loaded configuration layers
codex -c log_dir=./.codex-logThe Sprawl Moment: When a Local Override Fixes One Repo and Breaks Two Others
During a Friday production migration, you drop a temporary AGENTS.override.md inside a nested payment-worker directory and bump project_doc_max_bytes = 65536 inside your desktop's ~/.codex/config.toml so Codex CLI stops dropping your database safety checks. Everything passes on that workstation. On Monday morning, you open a second laptop to hotfix a sibling service, switch to Cursor for frontend cleanup and Claude Code for test generation, and realize the hard way that the temporary override stayed untracked on the first machine, the 64 KiB cap never made it to your second ~/.codex/config.toml, and neither Cursor nor Claude Code reads your Codex profile rules at all.
How Do Codex CLI Overrides Compare With Claude Code, Cursor, and Antigravity?
Every major AI coding agent enforces different directory scopes, override precedence rules, and hard byte or token ceilings, so raw AGENTS.md chains rarely translate cleanly when you switch tools. While OpenAI Codex CLI uses root-to-CWD concatenation capped at 32 KiB, Claude Code relies on lazy-loaded SKILL.md directories, Cursor evaluates .cursor/rules/*.mdc glob triggers, and Google Antigravity enforces cumulative 24 KB per-file and 20,000-token aggregate budgets.
| Coding Agent | Global Scope Path | Repo Override Mechanism | Hard Size / Token Cap | Silent Failure Mode |
|---|---|---|---|---|
| OpenAI Codex CLI | $CODEX_HOME/AGENTS.override.md or AGENTS.md | AGENTS.override.md > AGENTS.md > fallback list per dir | 32 KiB (32,768 bytes) cumulative project_doc_max_bytes | Stops appending deeper subdirectory files once 32 KiB cap fills |
| Anthropic Claude Code | ~/.claude/CLAUDE.md & ~/.claude/skills/<name>/SKILL.md | CLAUDE.md + .claude/skills/ + managed-settings.json | SKILL.md <= 500 lines; 1% context window skill listing cap | Oversized SKILL.md wastes active reasoning window; unindexed skills drop |
| Cursor IDE | Cursor User Rules (local app settings) + ~/AGENTS.md | .cursor/rules/*.mdc (globs & alwaysApply) + AGENTS.md | Recommended <= 500 lines per .mdc rule file | Multiple alwaysApply: true .mdc files bloat every prompt turn |
| Google Antigravity | ~/.gemini/GEMINI.md & ~/.gemini/antigravity/skills/ | .agents/rules/ + workspace GEMINI.md + .agents/skills/ | 24 KB per rule file; 20,000-token cumulative rules budget | Cumulative rule concatenation overflows 20,000-token budget silently |
Notice how keeping procedural workflows inside on-demand ~/.codex/skills/<name>/SKILL.md folders—as documented in the Anthropic Claude Code Skills specification (under 500 lines per SKILL.md, 1% context listing budget) and echoed in Google Antigravity Rules documentation—keeps your AGENTS.md chain small enough to stay well below the 32 KiB ceiling.
Prompttly is a skill manager for AI agents — one library for your skills and prompts that syncs into Claude Code, Codex, ChatGPT, and Claude and is one hotkey away on your Mac, so your setup follows you across every machine, repo, and tool.
Instead of maintaining hand-edited copies across ~/.codex/skills, ~/.claude/skills, and repository rule files, Prompttly maintains two-way sync on Mac with version history and connects to any agent over MCP. When you only need a quick rule in a web chat or terminal without editing dotfiles, the Mac hotkey palette opens your whole library in 140 to 180 milliseconds (sub-200ms). For deeper setup patterns, explore our guides on configuring Codex CLI skills, AGENTS.md across Codex, Cursor, and Antigravity, syncing AGENTS.md across Git worktrees, and resolving multi-agent instruction precedence conflicts. You can also draft portable system rules with our free Custom Instructions Generator or browse every guide on the Prompttly Resources hub.
When Should You Avoid AGENTS.override.md and Custom Profiles?
Do not use AGENTS.override.md for shared team standards or multi-step procedural runbooks, and do not place provider, base URL, or telemetry settings inside project-local .codex/config.toml files. Overusing overrides masks missing repository documentation, while misplacing TOML keys causes silent configuration ignores across teammates.
- Avoid committing
AGENTS.override.mdlong-term: ReserveAGENTS.override.mdfor temporary local experiments or emergency folder overrides, and keep it listed in your global.gitignore. If a service genuinely needs permanent rules, update its directoryAGENTS.mddirectly. - Avoid stuffing workflows into root
AGENTS.md: Long PR review checklists, migration scripts, and release rubrics burn through the 32 KiBproject_doc_max_byteschain cap on every turn. Move task-specific procedures into lazy-loaded~/.codex/skills/<name>/SKILL.mdpackages. - Avoid inline
[profiles.*]tables or repo provider keys: Modern OpenAI Codex CLI reads standalone~/.codex/<name>.config.tomlfiles via--profile, and ignoresprofile,openai_base_url, andotelkeys inside project-local.codex/config.toml. - Avoid duplicating personal rules per machine: If you use only one laptop and one repository, a single
~/.codex/AGENTS.mdis enough; once you work across two machines or add Cursor and Claude Code, manual TOML and Markdown copies drift immediately.
Frequently Asked Questions: Codex CLI AGENTS.md Overrides and Profiles
In what order does OpenAI Codex CLI load AGENTS.md and AGENTS.override.md?
OpenAI Codex CLI checks your global Codex home directory (~/.codex or $CODEX_HOME) first, reading AGENTS.override.md if present and non-empty or falling back to AGENTS.md. It then walks from the project root (usually the Git root) down to your current working directory, picking at most one non-empty file per folder in strict order: AGENTS.override.md, then AGENTS.md, then entries in project_doc_fallback_filenames.
How do global config profiles work in ~/.codex/config.toml?
Modern OpenAI Codex CLI stores named profiles as standalone files beside config.toml at $CODEX_HOME/<profile-name>.config.toml, such as ~/.codex/review.config.toml, and activates them with codex --profile review. A profile sits above ~/.codex/config.toml in precedence and below trusted repository .codex/config.toml files and CLI -c overrides.
What happens when AGENTS.md files exceed project_doc_max_bytes in Codex CLI?
The project_doc_max_bytes setting in config.toml defaults to 32,768 bytes (32 KiB) across the entire concatenated instruction chain, not per file. Once cumulative bytes from global and root AGENTS.md files reach 32 KiB, Codex CLI stops appending deeper subdirectory instructions without raising an error, so nested overrides can be silently dropped.
Why does Codex CLI ignore .codex/config.toml in a cloned repository?
For security, OpenAI Codex CLI skips project-scoped .codex/ layers—including .codex/config.toml, project hooks, and rules—whenever a repository is marked untrusted under projects.<path>.trust_level. User-level ~/.codex/config.toml, active --profile overlays, and system configuration still load as expected.
How can I keep Codex CLI AGENTS.md rules synced with Claude Code and Cursor?
Because OpenAI Codex CLI reads ~/.codex/, Claude Code reads ~/.claude/skills/, and Cursor reads .cursor/rules/*.mdc, maintaining separate files across laptops quickly causes rule drift. Using a cross-agent skill manager like Prompttly keeps one canonical library synced across Codex, Claude Code, ChatGPT, and Mac hotkeys without manual copies.
Related Prompt Resources
Keep your Codex CLI rules and skills in sync everywhere
Stop debugging diverging AGENTS.md overrides and missing skills across machines. Prompttly syncs one skill and instruction library into Codex CLI, Claude Code, ChatGPT, and your Mac hotkey palette.