# Codex AGENTS.md setup: file locations and layering

> Canonical: https://skillalmanac.com/learn/codex-agents-md-setup | Updated: 2026-11-22 | Index status: not offered to search engines

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

## Facts

- 2026-11-21: Codex reads global instructions from CODEX_HOME, which defaults to ~/.codex, using AGENTS.override.md if non-empty, otherwise AGENTS.md (https://learn.chatgpt.com/docs/agent-configuration/agents-md)
- 2026-11-21: Project discovery starts at the project root, typically the Git root, and checks each directory down to the working directory for AGENTS.override.md, then AGENTS.md, then project_doc_fallback_filenames (https://learn.chatgpt.com/docs/agent-configuration/agents-md)
- 2026-11-21: project_doc_max_bytes caps the combined instruction size and defaults to 32 KiB; once reached, no more files are added (https://learn.chatgpt.com/docs/agent-configuration/agents-md)
- 2026-11-21: Files are concatenated from the root downward with blank lines between them, and empty files are skipped (https://learn.chatgpt.com/docs/agent-configuration/agents-md)
- 2026-11-21: Claude Code reads a repository's AGENTS.md only when no CLAUDE.md or CLAUDE.local.md exists in the working directory or above it, and requires v2.1.277 or later (https://code.claude.com/docs/en/memory)
- 2026-11-22: The Codex AGENTS.md page shows `codex --cd <dir>`, `--ask-for-approval never` and `-c log_dir=...`, and names codex-tui.log as the TUI log file (https://learn.chatgpt.com/docs/agent-configuration/agents-md)

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`:

```toml
project_doc_fallback_filenames = ["TEAM_GUIDE.md", ".agents.md"]
project_doc_max_bytes = 65536
```

5. 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](/learn/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](/skills/skill-almanac/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](/learn/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.

## Related skills

- [agent-instruction-files](https://skillalmanac.com/skills/skill-almanac/agent-instruction-files.md): Platform Score 46/100 (provisional)

## Related guides

- [Install Codex CLI and Sign In](https://skillalmanac.com/learn/install-codex-cli.md)
- [Codex Skills Explained: Locations and AGENTS.md Differences](https://skillalmanac.com/learn/codex-skills-explained.md)
- [Make Claude Code read AGENTS.md: import and verify](https://skillalmanac.com/learn/make-claude-code-read-agents-md.md)
- [Codex vs Claude Code: Config Files and Sandbox](https://skillalmanac.com/learn/codex-vs-claude-code.md)
- [Codex Pricing and Usage Limits: How Metering Works](https://skillalmanac.com/learn/codex-pricing-and-usage-limits.md)

## Sources

- https://learn.chatgpt.com/docs/agent-configuration/agents-md
- https://code.claude.com/docs/en/memory

Platform Scores report our assessment under a published method. They are not a safety guarantee.
