# Codex Features and Practical Usage
📝 Stop repeating the same context in every prompt. AGENTS.md is a layered instruction file that teaches Codex your build steps and code conventions for good.
🏷️ Title: Hierarchical Project Instructions (AGENTS.md)
🔗 URL:
📘 Overview
AGENTS.md files are persistent instructions Codex reads before starting work. Encode your project norms, build commands, and code standards in Markdown, and Codex automatically discovers and applies them. The defining trait is a layered model where files closer to your current directory take precedence.
⚙️ How It Works
Codex builds an instruction chain with strict precedence.
・Global (`~/.codex/`): checks `AGENTS.override.md` first, then `AGENTS.md`
・Project (Git root down to cwd): at each level checks `AGENTS.override.md`, then `AGENTS.md`, then custom fallback names
・Merge: files concatenate from the root downward with blank lines; later files (closer to cwd) override earlier ones
It stops adding files once the combined size hits `project_doc_max_bytes` (32 KiB default). Naming conventions:
・`AGENTS.md`: the standard instruction file
・`AGENTS.override.md`: a temporary replacement that takes precedence at its level
・fallback names: configurable via `project_doc_fallback_filenames` (e.g. `TEAM_GUIDE.md`)
🛠️ Practical Usage
Split by role for best effect.
・`~/.codex/AGENTS.md` (global): universal personal preferences, e.g. "Always run `npm test` after editing JS," "Prefer `pnpm`"
・repo-root `AGENTS.md`: team norms like linting standards, documentation expectations, and review criteria
・subdirectory `AGENTS.override.md` (e.g. `services/payments/`): override broader rules for a specific domain without deleting parent guidance
Verify what loaded by asking Codex to summarize the current instructions, e.g. `codex --ask-for-approval never "Summarize the current instructions."`
💡 Use Cases
In a monorepo where only the payments service needs a different test command or review bar, dropping a `services/payments/AGENTS.override.md` switches the rules on only when Codex works under that path. The "Review guidelines" you write here also apply to GitHub's `@/codex review`.
⚠️ Caveats
Codex rebuilds the instruction chain on every run, so there is no cache to clear — if guidance looks stale, restart in the target directory. Empty files are skipped and non-existent fallback names are ignored. The `CODEX_HOME` environment variable overrides the default profile location.
#
OpenAICodex# #
AGENTSmd#