CLAUDE.md and AGENTS.md: One Rulebook All Three Agents Read
Sep 14, 2026 · AI & BuildingEvery guide about CLAUDE.md and AGENTS.md gives the same advice, and it's good advice: keep one main file, and make the others thin shims that import it. Anthropic's own docs say this: “Claude Code reads CLAUDE.md, not AGENTS.md. If your repository already uses AGENTS.md for other coding agents, create a CLAUDE.md that imports it.” I follow it. My root CLAUDE.md is three lines long and the first one is an import.
That fixed the filenames, which is the part most guides cover. The three tools also disagree on which directories to collect those files from, so two agents launched in the same folder can end up with very different rulebooks, and the one with fewer rules has no idea. I found this by counting the bytes each tool loads from the same folder.
Quick answer: from a single working directory three levels deep in my workspace, Claude Code loaded 55,986 bytes of instructions and Codex loaded 24,150. The missing 30,058 bytes (54% of the rulebook) sat above a nested repository's own Git root, and Codex starts its search at the Git root. Nothing warned me. The Codex chain finished with 8,618 bytes to spare, so the well-known 32 KiB cap never came into it.
The Three Loaders Disagree About Where “The Project” Starts
All of these rules are in the docs, and I'd read all three before I built the layout that broke. The trouble shows up when you put them side by side, which no vendor's docs do.
| Tool | Reads | Which directories it collects from | Size behaviour |
|---|---|---|---|
| Claude Code | CLAUDE.md, CLAUDE.local.md |
“your current working directory and every directory above it.” No Git boundary appears in the rule. Subdirectory files load on demand when it reads files there | Loads a file up to 4 MiB in full, skips larger. Advises under 200 lines for adherence |
| Codex | AGENTS.override.md, then AGENTS.md, then your configured fallbacks |
“Starting from the Git root down to your current directory.” A nested .git becomes the ceiling |
“stops adding files once the combined size reaches the limit defined by project_doc_max_bytes (32 KiB by default)” |
| Gemini CLI | GEMINI.md by default; context.fileName accepts another name or a list, including AGENTS.md |
Home-directory file, then configured workspace directories, then “that directory and its ancestors up to a trusted root” | No published byte cap; concatenates general to specific, deepest last |
In the middle column, Claude Code walks up past every repository edge, and Codex walks down from the nearest one. In a flat, single-repo project they happen to pick the same files, which is why almost nobody notices. Put one .git inside another and they pick different files.
The Measurement: 55,986 Against 24,150
My workspace is a root repository with nine sibling repositories inside it, one per area of work, and one of those has a repository of its own nested a level deeper. I set it up that way for reasons that have nothing to do with agents: separate histories and separate commits per area. It's also a common layout. Any monorepo with vendored submodules looks like this.
I launched from the deepest directory and counted what each tool's documented rule would collect. I've made the directory names generic, but the byte counts are exact.
The 30,058 bytes are the workspace root rulebook and the tier above the nested repository: the failure-registry triggers, the naming rules, the single-committer Git convention, and the instruction never to claim something is done without the file that proves it. Claude Code loaded all of it, and Codex, launched from the same folder at the same time, loaded none.
Why the 32 KiB Cap Is the Wrong Thing to Worry About
The cap exists, and it's the number people quote most when they talk about these files. OpenAI's docs say it plainly: Codex “concatenates files from the root down” and “stops adding files once the combined size reaches the limit defined by project_doc_max_bytes (32 KiB by default)”. There is an open issue on the Codex repository reporting that when it kicks in there's no warning in the terminal UI, no log line and nothing in the editor extension. I checked my own config.toml while writing this. I've never set project_doc_max_bytes, so I'm running the 32,768-byte default.
The Codex chain came in at 24,150 bytes with a quarter of the budget left, so the cap never fired. My problem was how far up the tree Codex looks, which I'll call reach. It never looked above the Git root, and a size cap can't catch that.
You fix a length problem by trimming, and that's what most articles about these files tell you to do. If the problem is reach, trimming only shortens the files the agent was already reading, and the ones it can't see stay hidden. I spent a whole session trimming before I thought to measure, and it got me nothing.
The five-second check, before you rewrite anything. If one agent follows a rule and another ignores it, run git rev-parse --show-toplevel from the directory you launch the agent in. If that path is below the file with the rule, a tool that starts at the Git root was never going to read it, and rewording the rule won't change that.
The Import Trick Covers Two Tools Out of Three
The standard fix (one main file, plus shims that import it) works well where it works. Claude Code's import path is relative to the file doing the import, and imports can nest up to four levels deep. Gemini CLI supports the same idea. Both can point at a single AGENTS.md, and mine do. My CLAUDE.md files in two pillars are eleven bytes each: one import line and a newline.
Codex can't do this. I read its instruction-file docs end to end looking for an include directive, because I assumed I'd missed it. The docs cover discovery order, precedence, AGENTS.override.md for temporary global overrides, and configurable project_doc_fallback_filenames. They have no import or include syntax of any kind. A Codex instruction file has to contain its own text.
So with three tools you have two options:
| Shape | How it works | What it costs |
|---|---|---|
Canonical AGENTS.md(use this inside a repo) |
AGENTS.md holds every shared rule. CLAUDE.md is one import line plus any Claude-only additions. Gemini CLI either imports it or has AGENTS.md added to context.fileName |
Nothing, inside one repository. Breaks the moment a rule needs to live above a nested Git root |
| Mirrored portable block (use this for home-directory files) |
The shared rules live between two marker comments and are copied byte-for-byte into each tool's home file. Tool-specific content goes outside the markers | It's a copy, so it will drift. You need a scripted diff that fails loudly |
The home-directory files are where the import can't help, because there's no shared repository to hold the main file. Mine use the mirror, and the drift check is one command:
I ran it against both mirrors while writing this page and both returned clean: a 4,886-byte, 720-word, 60-line block, byte-identical across all three home files. The files around it differ (7,497, 6,660 and 6,675 bytes) because each one has settings only its own tool uses.
A symlink is a third option, and Anthropic documents it. On Windows it needs Administrator privileges or Developer Mode, and the docs say the import is the better choice there. A symlink also leaves you nowhere to put tool-specific content, which is usually why you'd want a shim in the first place. I'd use one only when the file is the same for every tool and nobody's on Windows.
The Layout That Works for All Three
I use four rules. The first is the one that fixes the problem above, and it's the one I was missing.
1. Every nested repository opens its instruction file with an inheritance block. A tool that starts at the Git root can't walk up to the parent rulebook, but you can tell it to open it. Name the parent files by relative path in the first section, before anything else. Tools that already walk up lose nothing, and tools that start at the Git root now get the files they were missing. It's the cheapest fix in this post.
2. Budget the whole chain. The 32 KiB cap applies to root-to-working-directory concatenation, so watch the total along the deepest path. Keep each chain under about 24 KB and the strictest tool never cuts anything. Claude Code's under-200-lines advice is a target for getting the agent to follow the rules, and it's well below any tool's hard limit.
3. A pointer file holds no rules. If CLAUDE.md is a shim, keep it a shim: an import and, at most, one sentence saying where the rules are. As soon as someone adds a rule to the pointer “just this once,” you have two sources of truth, and two of your three tools can't see one of them. Mine says this in its own text, as a note to the next person as much as to the agent.
4. Conditional content leaves the always-loaded file. Everything above is about reach, making sure the agent sees the right files. A separate question is what belongs in them at all. My answer is only what's true for every task. Anything that only applies in certain cases should sit in its own file behind a trigger, which costs one line in the always-loaded file. Claude Code now has a first-class mechanism for this in path-scoped rules under .claude/rules/, which load only when it touches matching files. I wrote up the portable version, and what to do with corrections you've had to give an agent twice, in Your AGENTS.md Gets Worse Every Time You Fix It.
Running more than one agent in the same repo?
I run a free community for people building data and AI pipelines: warehouse modeling, analytics and AI-assisted workflows.
Join the free AI community →Frequently Asked Questions
project_doc_max_bytes, which is 32 KiB by default and can be raised in config.toml. The cap applies to the combined chain, and an open issue says it kicks in with no warning anywhere. Claude Code loads a CLAUDE.md up to 4 MiB in full and skips anything larger. Its docs suggest under 200 lines so the agent follows the rules well. In practice, aim for the 200-line advice and keep any single root-to-working-directory chain well under 32 KiB..git becomes a Git root, and any tool that starts its search there can't see anything above it. Start each nested repository's file with a short block that names the parent files by path and tells the agent to open them.Related reading: Your AGENTS.md Gets Worse Every Time You Fix It, the companion to this page, about what belongs inside the file once you know which files get read. I Ran Claude Code and Codex Head-to-Head, where the two tools above work the same spec in the same repo and get judged blind. Multi-Model Verification, the same don't-trust-one-pass habit applied to an agent's output. AI as an Operations Layer, about where these agents run. For the hardware they run on, see Blendlogic Tech.
What would make this wrong
- The byte counts are what the documented rules select, not a packet capture. I counted the files each tool's published discovery rule would collect from that directory and summed them. I didn't instrument the agents to read back what entered the context window. If a loader doesn't do what its docs say (skips a file, removes duplicates, or applies an exclusion I missed), my totals are off. I'm confident about the gap itself, because it follows from two documented rules that go in opposite directions. The exact 30,058 figure assumes both tools match their docs.
- n=1, and it's my own layout. It's one workspace with ten repositories, and I designed it. Nested repositories are common enough that I think this applies widely, but I haven't reproduced it on anyone else's tree, and a flat single-repo project will never run into it.
- Claude Code's docs never mention Git boundaries. They say “your current working directory and every directory above it” and stop there. I'm reading that as “no boundary,” which matches what I see, but a stated rule would be better evidence.
- This is a moving target, and the docs moved while I wrote. Two of the three doc URLs I fetched had moved since I last read them. I pulled every quote here on 2026-09-14. The
project_doc_max_bytesdefault, the import depth and the fallback setting can all change in a point release, and the Codex truncation issue is still open. - My own chain is way past the advice I'm repeating. Claude Code recommends under 200 lines per file, and the chain it loads for me is 743 lines across seven files. This post argues that reach and length are separate problems. I fixed the first and still have the second.
- Harness features may absorb all of this. Path-scoped rules already do a better job than a hand-built trigger for the conditional-content case. If every tool ends up reading the same filename with the same directory rule, the inheritance block becomes a workaround for a gap that's gone. I expect the four-rule layout to last. The mirroring is the part most likely to become unnecessary.
Get the build notes
My AI experiments: what worked, what didn’t, and how I set them up. Sent to your inbox.
No spam, unsubscribe anytime · Privacy
You're in. Check your inbox for a welcome note.