Codex AGENTS.md setup: file locations and layering

Where Codex finds AGENTS.md files, how global and project layers combine, and how to confirm which instructions load in a session.

Updated · Markdown version

Codex reads AGENTS.md from two scopes: a global folder under CODEX_HOME (default ~/.codex), and each directory from the project root down to the folder where you launch it. The files are joined into one instruction block, and files nearer your working directory appear later so their guidance takes precedence.

Where Codex looks for files

Global scope comes first. Codex uses AGENTS.override.md when that file exists and is non-empty, and falls back to AGENTS.md otherwise. Only one file counts at this level.

Project scope starts at the project root, usually the Git root, and walks down to your current directory. Inside each directory Codex checks AGENTS.override.md, then AGENTS.md, then any names listed in project_doc_fallback_filenames. It keeps at most one file per directory. If no project root can be found, only the current directory is checked.

Setup steps

  1. Create the global folder if it is missing: mkdir -p ~/.codex. Place personal defaults in ~/.codex/AGENTS.md.
  2. Add AGENTS.md at the repository root for rules every contributor needs.
  3. For a service with its own rules, add AGENTS.md in that subfolder, for example services/payments/AGENTS.md.
  4. If your team uses other filenames, set them in ~/.codex/config.toml:
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536
  1. Restart Codex or start a new command so the change takes effect.

Check that it worked. Launch from the nested folder and ask Codex to list its sources:

codex --cd services/payments --ask-for-approval never "List the instruction sources you loaded."

For a written record, run codex -c log_dir=./.codex-log and read ./.codex-log/codex-tui.log. To test with a separate home, set CODEX_HOME=$(pwd)/.codex and confirm the active value with echo $CODEX_HOME.

How layers combine

Suppose the root AGENTS.md says to use pnpm, and services/payments/AGENTS.md says to run the payments test suite before committing. A session started in services/payments receives both, with the payments file later in the prompt, so its more specific wording wins where the two conflict. A session started at the repository root receives only the root file, because Codex does not walk down into subfolders on its own.

Empty files add nothing, so a placeholder file is harmless but also useless.

Pitfalls

  • Late rules disappear. A combined file set above 32 KiB stops adding files once the cap is reached. Notice it when Codex ignores a rule from a deep file. Raise project_doc_max_bytes or trim the root file.
  • A stray override hides the real file. An AGENTS.override.md left in a folder replaces that folder's AGENTS.md. Notice it by listing the directory. Delete the override or merge its content.
  • Launching from the wrong folder. Starting at the repository root skips nested rules. Use --cd to start in the folder you are working in.
  • Config edits do not apply mid-session. Changes to config.toml need a restart or a new command.
  • Mixed tools read different files. A CLAUDE.md in the same tree changes which file Claude Code reads. The make-claude-code-read-agents-md guide covers that case.

When to use a skill instead

A one-time setup like this needs no skill. The skill agent-instruction-files fits once a repository has several overlapping instruction files and you need a cleanup pass that removes stale lines before they use up the size budget. Use it to review what each file contributes and to move task-specific steps out of the always-loaded files. For a single root file in a small repository, editing it directly is faster.

FAQ

Does Claude Code read AGENTS.md?

Only under the conditions set out in the make-claude-code-read-agents-md guide. This page covers only how Codex finds its files.

How do I use AGENTS.md in Codex?

Create the file at the repository root and launch Codex from inside the repository. Confirm the load with the --cd command shown above, which lists the instruction sources Codex used.

What is the difference between AGENTS.md and CLAUDE.md?

Codex reads AGENTS.md through its own discovery rules. Claude Code reads CLAUDE.md first and treats AGENTS.md as a fallback, so a shared file is usually easiest to keep as AGENTS.md and import it from a short CLAUDE.md. Product behavior changes, so check the official pages listed in this guide before relying on it.

Platform Score is our assessment under a published method. It is not a safety guarantee.

Terms this guide uses

This item is a worked example in the AI glossary for:

Next steps

  1. Install Codex CLI and Sign In Read next.
  2. Codex Skills Explained: Locations and AGENTS.md Differences Read next.
  3. Codex compatibility Install evidence per tool.
  4. All guides by topic Browse everything.

Sources

This page is not offered to search engines yet: The content file does not mark this page indexable yet.