AGENTS.md in Codex. How Codex finds instructions, the override file and the 32 KiB limit
Where Codex looks for AGENTS.md, in which order, what AGENTS.override.md does, why a long file gets cut off and three commands that show which instructions Codex really loaded.
Part of the guideClaude Code tutorial 2026, the complete guide. Install, errors, commands, skills and plugins
In this article
In short
Codex reads AGENTS.md files before it starts any work. It takes one global file from your Codex home folder. Then it walks from the project root down to your current folder, taking at most one file from each. AGENTS.override.md wins over AGENTS.md in the same folder. Files closer to your current folder come later and so take priority. By default Codex stops adding text after 32 KiB. We checked this against OpenAI's Codex guide on 24 November 2026.
You add a rule to AGENTS.md, start Codex, and it ignores the rule. Most often the file is in a folder Codex never visits, or an override file sits above it. This page shows the order Codex follows, so you can see where your rule went.
If you are new to the format itself, start with what is AGENTS.md. Here we look only at Codex.
The order in which Codex reads AGENTS.md
The Codex guide describes an instruction chain that Codex builds once per run. In the interactive terminal app that usually means once per session.
- Global level. In your Codex home folder,
~/.codexunless you setCODEX_HOME, Codex readsAGENTS.override.mdif it exists, otherwiseAGENTS.md. Only the first non-empty file counts. - Project level. Codex starts at the project root, usually the Git root, and walks down to the folder where you started it. In each folder it checks
AGENTS.override.md, thenAGENTS.md, then any fallback names from your settings. - Joining. Codex puts the files together from the root down, separated by blank lines. Later files appear later in the prompt, so they take priority over earlier ones.
Two details surprise people. Codex includes at most one file per folder. And it stops at your current folder, so an AGENTS.md in a sibling folder is not read at all.
| Situation | What Codex reads |
|---|---|
Only AGENTS.md in the root | That one file |
AGENTS.md and AGENTS.override.md in the same folder | Only the override |
Started in services/payments | Root file, then the payments file |
| Started in the root | Root file only, not the subfolder files |
Empty AGENTS.md | Skipped |
What AGENTS.override.md is for
The override replaces the regular file in the same folder. The guide gives two uses. A team can keep stricter rules for one service, such as payments, in a nested override. And you can put a temporary global override in ~/.codex without deleting your usual file.
Remove the override and Codex goes back to the regular AGENTS.md. Codex follows rules you do not recognise? First look for an override file higher in the tree or in your Codex home folder.
Other tools do not treat this name the same way. Claude Code, for example, does not read AGENTS.override.md at all, according to its memory documentation.
The 32 KiB limit and fallback file names
Codex stops adding files once the combined instructions reach project_doc_max_bytes. The default is 32 KiB. Rules for a subfolder never seem to apply? The chain may have been cut before it reached them.
You can raise the limit or teach Codex another file name in ~/.codex/config.toml. The advanced configuration describes both settings.
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536With this setting Codex checks each folder for AGENTS.override.md, AGENTS.md, TEAM_GUIDE.md and .agents.md, in that order. Restart Codex after changing the file. Before you raise the limit, try removing repeated rules. A shorter file is easier for people to maintain as well.
Three commands to check what Codex loaded
Do not guess. The guide gives ready commands, and the first one asks Codex to repeat its instructions.
codex --ask-for-approval never "Summarize the current instructions."
codex --cd services/payments --ask-for-approval never "Show which instruction files are active."
codex -c log_dir=./.codex-logThe second command starts Codex in a subfolder. You should see the root file first and the nested file last. The third writes a plain-text log to ./.codex-log/codex-tui.log, where you can see which files were loaded. Codex rebuilds the chain on every run, so there is no cache to clear.
Code review rules for Codex in GitHub
For Codex code review on GitHub, the guide suggests a ## Code Review Rules section. Put it in the AGENTS.md closest to the code. Repository-wide checks go in the root file. Rules for one service go in that service's folder.
## Code Review Rules
- Flag any change to payment amounts that skips the existing tests.
- Flag new environment variables that are missing from the example config.Keep formatting and lint checks in CI. Review rules work best for things a linter cannot see.
Want a first draft for your own project? Our free AGENTS.md generator builds the file from your stack, commands and rules. It runs in the browser, and you can copy or download the result.
Questions about AGENTS.md in Codex
Does Codex read AGENTS.md automatically?
Yes. It reads the files before doing any work, with no extra setting. You only need settings for fallback names or a larger limit.
Where is the global AGENTS.md for Codex?
In ~/.codex/AGENTS.md, unless the CODEX_HOME variable points somewhere else. Run echo $CODEX_HOME to check.
Why does Codex ignore my AGENTS.md in a subfolder?
Most likely you started Codex in the root. It walks only down to your current folder. Start it in the subfolder or use --cd.
Can one repository have several AGENTS.md files?
Yes, one per folder. In a monorepo each package can have its own file. Examples are in AGENTS.md examples.
Do I need CLAUDE.md if the team also uses Claude Code?
Not always. Claude Code reads AGENTS.md when no CLAUDE.md exists. How to keep one source of rules for both is in AGENTS.md vs CLAUDE.md.
We use the same instruction files in the web applications we build for clients. Before you add a new rule, run the first command above and see what Codex already knows.
What would you like to change in your business?
Leave your number. We will talk about your process and see whether we can help. The first call is free.
The service this text is about
Automation and AI / OCRAutomation of document re-typing, OCR and checking rules, and your data stays with you.