Codex AGENTS.md and config.toml: give it stable rules
The short answer. Two files, two purposes. AGENTS.md holds natural-language instructions for the agent (how the project is built, which conventions to follow, what not to touch); config.toml holds the settings (model, sandbox, approvals, web search). Codex reads AGENTS.md once per run, from the project root down to the current folder, and files closer to the working folder win; the total is capped at 32 KiB by default (project_doc_max_bytes). For config.toml, in order, the command line wins, then the project file (.codex/config.toml, only if the project is trusted), then the profile, then your own ~/.codex/config.toml. The cost: every instruction you write occupies context in every session, so a long, vague AGENTS.md makes the work worse instead of better. Part 4 of the OpenAI Codex series; data from the documentation of 30 October 2026.
Note. The examples are built on the documented rules and I did not run them. I am not affiliated with OpenAI.
The difference that avoids half the mistakes
An instruction in AGENTS.md is a suggestion the model may follow badly or ignore; a value in config.toml is a constraint enforced by the program. If you want the agent not to write outside the workspace, do not write it in AGENTS.md: set sandbox_mode = "workspace-write" (part 3). If you want it to use pnpm and not npm, that is a suggestion and belongs in AGENTS.md. The practical rule: what must always hold goes in the program; what helps it work well goes in the text.
How Codex finds AGENTS.md
The dedicated page describes the chain, built once per run, in two scopes plus a merge:
- Global. In the Codex home folder (
~/.codex, or the one set byCODEX_HOME) it readsAGENTS.override.mdif present, otherwiseAGENTS.md. It uses only the first non-empty file at this level. - Project. It starts at the root (normally the Git root) and walks down to the current folder. In each folder it checks
AGENTS.override.md, thenAGENTS.md, then the names inproject_doc_fallback_filenames. At most one file per folder. With no project root, it checks only the current folder. - Merge. Files are concatenated from the root downward, separated by blank lines; those nearest your folder appear later and therefore prevail.
Example locations: ~/.codex/AGENTS.md for your personal preferences; AGENTS.md at the root for repository norms; services/payments/AGENTS.override.md for an area with its own rules. The AGENTS.override.md file takes priority over AGENTS.md in the same folder and is the way to replace guidance without deleting the base file: in the documentation's example, the payments folder's AGENTS.md is ignored because its override exists. After changing these files, restart Codex: the chain is built at startup.
The 32 KiB limit and what follows from it
project_doc_max_bytes caps the combined instructions. The default is 32 KiB and, once reached, Codex stops adding files. The concrete risk is silent: if the chain is long, the deeper files (the more specific ones) may be left out. The two ways out are raising the limit or, better, splitting the rules into nested files, each short and tied to its own area. Even short of the ceiling, a huge file has a cost: every word is context the agent rereads each session and that competes with the real code of the task.
What to put in a good AGENTS.md
/init generates a draft. Then cut it. An effective file answers five questions and no more:
- How do you build and test? The exact commands (
pnpm install,pnpm test --filter api), not "run the tests". - Which conventions are invisible in the code? Names, folder structure, commit style.
- What must not be touched? Generated files, already-applied migrations, vendored folders.
- Which traps have already cost time? Every line here is gold, because it is the one piece of information the code does not contain.
- When is it "done"? Which command must pass.
# AGENTS.md (example)
## Build and test
- Install: `pnpm install`
- API tests: `pnpm --filter api test`
- Lint is part of done: `pnpm lint` must pass.
## Conventions
- TypeScript strict; no `any` without a comment explaining why.
- One commit per logical change, format `type(scope): subject`.
## Do not touch
- `src/generated/`: regenerate with `pnpm codegen`.
- Existing migrations in `db/migrations/`: add a new one instead.
## Known traps
- Integration tests need Postgres on localhost:5432; without it they fail with a timeout, not a clear error.
What not to write: generic descriptions ("write clean code"), things the model already knows, and above all anything that is a security rule not enforced by the program. If a sentence starts with "you must never", ask yourself whether it belongs in config.toml or a check script.
config.toml: where it lives and who wins
The documented locations:
- User:
~/.codex/config.toml. - Project:
.codex/config.tomlin the repository or a subfolder. Codex loads project.codex/layers only if you trust the project. - System (Unix):
/etc/codex/config.toml.
And the precedence, highest first: (1) command-line flags and --config overrides; (2) the project .codex/config.toml, the one closest to the working folder wins; (3) profile files chosen with --profile (~/.codex/profile-name.config.toml); (4) your user configuration; (5) cloud-managed defaults, when delivered for your workspace; (6) the system configuration; (7) built-in defaults. Note the point that surprises people: a project file beats your user file. It is useful for a team (the repo imposes its rules) and it explains why the same command behaves differently in two folders.
The main keys from the "Config basics" page: model (default model), approval_policy, sandbox_mode, model_reasoning_effort, web_search (values cached, indexed, live, disabled), personality, log_dir. An example taken from the page:
model = "gpt-6.1-sol"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
model_reasoning_effort = "medium"
web_search = "cached"
[features]
shell_snapshot = true
For a one-off test you do not need to edit the file: codex -c log_dir=./.codex-log overrides the key for that run only. For experimental features: codex --enable feature_name, or feature_name = true under [features]; to turn them off, false. Model names change: the example uses gpt-6.1-sol because it is the one in today's documentation, but before copying it check the Models page (part 5).
A reasonable team setup
A repository can contain an AGENTS.md at the root and a .codex/config.toml fixing cautious sandbox and approval settings. The advantage is that every colleague starts from the same behaviour. The cost is twofold: project configuration applies only to trusted projects (so it must be explained to newcomers) and it falls under code review like any other file. Treat a change to .codex/config.toml as you would a change to a CI pipeline: it potentially changes what a process can do with your permissions.
If you also use Claude Code, the concept is the same with a different file: I discuss it in this guide to the Claude Code workflow. The risk of keeping two parallel files is drift: decide which is the source of truth and reduce the other to a pointer.
What I did not verify
I could not open the "Advanced config" and "Config reference" pages: so I do not describe the profile format or the MCP server table. I did not verify how cloud-managed values interact with project ones beyond the declared order of precedence.
Sources (consulted 30 October 2026)
- AGENTS.md (search chain, override, 32 KiB limit, fallback names).
- Config basics (locations, precedence, keys, overrides).
- Codex CLI (
/init).
← Part 3: sandbox and approvals Part 5: models, reasoning and costs →
Commenti
Caricamento commenti...
Sign in to comment