AGENTS.md vs CLAUDE.md: keep one file and import it
Keep one AGENTS.md for every agent and a CLAUDE.md that imports it. What Claude Code and Codex each read, in what order, and how to check.
Write your project instructions once, in AGENTS.md. Add a CLAUDE.md that contains one line, @AGENTS.md, plus anything only Claude Code needs. Codex reads AGENTS.md directly, and Claude Code reads it through the import. You keep one source of truth, and neither agent depends on a feature that the other does not have.
What is the difference between the two files?
AGENTS.md is an open, plain Markdown format for guiding coding agents, with no required fields. The agents.md site calls it "a README for agents" and lists Codex among the tools that read it. CLAUDE.md is the file name Claude Code has always used for the same job, with some extras, such as imports and a local variant for personal notes.
Both are context, not enforcement. Claude Code's documentation says it treats these files as context and that there is no guarantee of strict compliance. The more specific and short the instructions, the more consistently they are followed.
Does Claude Code read AGENTS.md on its own?
Sometimes. Claude Code's memory documentation says that from version 2.1.277 it reads AGENTS.md as your project instructions. By default it does so only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or any directory above it. If both files exist, Claude reads the CLAUDE.md files only, unless you set its Project instructions setting to load both. Your own ~/.claude/CLAUDE.md does not count for that check.
That rule is why the import is still the safer layout. One personal CLAUDE.local.md is enough to stop Claude from reading AGENTS.md for that person. The documentation also lists sessions that cannot read AGENTS.md directly, and says that before version 2.1.281 some sessions, such as those on Amazon Bedrock or with telemetry disabled, read CLAUDE.md files only. An @AGENTS.md import works in all of them. If you want both files read side by side without an import, the Project instructions setting accepts claude-md-and-agents-md.
What does each agent read, and in what order?
| What | Claude Code | Codex |
|---|---|---|
| Personal file | ~/.claude/CLAUDE.md | ~/.codex/AGENTS.md, or AGENTS.override.md there |
| Project files | CLAUDE.md in the working directory and every directory above it, loaded at launch | One file per directory, from the project root down to the working directory |
| Files below the working directory | Loaded on demand, when Claude reads or edits a file in that directory | Not loaded: Codex stops at the working directory |
| Which one wins | All files are concatenated, root first, so the closest is read last | All files are concatenated, root first, so files closer to you come later |
| Override file | CLAUDE.local.md is added after CLAUDE.md | AGENTS.override.md replaces AGENTS.md in the same directory |
| Size | Aim for under 200 lines per file | Combined cap of 32 KiB by default, set by project_doc_max_bytes |
Both agents concatenate rather than replace, so a nested file adds to the root file. Write nested files as additions, and do not repeat the root rules in them.
Codex checks AGENTS.override.md first in each directory, then AGENTS.md, then any names you list in project_doc_fallback_filenames, and includes at most one file per directory. It stops adding files once the size cap is reached, so late content can be cut off. Claude Code does not read AGENTS.override.md, AGENTS.local.md or anything under a .agents/ directory.
How do nested files work in a monorepo?
Put shared rules in the root file and package-specific rules in packages/billing/AGENTS.md, next to the code. The agents.md site says agents read the nearest file in the directory tree, so the closest one takes precedence.
The two agents differ in when nested files load, so the way you launch matters. Claude Code loads a subdirectory's file when it reads or edits something there, and a nested AGENTS.md loads that way only if the subdirectory has no CLAUDE.md of its own. Codex builds its chain once per run from the root to the directory you start in, so start it in the package (codex --cd packages/billing) when you want that package's rules. In a large repository, Claude Code can skip other teams' files with the claudeMdExcludes setting.
A nested CLAUDE.md with an @AGENTS.md import next to each nested AGENTS.md keeps the same one-file rule at every level.
A copyable pair of files
AGENTS.md holds everything both agents need:
# Project instructions
## Commands
- Install: pnpm install
- Test one file: pnpm vitest run path/to/file.test.ts
- Full check before a pull request: pnpm check
## Layout
- apps/web: the Next.js site
- packages/billing: invoice logic, no UI code
## Rules
- Use top-level `import type`.
- Run the formatter before you commit; do not reformat files you did not change.
- Never write secrets or real customer data into files, tests or commits.
- Database migrations are numbered by hand: ask before adding one.CLAUDE.md imports it and adds only what is specific to Claude Code. Claude reads the imported file first, then the rest:
@AGENTS.md
## Claude Code
Use plan mode for changes under `packages/billing/`.Imports resolve relative to the file that contains them and can nest up to four hops deep. They organize a file but do not shrink it: an imported file loads together with the file that imports it, so its length still counts.
A symlink (ln -s AGENTS.md CLAUDE.md) also works, but the documentation lists two catches. Claude's edit tools refuse to write through a symlink, and on Windows a committed symlink is checked out as a one-line text file unless core.symlinks is enabled. If anyone on the team uses Windows, use the import.
What belongs in the file, and what does not?
Put in
- The commands to build, test and check, exactly as you type them.
- Where things live, in one line per area.
- Rules the agent cannot infer from the code, such as hand-numbered migrations.
- How you want commits and pull requests written.
Leave out
- Secrets and private data. The file is committed and read by every agent and every contributor. Name the variable, never the value.
- Long documents. Longer files use more context and reduce adherence, and Codex truncates past its cap. Link to the document, or in Claude Code move rules that matter for only part of the codebase into path-scoped files under
.claude/rules/. - Rules a tool can enforce. Indentation, import order and unused variables belong to the formatter and linter. A rule that must hold every time should be a hook or a check. Claude Code's documentation points to a
PreToolUsehook for blocking an action regardless of what the model decides. - Vague advice. "Write clean code" costs lines and changes nothing. "Run the tests for the file you changed before you commit" is something the agent can follow.
Contradictions do harm too. Claude Code's documentation warns that when two instructions conflict, the model may pick one arbitrarily, so review nested files when you change the root.
How do you check what an agent loaded?
Claude Code
- Run
/context alland read the list under Memory files. If a file is missing there, Claude cannot see it./memorylists the files too, including anAGENTS.mdthat Claude read directly (version 2.1.280 or later). - A nested file does not appear at launch. When it loads, a
Loadedline with its path appears in the terminal. - For a log, add an
InstructionsLoadedhook. It fires for anAGENTS.mdthat aCLAUDE.mdimports, but not for one that Claude reads directly through the setting.
Codex
- From the repository root, run
codex --ask-for-approval never "Summarize the current instructions."and check that it cites guidance in precedence order. - Repeat with
codex --cd packages/billingto confirm a nested file or override takes effect. - Start with
codex -c log_dir=./.codex-logand readcodex-tui.logfor an audit trail. There is no cache, so restart Codex in the target directory when results look stale.
The short version
- Write
AGENTS.md. Keep it under 200 lines and well below Codex's 32 KiB. - Add
CLAUDE.mdwith@AGENTS.mdand the few Claude-only lines. - Nest files per package and start each agent in the package it works on.
- Move anything enforceable into a linter, a check or a hook.
- Verify once per agent, then again after you add a nested file.
If you run both agents on the same repository, Tenslo Code puts each in its own git worktree, so both start from the same committed files. The worktree guide covers what a worktree does not copy, such as ignored files, which includes a personal CLAUDE.local.md.
Sources
- AGENTS.md: a README for agents, agents.md
- How Claude remembers your project, Claude Code docs
- AGENTS.md, Codex docs (OpenAI)