AGENTS.md is the repository's durable contract: instructions Codex reads before starting work and builds a chain from once per run or session. Unlike a one-off prompt, it is a reviewed source of truth living in the repository under version control. Global guidance is in $CODEX_HOME, while the project chain is built from the repository root to the current working directory - that is, the more general is set higher, the more specific closer to the code.
The order of building the chain matters, because it determines what wins. In each directory, AGENTS.override.md is looked for first, then AGENTS.md, then names from project_doc_fallback_filenames. No more than one non-empty file is taken per directory. Instructions closer to the current directory appear later in the chain and therefore override the general ones. This is the same precedence logic as in config: the specific overrides the general, not the other way around.
A good AGENTS.md is a project contract, not a retelling of the structure. It helps to see a meaningful example once. Below are the repository map, the required checks and the change policy: where the code and tests are, which commands to run after edits, what not to do without approval. It is exactly what cannot be reliably inferred from the code - verification commands, boundaries, the definition of done - that is worth writing, and there is no need to repeat the obvious from package.json.
The point of AGENTS.md is to name what the agent will not infer itself. A repository map saves it exploration: where the application code lives, where the integration tests are. Required checks set the signal: run lint after TypeScript edits, run the affected tests for behavior changes. A change policy sets boundaries: do not add production dependencies without approval, preserve public API compatibility unless the task explicitly requires otherwise. This is the contract by which the agent acts by default.
AGENTS.md is worth keeping short and checkable rather than growing into an encyclopedia. Long instructions take up context and lose salience - the agent follows vague verbosity worse than a short clear list. General facts stay in the root file, while requirements specific to a subdirectory are moved into its own AGENTS.md, which is picked up right there. Nested overrides are a way to keep an instruction next to the code it relates to rather than dumping everything into the root.
It helps to see how to check the active instructions and their sources once. Below are the commands that ask Codex to list the effective instructions in precedence order, including from a specific subdirectory via --cd. You return to this form when behavior does not match expectation: most often the matter is which AGENTS.md is actually in play and what overrides what. Checking the chain with a command is cheaper than guessing from the file tree.
AGENTS.md is executable policy, and it is worth treating like code. A change of instructions affects all future sessions, so it is reviewed: whether the boundaries expanded, whether a requirement appeared that the agent will now take as a given. And, as with everything untrusted, instructions from a foreign branch are treated cautiously - an AGENTS.md that came with an unverified repository is also configuration written by someone else, not an unconditional truth.
The typical failures around AGENTS.md are predictable. Retelling the structure the agent already sees instead of naming the non-obvious. Bloating the file so it loses salience. Dumping subdirectory-specific requirements into the root instead of a nested file. And expecting an edit to apply retroactively without checking the chain. Keep AGENTS.md a short contract, move the particular into nested files, name what the agent will not infer itself, and check the active instructions with a command.
# AGENTS.md
## Repository map
- Application code: src/
- Integration tests: tests/integration/
## Required checks
- Run pnpm lint after TypeScript edits.
- Run pnpm test --filter affected for behavior changes.
## Change policy
- Do not add production dependencies without approval.
- Preserve public API compatibility unless the task explicitly requires otherwise.# List the active instructions and their sources
codex --ask-for-approval never "Summarize the active instructions and their sources."
codex --cd services/payments --ask-for-approval never \
"List active instruction files in precedence order."
# search order: AGENTS.override.md -> AGENTS.md -> project_doc_fallback_filenames