A new study tracked a quarter-million AI agent instructions across 1,867 GitHub repositories and may have found the solution. (Hint: The answer is not “Delete it all.”)
By Karen Spinner
Published: 2026-08-31
URL: https://wonderingaboutai.substack.com/p/how-to-stop-your-claudemd-file-from
TL;DR: People (and the agents they delegate to) tend to keep adding rules to context files like CLAUDE.md until the files are bloated enough to cause context rot. A study by Kushal Chakrabarti of more than 1,800 GitHub repositories found that old rules are almost never deleted, and a follow-up experiment showed that AI models are more likely to keep rules files smaller when they add a comment alongside each new rule recording what failed, what they tried, and how it turned out.
Disclosure: Claude Fable drafted parts of this article, which I edited for style and accuracy. It covers a new preprint by Kushal Chakrabarti about why the files we write for AI coding agents never stop growing and eventually contribute to context rot. This is another entry in my series covering new AI research in mostly plain language.
About the study
Kushal Chakrabarti analyzed the full edit history of 1,867 GitHub repositories, following 247,694 individual instructions written for AI coding agents. He discovered:
-
The average instruction file more than triples in size over its lifetime. Files in about two-thirds of repositories grow, while only about a quarter of files ever shrink.
-
The older an instruction gets, the less likely anyone is to delete it. Once the reason behind a rule has been forgotten, removing it makes people nervous.
-
Roughly three out of four deletions happen in a single burn-it-down rewrite, and the file grows back to nearly full size within ten commits.
-
A one-line comment recording why each instruction was added removed over 99% of the bloat in a controlled test, with no loss of accuracy. Seriously.
-
If you’ve used Claude Code, GitHub Copilot, or any other agentic coding tool, you’re familiar with the context file. It may be called CLAUDE.md, AGENTS.md, or copilot-instructions.md, and it’s a plain-text list of rules for your AI. It includes things like “Use tabs, not spaces,” “Run the tests before committing,” and “Never touch the migrations folder.”
Every time the agent does something wrong, you add a line (or ask Claude to). And these instructions tend to accumulate over time.
Chakrabarti’s paper maps this phenomenon as it plays out in repos across GitHub, and then tests a possible solution that anyone can try.
Too much context is TMI for your agent
Context files are useful, at least when they’re well made. One study found that agents finish tasks about 29% faster, using about 17% fewer output tokens, in repositories that carry a context file (though not every study shows a benefit).
But there’s a catch. Benchmark research suggests that language models follow instructions worse as the number of instructions grows, and tests that stack constraints one at a time see compliance start slipping within the first five constraints. The median file in this study already contains 39 instructions.
So, while these files should stay small, they typically only expand. Why?
Three possible causes of context bloat
Earlier studies noticed bloated context files but only looked at how many lines they contained. This meant they couldn’t tell when context was deleted and replaced or rewritten. Chakrabarti tracked individual instructions instead, which let him test three competing explanations for context accumulation:
-
Staleness. Instructions go out of date as the project changes, and people just haven’t gotten around to pruning them.
-
Fragility. Badly written instructions are deleted, while useful instructions accumulate.
-
Imperfect recall. Once nobody remembers why an instruction was added, everybody is afraid to delete it.
How the study worked
The study was conducted in two parts, an analysis of more than 1,800 GitHub repositories and a simulated project in which the model attempted to complete a task with and without notes it wrote to itself between rounds.
Part 1: An autopsy of 1,867 repositories
This part of the study treated instructions the way an actuary treats people. Each instruction received a birth date (the commit where it first appears) and, sometimes, a time of death (the commit where it disappears). Statisticians use this kind of analysis to ask questions like “does the risk of a lightbulb burning out rise or fall as the bulb ages?”
In this case, the question was, “Does the risk of an instruction being deleted rise or fall as the instruction ages?” The three possible explanations each predict different answers:
-
Staleness predicts the risk of any individual instruction being deleted will rise with age, since old rules go out of date but remain in the file.
-
Fragility predicts the likelihood of deletion will fall with age, because bad instructions get deleted quickly, leaving mostly useful, well-written instructions behind.
-
Imperfect recall also predicts the chance of any instruction being deleted will fall over time, since contributors don’t remember the rationale behind older rules. It also predicts that the drop will be steeper in files edited by many people, since the reasons behind the rules are scattered across more individuals.
The final dataset covers nearly 300,000 file versions and 247,694 instruction lifetimes.
Part 2: Simulated writing tasks starting with zero context
You can’t measure “bloat” in a real repository, because the ideal CLAUDE.md will vary greatly across use cases. This means you can’t tell if any given file is too long for its purpose (even though most of them are).
So for the experiment, Chakrabarti chose writing tasks from Google’s IFEval, a benchmark that pairs writing tasks with explicit rules (”respond in valid JSON,” “stay under 200 words”) and automatic checkers for each rule.
He gave a model the tasks without the rules. Each round, the model attempted the task, the checkers graded the output, and the model received only a vague complaint like “the word count is off,” never the rule itself. It then edited its own rules file and tried again, for 15 or 51 rounds.
He ran three versions of this process for both the long and short experiments. First, the model’s rules file was passed as-is from one round to the next. Next, the rules were updated in each round with meaningless placeholder comments (”added to address a recurring issue”). And third, each rule was annotated with a real comment the model had written for itself, recording the failure that prompted it, the rationale for it, and how earlier attempts had gone.
All comments were stripped out before the model attempted the task, so they could only influence how it edited the rules, never how it wrote the answer. At the end of the experiment, Chakrabarti measured how often the model’s outputs passed automated checks and how big its rules file was vs. the smallest one that could have worked.
What the data showed
The repository autopsy settled which of the three explanations is right, and the zero-context experiment identified a successful approach to keeping CLAUDE.md files manageable.
Imperfect recall makes old instructions “undeletable”
The repo autopsy showed that the risk of deletion for instructions in agent context files fell over time. This ruled out staleness, leaving fragility and imperfect recall as possible explanations.
Chakrabarti then refit the data with a statistical model designed to account for the fragility effect (bad instructions dying early while sturdy ones survive). It was responsible for less than a third of the decline. He also looked at deletion risk in files edited by multiple authors and found it fell faster than in files edited by a single author.
All this strongly suggests that imperfect recall is the best explanation of why agent instruction files become bloated over time.
Deletion happens by demolition
Most instructions in CLAUDE.md and similar files are deleted in batches rather than one at a time. Roughly three out of four deletions happen as part of a wholesale rewrite, a single commit that wipes most of the file. This is likely because, when context rot sets in and line-by-line fixes don’t work, starting over is easier than working out which of dozens of unexplained rules is the culprit.
But just rewriting the file doesn’t work. A newly trimmed file drops to about 60% of its former size, climbs back above 90% within ten commits, and then grows faster than before. In other words, you can hack out all your bloat, but it comes back fast if you don’t fix the process that created it.
One-line comments nearly erased the bloat
In the short, 15-round version of the no context experiment, models working without comments ended with context files about 60% larger than the known minimum. Models with informative comments in their context file ended slightly below the minimum, while passing hidden checks at the same rate.
In the long, 51-round experiment, the comment-free rules files grew to 211% above minimum. The commented ones settled at 1% above. Writing useful comments removed over 99% of the excess.
Of course, the comments provided have to be meaningful. Placeholder comments performed just as badly as no comments.
What a useful comment records
Next, Chakrabarti analyzed the comments themselves, removing one element at a time to determine what, exactly, made comments useful enough to counter context creep.
After this exercise, he found that the most important information for the context file was the specific outcomes of previous efforts.
A comment describing past attempts without saying how they turned out actually performed worse than writing no comments at all, because it forces the model to build on a questionable story. Even dropping the count of how many rounds the same failure had happened reduced the comment benefit by more than one third.
In practice, a good comment might look like this:
Agent kept mocking the database in tests.
“Write realistic tests” failed twice; this wording stopped it.
Use the test database in tests; do not mock the data layer.
Smarter agents bloat faster
This study also discovered that smarter models are actually more susceptible to context bloat. When given the simulated tasks without comments, the excess context grew from about 68% above the minimum with the least capable model to over 570% above it with the most capable.
A smarter agent with no memory of its reasons just accumulates instructions more efficiently, and comments helped most for the strongest models.
Bloat degrades obedience
Chakrabarti’s final test seeded prompts from WildIFEval, a benchmark built from real human requests, with 16 irrelevant instructions borrowed from other tasks, and gave them to models as part of their context. This junk alone knocked 24 percentage points off the agent’s compliance with the correct rules already present.
What this means for your CLAUDE.md
Implementing the lessons from this study is easy. When you add an instruction to CLAUDE.md or a similar context file, write down the rationale behind it.
You can open the file and add comments yourself, or just tell Claude to do it whenever it’s time to record a new rule. The evidence suggests that this simple habit can minimize context bloat.
Disclaimer: The controlled experiment used tiny prompts (two or three ideal rules, versus the 39 in a typical real file) and one small model, and the real-world compliance results depend on an LLM judge. The repository data shows bloat happening in the wild, and the experiment shows comments stopping it in the lab. But the experiment did not show this effect in a real repo at scale.
The paper’s ethics note also warns readers against automating context deletions based on comments. This risks deleting important safety instructions.
Experiment at home
You can test this paper’s findings, even without code.
Run your own individual test
Open your project’s context file and run git log --follow -p on it to list every commit that ever touched the file along with the lines each one added and removed. Count the instructions appearing in each version and watch for the pattern from the paper, in which additions pile up and deletions rarely occur.
Then, once you have a baseline, start commenting (or instructing Claude to comment). Ensure every new instruction is paired with a note recording the failure that prompted it and what you’d already tried. Then track your file over time.
Try a simplified version of the full experiment
Replicating the controlled experiment is also straightforward, since IFEval is public (Apache 2.0, in Google’s google-research repository).
If you use Claude Code, make a folder containing a PDF of the study, and ask your coding agent to recommend a plan for replicating the study’s results at a smaller scale and provide a budget estimate for each alternative. (The original study used 38 million tokens.)
The paper says the author will share the data and code from the study, but prints no repository URL.
But if all you want is Claude to perform better, a possible solution to context bloat is available right now in any editor, on the file you already have.
Whew, you made it to the end! Subscribe for more AI research in mostly plain language and updates on my experiments.
