Your AGENTS.md Gets Worse Every Time You Fix It
Sep 4, 2026 · AI & BuildingThe most common advice about agent instruction files is good advice. When your coding agent repeats a mistake you've already corrected once, write the correction down. Eric Ma puts it this way: “whenever you find yourself giving the same instruction twice, add it to AGENTS.md instead.”
A second piece of advice is also right: these files stop working when they get long. Tian Pan's analysis of instruction files puts reliable compliance at somewhere between 150 and 200 instructions. He finds that effective files cluster around a few hundred words, and that the correlation with length turns negative past about a thousand. You've probably lived the cycle he describes: the agent ignores a rule, so you add a clearer version, then it ignores a different rule, so you add that one too. A few weeks later the file is four hundred lines and the agent ignores more of it than ever.
The two clash somewhere around the fortieth correction. Keep writing corrections down and the file gets too long. Trim it and you lose the lessons that make an agent useful in a working codebase. Most writing on this says to trim, which keeps the file short, but nobody says where the trimmed corrections should go.
Quick answer: keep the corrections in a separate file, and put a short list of triggers in the always-loaded one. A trigger is a moment you can see coming, like “about to claim something is done” or “about to ship anything someone outside will see”, and each one tells the agent to open a separate registry and check it before acting. In my own workspace that trigger block is 11 lines and 130 words, and it points at a registry of 115 dated corrections totaling 17,853 words. All 115 are in force. None of them sit in the context window until a trigger fires.
Three Ways to Split the File, and Only One Handles Corrections
People already split instruction files by folder or by task. Both methods are well covered, and neither one catches repeat mistakes.
Split by directory. This is the AGENTS.md format's own recommendation. You put another AGENTS.md inside each package, agents read the nearest file in the tree, and the closest one wins. It works at scale too: the spec notes that OpenAI's main repository has 88 of them. The lookup key is where the file you're editing lives.
Split by task. This is progressive disclosure, and Tian Pan's piece already proposes it. You keep a small root file and move task guidance into separate documents the agent loads when it needs them. The lookup key is what the agent set out to do: it's about to run the tests, so it opens the testing document.
An agent won't go look up a correction on its own, because it doesn't know it needs it. If it had known the rule applied, it wouldn't have made the mistake that created the rule. A deploy mistake belongs to an action, so the folder key misses it. The task key misses it too: an agent that just finished a page and is about to call it shipped thinks it's done, and that's the moment the correction needs to interrupt.
| Split strategy | Lookup key | Good for | Fails on corrections because… |
|---|---|---|---|
By directorynested AGENTS.md | where the file lives | per-package build and style conventions | a mistake belongs to an action, and a folder can't see actions |
By taskprogressive disclosure | what the agent set out to do | reference material the agent knows to go find | the agent doesn't know it needs it, which is why it made the mistake |
By triggerfailure registry | a moment the agent is about to pass through | accumulated corrections | (n/a) |
A Trigger Names a Moment
The trigger list has to be short enough to load every time and specific enough to fire.
A trigger names an action you can observe. “Be careful with deployments” never fires, because an agent can't tell at any given moment whether it's being careful. “About to claim something is scheduled, sent, confirmed, done, fixed, or validated” does fire, because the agent is about to type one of those words. Listing the exact verbs makes it close to a word match against the agent's own draft.
It also fires before the action. “Deployments must be verified” gets checked at review time, after the damage. “Before you say the word done, go check” gets checked while stepping in is still free. Getting this order wrong is the most common way people write a useless rule.
And it points at exactly one file. “Check the relevant documentation” makes the agent decide what's relevant, on top of the call it already got wrong. With one named file, it runs one grep.
What it looks like. The always-loaded file has a block that reads roughly: fires on draft / dispatch / edit / send, then four short trigger conditions, then one sentence: on any trigger, read the registry and grep for matching entries before acting; treat it as authoritative, it overrides fresh-session recommendations that contradict it. I added that last clause because a capable model with strong priors will work out a recommendation the registry already recorded as a mistake, and then trust its own reasoning over the written record.
What Goes in an Entry, and Why Every Entry Needs a Date
Each entry in mine has five parts: an ID you can grep for, the symptom as it showed up, the condition when it fires, the fix, and the dated incident that caused the entry.
People leave out the date. Without it, every entry looks equally current and equally important, so nobody ever deletes one, and the registry grows until it's as unusable as the four-hundred-line file it replaced. With a date, you can go through entries and ask whether each cause was fixed at the root, and retire the ones that were.
Three Corrections From My Registry
All three happened on my own sites.
“A URL in the sitemap is not evidence the page was deployed.” A deploy shipped the homepage and the sitemap, which both referenced a new post, and never uploaded the post file itself. For three days the homepage linked to a 404, and the sitemap sent that 404 to Google. The file was in the repository the whole time. A second page did the same thing and sat at 404 for two weeks before anyone noticed. The entry says to curl the new page itself after every deploy, because checking the index that links to it proves nothing.
“Corrections propagate to tables; they don't propagate to sentences.” After a measurement audit, I corrected a set of benchmark figures across the tech site. Every table got updated and every page got checked. Three weeks later a new post cited the old numbers in its text, because whoever wrote it pulled them from memory and from an older post. The corrected source was on disk the whole time. The rule that came out of it is narrow. When a new page cites an existing measurement, re-open the source of record and never copy a number from memory or from another page. A later incident added to it, when a page attached made-up settings to a number that had been measured correctly. Now the rule also says to copy the conditions word for word, or write “not logged.”
“Two sessions on one machine race the git index.” This is my favorite. I had a one-writer-per-repository rule, and the agents were following it, but every session on a machine shares the repository's git index. Two agent sessions on the same machine can follow that rule and still collide. One session staged files and its commit command failed, so the work stayed staged. The other session's next commit swept those files into an unrelated message. The second time was worse. A commit included stale staged copies of two files and undid edits it had never touched, with no warning, under a message about something else. The fix is one line: stage and commit in a single command, or use git commit -o <file> -m <msg> to skip the index, so nothing sits staged in between.
A smarter model couldn't have worked out any of these three from first principles. They're facts about one specific setup that I found by breaking it, so a better model wouldn't make the registry unnecessary.
AGENTS.md or CLAUDE.md?
Use both, but keep the actual rules in only one. AGENTS.md is the vendor-neutral format, read by a long list of tools including Codex, Cursor, Gemini CLI, Copilot, Zed, Aider, Windsurf and Devin. CLAUDE.md is Claude Code's version, and GEMINI.md serves some Google tooling. The AGENTS.md spec doesn't mention either of them, so lining them up is your job.
When more than one agent works in a repository, you usually end up with three files that look reasonable and have drifted apart, so the agent's behavior depends on which tool you happened to open. I keep AGENTS.md as the one canonical file and make the others thin shims that import it and add only a pointer or two. Measured this morning, the canonical file is 4,057 words, the Claude shim is 100 words, and the Gemini shim is 161. A change in behavior gets made in one place.
The Numbers
Measured with wc on 2026-09-04:
| File | Role | Loaded | Size |
|---|---|---|---|
AGENTS.md | canonical entry file | every session | 153 lines / 4,057 words |
| ↳ trigger block | routes to the registry | every session | 11 lines / 130 words |
CLAUDE.md | shim, imports the above | every Claude session | 100 words |
GEMINI.md | shim, imports the above | every Gemini session | 161 words |
PITFALLS.md | failure registry | only when a trigger fires | 115 entries / 17,853 words |
The registry is 4.0× the byte size of the entry file that points at it, and roughly 137× the size of the trigger block that does the pointing. So 115 corrections cost about 1.1 words each of permanent context. Fold those same 115 entries into the always-loaded file and you'd have something like 22,000 words of standing instructions, far into the range where the published measurements say an agent follows fewer rules.
One catch: my own entry file is still 4,057 words. Tian Pan's data puts effective instruction files at a few hundred words, so mine is about four times too big even after the split. The split kept 17,853 words out of every session, and shrinking the entry file is my next job. If you copy one measurement from this page, copy the trigger block (130 words).
Building with agents in a real repo?
I run a free community for people building data and AI pipelines (warehouse modeling, analytics, AI-augmented workflows). Members trade notes on what they're shipping.
Join the free AI community →Frequently Asked Questions
Related reading: I Ran Claude Code and Codex Head-to-Head: two agents working the same spec in the same repo, which is the situation this file setup is built for. Multi-Model Verification: Catching LLM Hallucinations in Enterprise Reports: the same habit of never trusting a single pass, applied to output instead of instructions. Governing AI Agents' Data Access: the other half of agent governance, limiting what an agent may read instead of how it behaves. AI as an Operations Layer: where these agents run. For the hardware side, see Blendlogic Tech.
What would make this wrong
- It's one workspace, and I built it. Every number here is measured, but they all come from one setup designed by the person arguing for it. I haven't run the comparison (the same 115 corrections put into the entry file, the same tasks, compliance measured both ways), so the case rests on published length research plus my own incident record.
- I can't prove the triggers fire reliably. I can show the registry catches things, because I've added entries since it went in. I can't show how often an agent passed a trigger moment and skipped the check without saying so. That's the number that would settle this, and I have no way to measure it. A trigger that fires half the time still beats a rule lost in a long file, but “better” is a weaker claim than the one this page makes.
- My own entry file fails the standard I'm citing. At 4,057 words it's about four times past the point where the length research shows things getting worse. If that research is right, an entry file that's still too big is cancelling out part of what I credit to the split.
- Stale entries keep costing me. The FAQ example (four items listed as outstanding that were all done) turned up by accident during unrelated work, so my audit schedule today is “whenever someone happens to notice.” A registry with no scheduled re-audit will eventually cost more than it saves, and mine doesn't have one yet.
- Agent tools may make this unnecessary. If agent runtimes ship reliable rule lookup, such as hooks that always fire on tool calls or automatic search over a rules folder, a hand-written trigger block becomes a workaround for a gap that has closed. The registry and its dated entries would still be useful, and the trigger list is the part most likely to go.
- Small projects shouldn't bother. If you haven't corrected the same mistake twice yet, you don't need a registry yet. Start one when you catch yourself writing the same correction down a second time.
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.