Skip to content

Pruning CLAUDE.md and AGENTS.md: The Ablation Protocol

Pruning context files means treating CLAUDE.md, .cursor/rules, and AGENTS.md as a budget to cut rather than a log to extend: instead of adding a rule after every mistake, the ablation protocol removes lines, watches for repeated failures over time, and restores only what demonstrably breaks without it. The practice reflects a July 2026 shift across tool vendors away from accretive instruction files toward smaller, evidence-tested ones.

Three months ago you added a line telling the agent never to run pnpm build while the dev server is up. This morning it ran pnpm build while the dev server was up. Your instinct is to rewrite the rule in bold, prefix it with “IMPORTANT”, and maybe add “YOU MUST” for good measure.

That is the wrong fix, and it has been the wrong fix for a while. What changed in July 2026 is that the people who build these tools stopped disagreeing about it.

What you’ll walk away with from the ablation protocol

Section titled “What you’ll walk away with from the ablation protocol”
  • A dated map of why every guide you have read contradicts every other guide, and a one-question test for telling which era a post belongs to
  • The mechanics each tool’s docs bury: which of your files load at launch, which load lazily, which “optimization” saves nothing at all, and the 32 KiB cut Codex makes without telling you
  • A routing table that answers “where does this line go” across all five destinations: root file, subdirectory file, path-scoped rule, skill, hook
  • Nine copy-paste prompts, with the per-tool deltas spelled out, that do the deleting and the moving for you
  • A protocol for re-running all of it the next time you change models, which is the trigger that actually matters

Why every guide you found contradicts every other guide

Section titled “Why every guide you found contradicts every other guide”

Here is the short version: the advice inverted, and almost nothing you will read is dated clearly enough for you to tell which side of the inversion it sits on.

Two words make the rest of this readable. They are not our coinages — they are the vocabulary Anthropic and the Claude Code team use themselves.

Accretion is growth by accumulation. Every time the model does something you did not want, you add a line telling it not to. The file only ever gets longer, and every rule is a scar from one specific past mistake.

Ablation is the opposite: deliberately cutting material away to see what happens without it. It is borrowed on purpose — ablation is the standard term in machine-learning research for removing a component to measure its contribution, and it is the word Anthropic used for what it did to Claude Code’s own system prompt.

The timeline:

  1. December 2025. The Agent Skills spec lands. Every context-file guide written before this date had nowhere else to put conditional knowledge, so it all went in the main file. That is why 2025-era templates look maximalist. They were not wrong at the time — they predate the alternative.
  2. January 2026 — accretion is the default. Boris Cherny, who created Claude Code and still runs it, describes the team’s own checked-in file: “Anytime we see Claude do something incorrectly we add it to the CLAUDE.md, so Claude knows not to do it next time.” The companion tip: end every correction with “update your CLAUDE.md so you don’t make that mistake again.”
  3. June 2026 — the tension shows. In a year-in-review conversation the same team describes itself as context-minimalist at the system-prompt level (“the minimal possible system prompt, the minimal possible tools, and then you let the model figure it out”), and restates the accretive project-file advice in the same breath.
  4. 24 July 2026 — the number. Anthropic publishes “The new rules of context engineering for Claude 5 generation models.” The Claude Code team removed over 80% of the system prompt for models like Opus 5 and Fable 5, with no measurable loss on coding evaluations.
  5. 26-27 July 2026 — ablation is the default. Opus 5 ships. The next day, the advice to users is the inverse of January’s: delete your context files, your skills and your hooks every six months, and see what the model can do without them before you add anything back.

Both camps say prune. They are opposite in default direction and cadence. Accretion says add on every error and edit occasionally. Ablation says delete everything periodically and add back rarely. Same team, inverted default, as the models crossed a capability threshold.

Which gives you the test: if a post about context files does not tell you when it was written, you cannot use it. Anything before December 2025 predates skills. Anything before late July 2026 predates the ablation turn. That includes most of the top search results, and it includes several articles on this site that we have since corrected.

Before you go and delete anything, be clear about what the ablation advice is pegged to. The 80% cut was made for Opus 5 and Fable 5 specifically. The “delete everything” line came from an interview given the day after Opus 5 shipped. None of it was tested on, or claimed for, a mid-tier or older model — and plenty of people run Sonnet for cost, Haiku for volume, or a local model for privacy.

The principle underneath travels better than the specific advice:

The scaffolding you need is inversely proportional to the capability of the model reading it. Every rule you write is a bet that the model cannot work this out on its own. Better models win those bets back.

That reframes the whole argument as a dial you set, not a doctrine you follow.

Frontier thinking models (Opus 5, Fable 5, GPT-5.6 Sol and equivalents). Ablate aggressively. This is where the published advice applies as written. Expect to end up with a very short file.

Mid-tier and older models (Sonnet, Haiku, previous Opus generations, local models). Keep more — but understand that the trade is worse in both directions. These models genuinely benefit from explicit instruction: the package manager, the prerequisite, the gotcha. Their instruction budget is also tighter, because smaller and non-thinking models degrade faster as instructions pile up than frontier thinking models do. You need more rules and you can afford fewer of them, which makes prioritisation matter more, not less.

Mixed teams. If your repo is read by your Opus 5, a colleague’s Sonnet, and CI running something cheap, the file has to serve the least capable reader in the loop. Tune for that one. A strong model copes with a slightly over-specified file far better than a weak model copes with an under-specified one.

The practical upgrade to “delete it every six months”: re-ablate whenever you change models, not on a calendar. Six months is a proxy for “a model generation has probably passed.” A model switch is the actual trigger. And when you move down a tier — cost pressure, rate limits, an offline model — expect to add some back. That is the dial moving, not you regressing.

There is much less rigorous work here than the confident blog posts imply, and what exists is not a ringing endorsement. Three studies matter.

StudyWhat it actually found
Chroma, Context Rot (2025)18 frontier models, inputs from roughly 10k to 500k tokens. Every single one degrades as input length grows. Not most — all of them, at every increment tested. Degradation is non-uniform, and there is a pronounced lost-in-the-middle effect: a fact buried mid-context is far less likely to be used than the same fact at either end.
Jaroslawicz et al., How Many Instructions Can LLMs Follow at Once? (July 2025)The IFScale benchmark: 500 instructions, 20 models, seven providers. The best frontier models reach 68% accuracy at 500 instructions. Crucially, adding instructions degrades adherence to all of them, not just the new ones — and there is a measurable bias toward instructions that appear earlier.
Gloaguen et al., ETH Zurich, Evaluating AGENTS.md (v1 Feb 2026, v2 Jun 2026)The most direct study of whether repository context files help at all. The v2 abstract: context files “do not generally improve task success rates, while increasing inference cost by over 20% on average.” The v1 paper reported a granular split that v2 aggregates away: LLM-generated files about 3% worse, developer-written files about 4% better.

The most useful result is not the success rate. It is the mechanism. When a context file mentioned the uv tool, agents used it 1.6 times per instance versus under 0.01 when it was not mentioned — a 160-fold increase. Repo-specific tools showed a roughly 50-fold jump.

Instructions are followed. Sometimes to a fault. Every line you write is an attractor, pulling the agent toward whatever it names whether or not the task calls for it. That is the real cost of a long file, and it is why “harmless extra context” is not a thing.

The paper is equally direct about the single most common section in these files: “repository overviews, although popular and recommended by model providers, are not helpful.”

So do context files help? Less than the vendor consensus implies, and the honest answer is that this is not settled. A follow-up paper (Probe-and-Refine) points out that neither the ETH study nor its successors vary the agent’s step budget, which is a real confound, and notes that the two most rigorous studies in this area reach opposite conclusions. Treat the ~4% developer-written gain as v1’s finding within that study’s scope, not as a measured law.

What survives the disagreement is narrower, and the two halves of it carry different weight. Length has a real, measurable cost — that one is supported right across the table: Chroma measured it against input length, IFScale against instruction density, ETH against inference cost. Hand-written beats generated is the weaker claim: it is ETH v1’s result within its own scope, and neither of the other two studies compared authorship at all. Lead with the first. Neither depends on context files being a large win.

This is the section the official docs will not assemble for you, and it is where most wasted context lives. Everyone knows the main file loads every session. Almost nobody has checked which of the other mechanisms actually defer loading and which merely look like they do.

Loads every session: any .mdc rule with alwaysApply: true, plus User Rules and Team Rules. Team Rules are the easy one to forget, because they are managed from the dashboard rather than your repo — you can be paying for context you cannot see in your checkout.

Loads conditionally: rules with globs (only when you touch matching files), rules with only a description (only when the agent judges them relevant), and manual rules (only when you type @rule-name).

Loads lazily: AGENTS.md in subdirectories. This is newer than most guides and widely missed — Cursor reads AGENTS.md natively in the project root and in any subdirectory, applying it when you work with files in that directory or its children.

Two traps worth knowing:

  • Frontmatter is honoured only in .mdc files. Put globs or alwaysApply at the top of a plain .md rule and it is ignored — the file applies as-is, which usually means always. This is the single most common reason a “scoped” rule is silently costing you context on every turn.
  • /migrate-to-skills skips exactly the rules you most need to review. It converts dynamic rules and slash commands into skills, but excludes rules with alwaysApply: true or specific glob patterns. Your always-on rules are the expensive ones, and the migration tool will walk straight past them.

Cursor’s stated guidance is to keep rules under 500 lines and split large ones into composable files. Precedence when rules conflict: Team Rules, then Project Rules, then User Rules — all applicable rules are merged, and earlier sources win.

Once you know what defers, “should this line stay” becomes the wrong question. The right one is where does this line go. There are five destinations, and the main file is only one of them.

What you haveCursorClaude CodeCodex
Universal rule, needed every sessionAGENTS.md, or .mdc with alwaysApply: trueCLAUDE.md (target under 200 lines)root AGENTS.md
Rule that applies to a file type.mdc with globs.claude/rules/*.md with pathsnested AGENTS.md (directory-scoped only)
Rule that applies to one part of the reposubdirectory AGENTS.mdsubdirectory CLAUDE.mdsubdirectory AGENTS.md, or .override.md to replace
Multi-step procedure.cursor/skills/<name>/SKILL.md.claude/skills/<name>/SKILL.md.codex/skills/<name>/SKILL.md
Something that must actually happenhookPreToolUse / Stop hookhook (beta), or CI
Guidance only a weaker model needssubagent definition in .cursor/agents/subagent definition with model:subagent definition
Personal preference, not the team’sUser RulesCLAUDE.local.md~/.codex/AGENTS.md
Note for human maintainersREADMEHTML comment (costs zero tokens)README

Two rules of thumb fall out of that table.

If a rule starts with the word “when”, it does not belong in the main file. “When working on API handlers, validate with the shared schema helper” is a path-scoped rule wearing a disguise. Move it, and it costs you nothing until the agent actually opens something under src/api/.

If you would be genuinely annoyed when the model ignores it, prose is the wrong tool. Context files are advisory. In Claude Code the file is delivered as a user message after the system prompt, which is the mechanical reason it never binds. Hooks are deterministic. “Never run the build while the dev server is up” is not a sentence, it is a PreToolUse hook.

These are ordered as a protocol. Run 1 to establish what you actually need, 2 and 3 to delete, 4 through 6 to move what survives, 7 to harden what must not fail, 8 to consolidate, and 9 to prove any of it worked.

Each prompt has a shared core and a per-tool delta. The delta is genuinely all that differs — paths and a couple of tool-specific steps — so rather than printing three near-identical prompts, the core is stated once and the tabs carry only what changes.

Do not start by editing. Start by finding out what the file is buying you. This is the one step everybody skips, and it is the one that makes every later decision evidence-based instead of aesthetic.

The column that matters is the last one. Ablation says add a line back only after the model has failed the same way more than once. A single stumble is noise; the line you would have added is a bet you would have lost.

Archive .cursor/rules/ wholesale as well as AGENTS.md — and check the dashboard for Team Rules, which are not in your checkout and will keep applying while you think you have ablated.

The official test is one question per line: would removing this cause the agent to make a mistake? If not, cut it. The reason it works better as a prompt than as a manual pass is that the agent has to state a reason for every verdict, and reading twenty weak reasons in a row is what finally makes you delete them.

Expect the KEEP set to be about a third of what you started with. If it is not, the audit was too polite — say so and run it again.

Add: “Also list every rule file with its application type (Always / Intelligent / Glob / Manual) and its line count. Flag any .md file carrying frontmatter — frontmatter is ignored outside .mdc, so those rules are applying always regardless of what their globs field says.”

Every tool ships a command that writes you a context file, and every one of them writes a document optimised for describing your project to a human reader rather than for changing a model’s behaviour. Those are different jobs. This is also the direction the research is least kind about: LLM-generated context files scored worse than no file at all.

Run the generator if you like — it does surface commands and conventions, which saves you the discovery. Then cut it, hard, by category.

The file map deserves its own note, because it fails differently from the others. The rest of a bloated file merely costs you tokens. A file map goes stale, and stale context is worse than no context — it sends the agent confidently to a path that no longer exists. Your agent has search tools and is very good at using them. It does not need your map. It needs your map to not be wrong.

Cursor generates rules from the Settings pane and via chat. Whichever you used, run the trim before committing — generated rules default to alwaysApply, which is the most expensive setting available.

4. Move path-conditional rules out of the main file

Section titled “4. Move path-conditional rules out of the main file”

This is the highest-value mechanical move available and the one people use least. Any section that begins “when working on X” is conditional content sitting in an unconditional file, costing you attention on every turn where X is irrelevant.

Target is .cursor/rules/<topic>.mdc. The extension matters — frontmatter is ignored in .md:

---
description: "API endpoint conventions"
globs:
- "services/api/**/*.ts"
---
# API rules
- Validate every request body with the shared Zod schema helper
- Error responses use the { error, code } shape, never a bare string

5. Push content down into subdirectory files

Section titled “5. Push content down into subdirectory files”

In a monorepo the root file usually contains three teams’ worth of rules, and every one of them is paying for the other two. Subdirectory files are the fix, and in all three tools they are lazier than the root file.

Place AGENTS.md in each package directory. Cursor applies it automatically when you work with files in that directory or its children — no frontmatter, no configuration.

AGENTS.md # only what is true everywhere
apps/web/AGENTS.md # Next.js app conventions
services/api/AGENTS.md # API service conventions
packages/ui/AGENTS.md # component library conventions

Rules are constraints. Skills are procedures. If a block of your context file reads like a runbook — numbered steps, a sequence, “first do this, then that” — it is in the wrong place, and it has been since December 2025.

The difference is loading. A rule in your main file is read on every turn forever. A skill is read when it is relevant.

The last instruction is the one people resist. Leaving “see the deployment skill for deployment steps” in your main file re-adds the cost you just removed. Skill discovery is automatic in all three tools.

Skills live in .cursor/skills/ or .agents/skills/, with ~/.cursor/skills/ and ~/.agents/skills/ for personal ones. Cursor also reads .claude/skills/ and .codex/skills/, so a shared skill directory works across all three tools.

Cursor ships /migrate-to-skills, which converts dynamic rules and slash commands automatically. Run it first — but know that it excludes rules with alwaysApply: true or specific globs, which is precisely the expensive set. Those you move by hand with the prompt above.

Cursor’s own framing: “compared to always-on, declarative rules, skills are better for dynamic context discovery and procedural how-to instructions.”

Some rules you would be mildly disappointed to see broken. Others cost you an hour. The second kind does not belong in prose at all — context files are advisory, and a “never do this” line in markdown is a strong suggestion to a probabilistic system.

The related principle, put well by HumanLayer: your agent is not an expensive linter. Never spend context describing rules a deterministic tool already enforces. If Biome reformats it on save, do not also tell the model about it.

Cursor supports hooks, managed alongside plugins, skills, MCP servers, subagents, rules and commands from the Customize page at user, team or workspace level.

8. Consolidate to one source of truth, then check the budget

Section titled “8. Consolidate to one source of truth, then check the budget”

If more than one agent touches your repo, you almost certainly have two files saying nearly the same thing, drifting apart at the rate you edit them.

AGENTS.md is the open cross-tool format for this — plain markdown, no required fields, nearest-file-wins in monorepos, and natively read by Codex, Cursor, Copilot, Gemini CLI, Aider, Windsurf, Zed, Cline and others. Claude Code reads CLAUDE.md only, does not read AGENTS.md, and does not fall back to it despite what several posts claim.

The fix is one line.

Cursor reads AGENTS.md natively, root and nested, so there is nothing to wire up. What to check instead is overlap: if you have both AGENTS.md and .cursor/rules/*.mdc with alwaysApply: true, they are merged and you are likely paying twice for the same guidance. Add: “List every rule that appears in both AGENTS.md and an always-applied .mdc rule.”

9. Prove it worked, and schedule the next round

Section titled “9. Prove it worked, and schedule the next round”

The step everyone skips. If you added a rule and cannot point to a behaviour change, you added noise — and noise is not free, because every line is an attractor.

Then put the next round on a trigger rather than a date. Six months is a proxy for “a model generation has probably passed”; a model switch is the real event.

You shortened the file and the rule is still ignored. Shortening is the right first move, but it is not the only failure mode. Check for a contradiction: if two rules give different guidance for the same behaviour, the agent may pick one arbitrarily, and no amount of shortening fixes that. In Claude Code, run /context and confirm the file actually loaded — a rule in a file that never loaded looks exactly like a rule being ignored. Then check whether the rule is falsifiable at all. “Write maintainable code” cannot be followed or violated, so it cannot be fixed by making it louder.

You deleted something load-bearing and found out in CI. This is the expected cost of ablation, not a sign you did it wrong — and it is why the archive in prompt 1 is a dated copy rather than a deletion. Restore the single line, not the section it came from. The temptation after one failure is to restore everything, which puts you back where you started.

Codex is ignoring your instructions and you blamed the model. Check the byte budget before anything else. The 32 KiB cut never shows up in the TUI, and because project files load root-first it takes your nearest ones first — the specific ones you most recently wrote. The file that crosses the limit loads only partially, so you can also get half a rule. The symptom — deep, precise instructions ignored while vague global ones are followed — reads exactly like a model regression and is not one. Prompt 2’s Codex delta finds it in one pass.

Auto memory rebuilds what you deleted. In Claude Code this is the failure mode with the longest fuse. You ablate the file, and over the following weeks Claude writes its own notes about your corrections into a file you never review, which loads into every session. Accretion, automated. Run /memory on the same cadence you review the main file, or set autoMemoryEnabled: false and curate by hand.

Your team disagrees about what got cut. Treat the archive and the log as the artifact under review, not just the resulting file. A PR that shows “we removed 140 lines, here is the log of what actually broke over three weeks” is arguable. A PR that shows a 140-line deletion is not. Block-level HTML comments are free in Claude Code, so the rationale can live in the file itself without costing context.

Everything you just read went stale. It will. The advice inverted once in seven months and the tooling moves faster than that — /doctor gained the trim check in v2.1.206, Cursor added nested AGENTS.md and /migrate-to-skills in the 2.4 line, Codex’s context ceiling moved twice in July 2026 alone. Apply the same test to this article that you apply to the others: check the date, then check the tool’s own docs before you act on a specific flag or path.

Where to go next after pruning context files

Section titled “Where to go next after pruning context files”