# Prune CLAUDE.md and AGENTS.md: the ablation protocol

URL: https://developertoolkit.ai/en/workflows/context/pruning-context-files/
Description: Trim bloated CLAUDE.md, AGENTS.md, and Cursor rules through ablation: move hard rules to hooks, procedures to skills, and verify every surviving line.

Pruning context files means treating `AGENTS.md`, `CLAUDE.md`, and `.cursor/rules/*.mdc` as a strict budget to cut rather than an incident log to extend. Developers and tech leads use the ablation protocol to archive bloated instructions, restore only lines backed by repeated failures, route hard rules into hooks and procedures into Agent Skills, and re-prune whenever models upgrade.

Three months ago you added a sentence telling the agent never to run `pnpm build` while the dev server is running. Today it ran `pnpm build` with the dev server up. The reflex is to rewrite that sentence in all caps with `IMPORTANT:`. Doing so lengthens the file, and a longer file is a primary reason the agent stopped following it. If you have not written a root file yet, start with [concise repository context](/en/workflows/context/agents-md-context/) first.

## Why longer context files make agents less reliable

**Accretion** adds a new line after every stumble, so the instruction file grows monotonically. **Ablation** removes instructions deliberately to measure which ones genuinely change behaviour, restoring only what provably prevents recurring defects. Four architectural mechanics explain why accretion backfires:

- **Instructions are advice, never enforcement.** Instruction files compete with code, tool outputs, and conversation turns for attention. Past 150–200 lines, compliance drops and conflicting rules produce unpredictable behaviour.
- **Overhead multiplies across subagents.** Every subagent inheriting the root instruction hierarchy pays that same fixed token cost again across parallel runs.
- **Byte budgets truncate silently.** Codex enforces a combined byte cap across project `AGENTS.md` files from root down; bloated root files truncate your specific subdirectory instructions first.
- **Stronger models need less scaffolding.** Every rule bets that the model cannot infer a convention from code. Upgrade frontier models and old hand-holding turns into noise; when teams mix frontier and cheaper CI models, write for the least capable reader and re-ablate whenever model tiers shift ([models hub](/en/ecosystem/models/)).

## Route every surviving line to the right layer

Once you understand what loads at launch versus on demand across Claude Code, Codex, and Cursor, pruning stops being a binary delete-or-keep choice and becomes a routing exercise.

| What the line expresses | Claude Code | Codex | Cursor |
| --- | --- | --- | --- |
| Universal repo contract (≤ 150 lines) | `CLAUDE.md` importing `@AGENTS.md` | Root `AGENTS.md` | Root `AGENTS.md` (avoid duplicating in always-applied rules) |
| Convention for one file pattern or package | `.claude/rules/<topic>.md` with `paths` or nested `CLAUDE.md` | Nested directory `AGENTS.md` (`AGENTS.override.md` to override) | `.cursor/rules/<topic>.mdc` with `globs` and `alwaysApply: false` |
| Multi-step workflow or runbook | [Skill](/en/ecosystem/skills/) in `.claude/skills/<name>/SKILL.md` | Skill in `.agents/skills/<name>/SKILL.md` | Agent Skill (`SKILL.md`) |
| Non-negotiable "never" boundary | `PreToolUse` / `Stop` [hook](/en/workflows/harness/agent-hooks/) + [permissions](/en/workflows/harness/permissions-and-sandboxing/) | Hook, `sandbox_mode`, or CI gate | Hook or required CI gate |
| Personal preference | User config or gitignored `CLAUDE.local.md` | User-level `AGENTS.md` | User rules |
| Maintainer rationale | HTML comment (`<!-- ... -->`) | README or ADR | README or ADR |

Two heuristics clear out most bloat immediately:

1. **Any rule beginning with "When working on…"** belongs in a path-scoped rule or nested `AGENTS.md`, never in the always-loaded root file.
2. **Any rule whose violation costs real debugging time** belongs in a deterministic [hook](/en/workflows/harness/agent-hooks/), permission rule, or CI check rather than prose.

**Imports organize files—they do not save tokens**

Splitting a 400-line `CLAUDE.md` into five `@` imported files still loads all 400 lines at session start. Genuine token savings come from deleting derivable facts, moving procedures to on-demand `SKILL.md` skills, and scoping path conventions with `paths` or `globs`.

## Run the five-step ablation protocol

1. **Archive the bloated instructions and start an ablation log.** Move existing instruction files into a dated archive folder, reduce root `AGENTS.md` to your layout, exact verification commands, and core boundaries, and create `CONTEXT-ABLATION.md` recording the archived line counts and active model. Work normally for one week; restore a line only after the same failure occurs **twice** in separate sessions.

     **Claude Code**

       Archive `CLAUDE.md`, `CLAUDE.local.md`, and unscoped `.claude/rules/` files. Pause auto-memory during the ablation week so it does not quietly rewrite deleted corrections back into your session, and verify loaded files in the context inspector ([Claude Code docs](https://code.claude.com/docs)).

     **Codex**

       Archive every `AGENTS.md` and `AGENTS.override.md` in the tree by moving rather than emptying them, and confirm workspace trust before comparing runs ([OpenAI Codex docs](https://developers.openai.com/codex)).

     **Cursor**

       Archive `.cursor/rules/*.mdc` files and audit user-level and team-managed rules in settings so hidden always-applied rules do not skew the baseline ([Cursor docs](https://cursor.com/docs)).

2. **Audit every archived line with a strict verdict.** Run the line-by-line audit prompt below so the agent classifies each sentence with repository evidence instead of polite agreement.

   **Copy-paste prompt: aggressive line-by-line ablation audit**

   ```text
   Read the archived instruction files in docs/context-archive/.
   Output one table row per rule: | Rule | Verdict | Evidence |

   Use exactly one verdict:
   - CUT-DERIVABLE: inferable from source files or manifests (cite up to 3 files).
   - CUT-ENFORCED: already enforced by linter, typechecker, formatter, or tests (cite config).
   - CUT-STALE: names a path, script, or package that no longer exists (verify in tree).
   - MOVE-PATH: applies only to a subset of files (state the glob and match count).
   - MOVE-SKILL: multi-step procedure better suited to an on-demand SKILL.md.
   - MOVE-HOOK: hard "never/always" rule that must be enforced deterministically.
   - KEEP: removing it causes a mistake impossible to derive from code.

   Give the aggressive cut, not the polite one. End with KEEP line count.
   ```

3. **Extract scoped rules, skills, and hooks.** Convert `MOVE-PATH` clusters into scoped `.claude/rules/*.md`, `.cursor/rules/*.mdc`, or nested `AGENTS.md` files (a rule true for three of four packages belongs in those three packages, never the root). Move `MOVE-SKILL` procedures into [Agent Skills](https://agentskills.io) with trigger-focused descriptions, and replace `MOVE-HOOK` prose with tested [hook scripts](/en/workflows/harness/agent-hooks/) and CI checks.

4. **Consolidate to one source of truth.** Merge remaining tool-agnostic `KEEP` lines into root `AGENTS.md`, reduce `CLAUDE.md` to `@AGENTS.md` plus minimal Claude-only notes, and eliminate overlap with always-applied Cursor rules.

5. **Prove behaviour and re-ablate on model upgrades.** For any disputed rule, run an A/B test in two fresh sessions—one with the rule, one without—and compare diffs. Schedule the next pruning round when your default model upgrades rather than waiting for calendar quarters.

**Copy-paste prompt: falsifiability test for a disputed rule**

```text
I want to test whether this instruction changes behaviour:
"<paste rule verbatim>"

1. Pick one real task in this repository where this rule should alter your output.
2. Describe the exact observable difference (import chosen, command run, or file
   structure) with the rule loaded versus omitted.
3. If you cannot name an observable difference, mark the rule UNFALSIFIABLE.
Do not edit any files.
```

## Verify the pruned file and prevent silent regrowth

Pruning is safe only when automated checks confirm nothing regressed and block accretion from creeping back in:

- **Run `@wondelai/harness-audit`.** Execute `npx @wondelai/harness-audit` locally and in CI (`--ci --min-score`). Station 1 explicitly enforces an instruction budget (flagging root files over 150 lines) and detects duplicate policies across `AGENTS.md` and `CLAUDE.md` ([harness audit checks](/en/reference/harness-audit-checks/)).
- **Enforce a CI line-count gate.** Add a lightweight check to your pull-request workflow so any commit pushing an always-loaded instruction file over your agreed ceiling fails automatically:

```bash
# CI step: fail when any root agent instruction file exceeds 150 lines
for f in AGENTS.md CLAUDE.md; do
  [ -f "$f" ] || continue
  lines=$(wc -l < "$f")
  if [ "$lines" -gt 150 ]; then
    echo "$f has $lines lines (limit 150). Prune or extract to scoped rules/skills."
    exit 1
  fi
done
```

- **Require ablation evidence in review.** Protect instruction files with `CODEOWNERS` so the tech lead signs off on every addition, requiring two dated failures in the ablation log—or a failing test case—before adding new always-on prose.
- **Watch existing CI gates.** Unit tests, type checks, and lint remain your real behavioural oracle; if pruning breaks anything load-bearing, CI surfaces it immediately.

## When pruning context files goes wrong

- **A rule is still ignored after shortening the file.** Check three causes in order: confirm the file actually loaded (verify workspace trust in Codex and loaded memory files in Claude Code), check for a contradicting rule in user-level or scoped configs, and verify the rule is falsifiable rather than vague advice.
- **You cut a load-bearing constraint and CI caught it.** That is the protocol working as intended. Restore that single line from the archive, cite the failure in `CONTEXT-ABLATION.md`, and leave the rest of its archived section deleted.
- **Auto-memory quietly reintroduces deleted prose.** Automated memory features record corrections over time. Audit personal and project memory whenever you review `AGENTS.md`, or disable auto-memory for shared repos where curated rules govern behaviour.
- **Codex follows root rules but drops directory-specific rules.** You hit Codex's combined byte cap across `AGENTS.md` files, truncating the deepest files first. Cut the root file further and extract runbooks into `.agents/skills/`.
- **Teammates disagree over deleted lines.** Settle disputes with the falsifiability A/B prompt and the two-strike log rather than debate. Any line that changes no observable artifact across fresh sessions stays out.

## Official docs and next steps

Consult vendor docs for current memory inspection, auto-memory settings, and scoped rule syntax: [Claude Code docs](https://code.claude.com/docs), [OpenAI Codex docs](https://developers.openai.com/codex), [Cursor docs](https://cursor.com/docs), and [Agent Skills](https://agentskills.io).

- [AGENTS.md and concise context](/en/workflows/context/agents-md-context/) — Structure the lines that survive pruning into one verified multi-tool contract.
- [Agent hooks](/en/workflows/harness/agent-hooks/) — Replace brittle 'never' prose with deterministic pre-tool and stop gates.
- [Agent Skills](/en/ecosystem/skills/) — Package extracted multi-step procedures as on-demand SKILL.md workflows.
- [Making a codebase agent-ready](/en/workflows/harness/agent-ready-codebase/) — Strengthen tests, types, and boundaries so short instruction files carry less load.
