AGENTS.md past 32 KiB: the rules Codex never reads
Codex cuts mid-line, in the file closest to your work, with nothing on screen. Where it cuts, what Claude Code does with 200 KB, and a script that shows yours.
Published · updated
For a year, every incident in this repository ended the same way: "add it to AGENTS.md". The root file is 30 KB now. The payments team keeps its own services/payments/AGENTS.md, 8 KB, and on line 40 it says: never call the live refund endpoint from tests, use the refund stub.
A developer starts Codex in services/payments and asks for an integration test for partial refunds. Codex reads the root file in full and the first 2,068 bytes of the payments file, which ends in the middle of line 21. The refund rule never reaches the model. The terminal shows nothing about it. The same request in Claude Code, on the same checkout, gets both files whole.
Nobody broke anything. Codex has a limit on how much instruction text it loads, 32 KiB by default, and it is documented. What the documentation does not make obvious is where the cut lands. This guide shows what each tool documents, what we measured, a script that tells you where your own cut is, and what to take out of the file so it stops growing.
What each tool documents
| Codex | Claude Code | Grok Build | |
|---|---|---|---|
| Size limit on instruction files | project_doc_max_bytes, "32 KiB by default". Codex "stops adding files once the combined size reaches the limit" | None documented for CLAUDE.md. The guidance is "target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence" | Terminal UI: "Files are loaded in full, with no size cap; short, specific instructions are followed more reliably than long ones" |
| Order | Global file from the Codex home, then "from the root down", "files closer to your current directory override earlier guidance because they appear later in the combined prompt" | Every CLAUDE.md (or AGENTS.md, when there is no CLAUDE.md) from the working directory up, at session start; subdirectory files when Claude reads a file there | Global rules in ~/.grok/, then every directory from the repo root down, "deeper files taking precedence on conflicts" |
| What the docs say to do when it is too big | "Raise project_doc_max_bytes or split large files across nested directories" | Move what matters for part of the code into path-scoped rules. Imports "don't reduce its context cost". HTML comments "are stripped before the content is injected" | Keep instructions short and specific |
| How to see what loaded | A plaintext TUI log with codex -c log_dir=./.codex-log, or the session file. RUST_LOG=warn codex exec … also names the file it cuts (measured, not documented) | /context all, under Memory files | grok inspect, with "approximate token count" per file |
Codex is the only one of the three with a hard cap, so it is the one where a long file loses text instead of only costing more.
What we measured
On one Linux machine, on December 2, 2026, with codex-cli 0.156.1 and Claude Code 2.1.329. Each case builds a fresh git repository, writes instruction files of 100-byte lines with marker lines at known byte offsets, and starts one headless run: codex exec or claude -p.
Instead of reading logs, we pointed each tool at a local stand-in for its API on 127.0.0.1: about twenty-five lines of Python for the Responses API, configured as a custom model provider in a throwaway CODEX_HOME, and about sixty lines for the Messages API. Each one records the request and answers "ok". No model call runs, no account is used, and we see the exact text the model would have received. Codex sends the instruction files in the first user message, in a block headed # AGENTS.md instructions for <directory>.
# $CODEX_HOME/config.toml for the lab
model_provider = "fake"
[model_providers.fake]
name = "fake"
base_url = "http://127.0.0.1:18741/v1"
wire_api = "responses"
env_key = "FAKE_KEY"| Codex case | What reached the model |
|---|---|
Root AGENTS.md, 20 KB | all of it |
Root AGENTS.md, 48 KB | the first 32,768 bytes, ending inside line 328: "…every change in this part of t" |
Root 30 KB + services/api/AGENTS.md 8 KB, started in services/api | the root file whole, then the first 2,068 bytes of the nested file, ending inside its line 21 |
Root 48 KB + the same nested 8 KB, started in services/api | the first 32,768 bytes of the root file; the nested file not at all |
~/.codex/AGENTS.md 10 KB + root 30 KB + nested 8 KB | the global file whole, the root whole, the nested file cut at the same byte as without the global file |
Root 48 KB, -c project_doc_max_bytes=65536 | all of it |
Root 40 KB + nested 8 KB, -c project_doc_max_bytes=65536 | both files whole |
Root AGENTS.md that starts with a 20 KB HTML comment, then 20 KB of rules (40 KB) | the comment, sent as text, and the first 12,359 bytes of the rules |
| 40 KB of Portuguese rules with accents and a ✔ on every line | cut at byte 32,768, in the middle of a word. In this file the cut fell between two characters; in a second file, where byte 32,768 was the first byte of a ✔, the model got a � (U+FFFD) in its place |
AGENTS.override.md (1 KB) next to AGENTS.md (20 KB) | the override only |
CLAUDE.md only | nothing; with project_doc_fallback_filenames = ["CLAUDE.md"], the CLAUDE.md |
In every Codex case the terminal said nothing about instruction files; the only warning we saw was about model metadata for our stand-in model name. The text sent to the model had no note that anything was cut. Codex 0.156.1 does write one line about it, at a log level the terminal does not show: with RUST_LOG=warn, codex exec printed project doc exceeds remaining budget; truncating path=…/services/api/AGENTS.md remaining_bytes=2068. A file left out entirely, as in the 48 KB + 8 KB case, gets no line at all.
| Claude Code case | What reached the model |
|---|---|
CLAUDE.md, 48 KB | all of it |
CLAUDE.md, 200 KB | all of it; the first request body was 256,545 bytes |
CLAUDE.md with only @AGENTS.md, and a 48 KB AGENTS.md | all of AGENTS.md |
Root CLAUDE.md 30 KB + services/api/CLAUDE.md 8 KB, started in services/api | both files whole |
AGENTS.md (20 KB) and no CLAUDE.md | all of AGENTS.md |
AGENTS.md (20 KB) and a 1 KB CLAUDE.md | the CLAUDE.md only, as its documentation says |
AGENTS.md that starts with a 20 KB HTML comment, then 20 KB of rules | all the rules, and none of the comment |
Five things the lab shows
1. Codex cuts at a byte, not at a file. The documentation says Codex stops adding files once the combined size reaches the limit. In our runs it did not stop at a file boundary: it kept the file that crossed the limit, cut at exactly 32,768 bytes, in the middle of a line and in the middle of a word. The model gets half a sentence and no sign that the rest exists.
2. The file closest to your work is the one that loses. Codex puts the nested files last so that they win on conflicts. When the budget runs out, last also means first to go. With a 30 KB root, the payments file kept 2 KB. With a 48 KB root, it was not sent at all, and the rules most specific to the code you are touching are exactly the ones that disappear. A team that follows the documented advice, splitting a big file into nested ones, still loses if the root alone is near the cap.
3. Your global file did not count. A 10 KB ~/.codex/AGENTS.md reached the model whole and did not move the cut in the project files by one byte. The 32 KiB budget in our runs was for the project files only. A bigger personal file does not push the team's rules out; a smaller limit on one machine does.
4. Comments cost Codex bytes; Claude Code strips them. A 20 KB block of maintainer notes inside <!-- --> at the top of the file went to Codex as plain text and pushed most of the rules out: only the first 12,359 bytes of them arrived. Claude Code removed the comment before sending and delivered every rule. A comment that is free in one tool is 20 KB of budget in the other.
5. Claude Code does not cut, it sends everything. A 200 KB CLAUDE.md went whole into the first request. That is not a loss of text, it is a cost: every request carries the file, and Claude Code's own documentation says longer files reduce adherence. Grok Build documents the same choice, full load and no cap, which we did not run. A file that fits in Claude Code and Grok Build can still be cut in Codex, so the tool with the cap sets the real size limit for a team that uses more than one.
Find your own cut: two minutes
Run this from the directory where you start Codex. It walks from the git root down to where you are, picks the same file Codex would pick in each directory (AGENTS.override.md, then AGENTS.md, then any fallback names you pass) and prints where the budget runs out. It does not count your global file, as in our runs.
#!/usr/bin/env python3
"""agents-md-budget.py: which AGENTS.md lines Codex keeps under project_doc_max_bytes.
Usage: python3 agents-md-budget.py [limit_bytes] [fallback names...]"""
import os, subprocess, sys
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 32768
names = ["AGENTS.override.md", "AGENTS.md"] + sys.argv[2:]
cwd = os.getcwd()
try:
root = subprocess.run(["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, check=True).stdout.strip()
except Exception:
root = cwd
dirs, d = [], cwd
while True:
dirs.insert(0, d)
if d == root or os.path.dirname(d) == d:
break
d = os.path.dirname(d)
left = limit
print(f"budget {limit} bytes (your ~/.codex/AGENTS.md is not counted)")
for d in dirs:
for n in names:
p = os.path.join(d, n)
if os.path.isfile(p) and open(p, "rb").read().strip():
data = open(p, "rb").read()
rel = os.path.relpath(p, root)
if left <= 0:
print(f"NOT LOADED {rel} ({len(data)} bytes)")
elif len(data) <= left:
print(f"full {rel} ({len(data)} bytes)")
else:
line = data[:left].count(b"\n") + 1
lost = data[left:].count(b"\n")
print(f"CUT {rel}: keeps {left} of {len(data)} bytes, "
f"stops inside line {line}; ~{lost} lines after it never reach the model")
left -= len(data)
breakOn the lab repository with a 30 KB root, started in services/api:
budget 32768 bytes (your ~/.codex/AGENTS.md is not counted)
full AGENTS.md (30700 bytes)
CUT services/api/AGENTS.md: keeps 2068 of 8100 bytes, stops inside line 21; ~61 lines after it never reach the modelCodex cut that file inside line 21 too. Run it from each directory your team starts Codex in, and from the one your CI job uses. If you raised the limit, pass it: python3 agents-md-budget.py 65536. Then open each CUT or NOT LOADED file at the line it names and read what is below it.
What to do about it
Raise the limit where Codex runs. project_doc_max_bytes = 65536 in config.toml, or -c project_doc_max_bytes=65536 on a codex exec line in CI, brought back every rule in our 48 KB and 40 + 8 KB cases. It is a setting of each machine that runs Codex, so it has to be set on every laptop and every runner, and a machine that missed it cuts silently. It also makes the file cost more on every request, in Codex and in the tools without a cap.
Take the comments out. Notes for humans inside <!-- --> are free in Claude Code and full price in Codex. Move the history and the reasoning to a docs/ file the instructions link to.
Stop the file from growing. A cap only hurts a file that keeps growing, and instruction files grow from one kind of line: the thing that is true now. "Deploys are frozen until the 5th." "The payments sandbox is read-only during the migration." "/v1/orders is frozen, use /v2/orders." Each one was the right thing to tell every agent on the day it was written. Each one has an end date nobody writes down, and nobody deletes the line when the date passes. Six months later the root file is 30 KB, half of it is history, and the cap falls on the payments team.
Split by how long it stays true:
Keep in AGENTS.md | Move out of AGENTS.md |
|---|---|
| How to build, test and run | A state with an end date: a freeze, a read-only sandbox, a migration |
| Conventions for this code | A decision that will be revisited, with who made it and when |
| Rules that hold until someone changes them in a pull request | What one run found that the next run has to know |
| Short enough that every tool loads all of it | The reasoning and history behind the rules |
The first column stays reviewed and versioned with the code. The second column needs a place that has a date on every value, that replaces an old value instead of piling up next to it, and that an agent reads when the request is about it, not on every request.
The same setup with ValorBrain
ValorBrain is a memory server for teams of agents, reached over MCP at one URL from every repository, tool and machine. The freeze becomes one keyed fact with a date, instead of a line in the root file:
{
"tool": "upsert_keyed_fact",
"arguments": {
"fact_key": "deploy.production.freeze",
"fact_value": "frozen until 2026-12-05 (payment provider migration); hotfixes need the on-call lead",
"as_of": "2026-12-02",
"evidence": "#eng-announce, 2026-12-02 09:10",
"authority": "agent"
}
}"agent" because an agent is copying an announcement. "human" is for the words of whoever decided: it needs them verbatim in human_order, sent with a token bound to that person, and without that the write is refused and nothing is saved.
On December 5 someone writes the new value under the same key and it replaces the old one; keyed_facts_as_of still returns what was in force on any earlier date. Nothing accumulates in the instruction file, so nothing pushes the payments rules past the cap.
The root AGENTS.md gets a few lines instead of the growing list:
## Team memory
States with a date (freezes, migrations, read-only systems) and decisions that will be revisited
live in the team memory, not in this file. Before deploys, migrations or anything touching
payments, read it; when you learn one, write it with `upsert_keyed_fact`, with the date.On a developer's machine, one command adds the server, writes the memory rules into the harness's user-level instruction file (for Codex, ~/.codex/AGENTS.md, which in our runs did not count against the 32 KiB) and installs hooks:
npx -y @valorbrain/connect@latest --token <vbm_…> --harness <claude-code|codex|grok>On Claude Code and Codex a hook fetches memory at session start and on each prompt. memory_prepare returns the keyed facts whose key shares a word with the request, or whose value shares two, up to 12 by default, so a request about a deploy brings deploy.production.freeze and "rename this component" does not. A CI job gets none of the hooks: it needs the MCP entry and a few lines in the job's prompt, as Headless and scheduled agent runs shows.
What ValorBrain does not do
- It does not shrink your
AGENTS.md. Moving the dated lines out is your job, and the lines you leave in are cut by Codex exactly as before. - It does not change Codex's cap. If the file that stays is over 32 KiB, raise
project_doc_max_bytesor shorten it. - It does not replace the file for rules that apply to every request. A fact reaches the model when the request matches it. "Never call the live refund endpoint from tests" has to hold even when the request does not mention refunds, so it belongs in the payments
AGENTS.md, inside the budget. - It does not reach a harness that is not connected to it. An agent without the server, or a CI job without the token, reads nothing from it.
What we ran and what we did not
Twenty cases, one run each, on one Linux machine, with throwaway repositories, filler text and local stand-ins for both APIs: thirteen in Codex and seven in Claude Code, and two of the Codex cases run again with RUST_LOG=warn. No model call ran, so the lab shows what each model receives, not what it does with it, and it does not measure adherence on long files. We did not run the Codex TUI, the IDE extension or Codex cloud tasks, a project-level Codex config, macOS or Windows. Grok Build is not installed on the lab machine: its column is documentation only, and its "no size cap" is not measured. We did not test Claude Code's .claude/rules/ or subdirectory files loaded on demand.
The lab is one bash script, a file generator and the two stand-in servers. They build everything under /tmp and delete it after.
Checklist
- You ran the budget script from every directory your team and your CI start Codex in, and no file shows
CUTorNOT LOADED. - If you raised
project_doc_max_bytes, every laptop and every runner has the same value. - No maintainer notes inside
<!-- -->in a file Codex reads. - Nothing in the root
AGENTS.mdhas an end date. Freezes, migrations and read-only systems live somewhere with a date on them. - Rules that must hold on every request in one part of the code are in that directory's
AGENTS.md, near the top. - The root file is short enough that a nested file still has room after it.
Sources, read on December 2, 2026: Codex, Custom instructions with AGENTS.md (discovery, merge order, project_doc_max_bytes, fallback names, verifying what loaded), and the default project_doc_max_bytes = 32768 in the codex-cli 0.156.1 binary; Claude Code, How Claude remembers your project (size guidance, imports, HTML comments, when AGENTS.md loads); Grok Build, AGENTS.md (Terminal UI) (discovery, no size cap, grok inspect); the documentation that used to be at cursor.com/docs now redirects to docs.grok.com and calls the product Grok Build.
Next: CLAUDE.md, AGENTS.md and .cursor/rules in one repo for which file each tool reads, A decision in one repo, an agent in another for what an agent reads from outside its own repository, and Claude remembered it on one laptop for the cut in Claude Code's auto memory index.
Claude Code auto memory: what your team doesn't get
Auto memory stays on the machine that learned it, so the teammate and the CI job hit the same wall. Where it loads, where it's cut, where a team keeps it.
A 40,000-character MCP tool result: what the model gets
Codex keeps about 6 KB from each end; Claude Code moves anything past 50,000 characters to a file. A script to size your own tool's result, and what to change.