Codex CLI
Codex CLI project instructions (AGENTS.md)
AGENTS.md is the project-instructions file Codex reads at startup — the place for build/test commands, code style, and repo-specific rules. Generate a scaffold with /init in the TUI.
Discovery order
Instructions are assembled once per run (per TUI session), in this order:
- Global scope — in
$CODEX_HOME(default~/.codex): readsAGENTS.override.mdif it exists, otherwiseAGENTS.md. Only the first non-empty file at this level is used. - Project scope — starting at the project root (typically the Git root; configurable via
project_root_markers), walking down to the current directory. In each directory Codex checksAGENTS.override.md, thenAGENTS.md, then the names inproject_doc_fallback_filenames. At most one file per directory. If no project root is found, only the cwd is checked. - Merge — all files found are concatenated root-down, joined with blank lines. Files closer to the cwd appear later and therefore override earlier guidance.
Rules and limits
- Empty files are skipped.
- The combined size is capped at
project_doc_max_bytes(default 32 KiB). AGENTS.override.mdtakes precedence overAGENTS.mdin the same directory — e.g.services/payments/AGENTS.override.mdreplaces that directory’sAGENTS.md(useful for local, uncommitted tweaks).- The
model_instructions_fileconfig key replaces Codex’s built-in instructions entirely — it is separate from (not a substitute for)AGENTS.md. - For Codex code review in GitHub, add a
## Code Review Rulessection to theAGENTS.mdclosest to the code being reviewed.
Example AGENTS.md
# AGENTS.md — example-repo
## Project
Go 1.22 microservice. Entry point: cmd/server/main.go.
Internal packages live in internal/; nothing outside internal/ may import them.
## Build and test
- Build: make build
- Unit tests: make test
- Lint: make lint (run before every commit)
- Integration: make test-integration (requires Docker)
## Code style
- Use gofmt; keep functions under 60 lines.
- Errors: wrap with fmt.Errorf("context: %w", err).
- No new dependencies without discussing first.
## Conventions
- Migrations in db/migrations/ are append-only — never edit applied ones.
- API changes require updating docs/openapi.yaml in the same commit.
## Code Review Rules
- Flag any SQL string concatenation.
- Flag unbounded goroutines.
Keep it concrete: exact commands and hard rules work better than general advice. Subdirectory AGENTS.md files are a good fit for monorepos, where each package can carry its own instructions.
Last verified: 2026-09-07
Official sources:
- https://developers.openai.com/codex/guides/agents-md
- https://developers.openai.com/codex/config-reference
AI coding tools evolve quickly. If you find outdated information, please open an issue or pull request.