AI coding

What to Prune When a Context File Outgrows Its Token Budget

Antonio Evans9 min read

A clean editorial scene: a printed 40-page document on a desk, 18 pages set aside in a neat stack and 22 pages remaining in the main pile.
Key points

Key points

  1. 1Record a baseline pass rate on a fixed eval set, plus a second run to measure noise, before you edit anything.
  2. 2Sort each section into drop, rewrite or keep based on whether removal moves the pass rate and whether a shorter restatement holds it.
  3. 3Test one section at a time, because batched cuts hide which section was load-bearing.
  4. 4Stop at the first removal whose accuracy cost exceeds the tokens it frees, and log where you stopped.

Set the baseline before you cut anything

Pruning before evaluating leaves you with no signal, because model output is stochastic and "it looks fine" is not a measurement. Prompt evaluation exists to detect regressions before users do, using repeatable scoring across representative inputs rather than isolated examples Braintrust's guide to prompt evaluation. Build that instrument first.

A usable eval set is fixed, scored the same way every run, and large enough that one flaky case does not dominate. If you have nothing, a tiered minimum suite is a reasonable start: separate checks for general behavior, grounded behavior and tool use, mixing automated checks with a judge where automation cannot express the criterion the MVES framework paper. Twenty to fifty tasks works.

Record three numbers: the pass rate, the token count of the file, and the per-call prompt token count. Aggregate token totals hide the prompt bloat you are hunting, because small template additions accumulate without producing an obvious failure Braintrust on tracking token usage.

Then run the eval twice on the unchanged file. The gap between those two runs is your noise band. If three tasks swing with zero edits, a two-task swing after a deletion proves nothing.

The decision rule: three verdicts, one section at a time

Ask two questions per section, in order.

Does removing it change output? Delete the section, run the eval, compare against the noise band. If the pass rate holds, the section is not doing work: drop it. If the rate falls outside noise, the section matters and you move to question two.

Can the same instruction be stated in fewer tokens with the same effect? Compress it, run the eval. If the rate holds within noise of the pre-rewrite run, rewrite and keep the shorter version. If it falls, keep the original wording.

The discipline that matters is serial application. Bundling ten cuts into one commit and seeing the rate hold proves the ten together were unnecessary, not which five were. You will keep a bloated section because a good cut in the same batch masked its contribution.

There is a deliberate asymmetry here. Dropping is cheap to test and reversible; keeping costs tokens on every request. Every token in a persistent context file loads on every request regardless of relevance, so the file should be as small as possible Matt Pocock's AGENTS.md guide. That guide cites an instruction budget of roughly 150 to 200 instructions followed with reasonable consistency by frontier thinking models, and fewer for smaller or non-thinking ones. That is a ceiling on instruction count, not just characters.

Eval resultMeaningVerdict
Rate holds within noise after removalSection does not influence behaviorDrop
Rate falls on removal, holds after terse rewriteContent matters, wording was paddedRewrite
Rate falls on removal, falls again on rewriteContent matters and resists compressionKeep
Rate rises on removalSection actively harms outputDrop, then investigate
Verdict flips between runsNoise band too wide or set too smallUnresolved, grow the set

The last row is the one people skip, and it is the commonest reason pruning campaigns stall. A section that produces different verdicts on consecutive runs is a coin flip, not a finding.

Why noise is not a technicality

Non-determinism survives temperature zero. Outputs can vary across calls due to hardware numerics, decoding implementations, concurrency or upstream model changes the evaluation-driven iteration paper. That paper also reports a blunt warning: replacing task-specific prompts with generic "improved" rules moved extraction pass rate from 100% to 90% and RAG compliance from 93.3% to 80% for one local model, while instruction-following improved. Quality dimensions trade against each other.

So do not ask whether a section helps "generally." Sections help specific behaviors, and a change that improves format adherence can quietly break extraction. Split the eval into per-behavior buckets even if you report one headline number. When a removal drops the aggregate by three points, the buckets tell you whether you lost formatting or correctness. Those are not worth the same tokens, and your stopping rule needs that distinction.

Worked example: 40 sections to 22

Take a repository context document with 40 headed sections at 7,850 tokens: architecture notes, conventions, exact commands, known gaps, file paths, directory listings and a decision log. A useful context document covers architecture, domain model, patterns and conventions, file paths with purpose, exact commands and known gaps the CONTEXT.md discussion. That list suggests most sections should be dense, not narrative.

The eval was 60 tasks drawn from real work: add an endpoint following existing patterns, thread a field through the data layer, fix a failing test with the project command. Baseline on the untouched file was 51 of 60, or 85.0%. A second run also scored 51 of 60, so the noise band was plus or minus two tasks.

Applying the rule took 16 deletion tests and 9 rewrite tests.

CategoryInOutTokens inTokens outVerdict
Directory tree listings601,1400Drop: searchable
Stack descriptions507800Drop: in manifests
Decision log31620180Rewrite to live constraints
Style conventions74900430Rewrite as imperatives
Build and test commands44520460Keep: not discoverable
Known gaps55610590Keep: prevents bad assumptions
Domain model and keys431,030870Rewrite: entities and cascades only
Architecture and data flow652,2501,180Rewrite: invariants only
Total40227,8503,710

The surprise was the discoverable categories. Six directory trees and five stack summaries cost 1,920 tokens, and removing them moved the rate from 51 to 52 of 60. Within noise, so the honest reading is no effect. But it matches research finding that LLM-generated context files reduced task success by 2 to 3% while raising cost over 20%, and that the same content improved performance by 2.7% once all repo documentation was stripped first, meaning it is redundant rather than useless Addy Osmani's summary.

The file landed at 3,710 tokens, a 52.7% reduction. Pass rate moved from 51 of 60 to 54 of 60, or 90.0%. All three gained tasks came from buckets where a rewrite removed a conflicting instruction, not from a deletion. Deletions bought tokens; rewrites bought accuracy.

Two sections earned specific attention. The style section held seven rules across 900 tokens, several contradicting each other on error handling; compressed to four imperatives at 430 tokens, the endpoint bucket went from 8 of 12 to 10 of 12. The architecture section lost its narrative of why the system was built that way, which no task depended on, and kept the invariants new code must respect.

The stopping point came at the eleventh deletion. Removing a cascade delete rules section cost two tasks, and the rewrite attempt cost the same, so the content was irreducible. Those 140 tokens were worth more than they cost.

The rewrite pass carries the accuracy gain

Deletion is mechanical. Rewrite is where judgment enters.

Convert prose to imperatives. "We generally try to keep controllers thin and put logic in services, though there are exceptions in legacy billing" becomes "Controllers delegate to services. Exception: billing/legacy keeps logic in controllers." Fewer tokens, exception preserved. Context engineering practice points at clarity and precision in instructions, with structured organization and format optimization as supporting moves Packmind's context engineering practices.

Replace discoverable description with pointers. The distinction that matters separates what the agent finds by reading the repo from what it cannot: tooling gotchas, non-obvious conventions, landmines. Everything else is noise Addy Osmani. A context file briefs the assistant rather than introducing the project, which is exactly the non-discoverable layer the CONTEXT.md discussion.

Delete instructions the model no longer needs. Capability moves, and guidance required by an earlier generation is often dead weight. Build rules files gradually rather than front-loading, because what you once had to include may no longer be necessary Birgitta Böckeler on context engineering for coding agents. Your eval decides "no longer necessary," which is why the double baseline matters.

For the bookkeeping, parse the file into sections so token-per-section accounting is mechanical rather than a manual audit. A Markdown analysis library extracts headers, sections, code blocks and lists programmatically the markdown-analysis package, which gives you the table above for your own file.

from mrkdwn_analysis import MarkdownAnalyzer

print(MarkdownAnalyzer("CONTEXT.md").count_elements("header"))
print(MarkdownAnalyzer("CONTEXT.md").analyse())

Route dropped content instead of destroying it

Dropping a section from the always-loaded file does not mean deleting the knowledge. Tools, MCP servers and skills are context interfaces the agent loads when it decides they matter, and each one you configure consumes space, so choosing them deliberately is part of the same budget problem Birgitta Böckeler.

The routing is simple. Exact build and test commands stay loaded: short, non-discoverable, constantly used. Long runbooks become a skill. Deep domain detail becomes a referenced document read when the task touches the data layer. Decision logs move to a record consulted only when someone asks why.

Staleness is why this matters. An analysis of over 3,000 GitHub projects found 28.9% of the most popular projects currently contain at least one outdated code element reference, and 82.3% were outdated at least once in their history the outdated references study. A human fills the gap with skepticism; an agent reading stale text on every request has stale context poisoning its work Matt Pocock. Moving high-volume, slow-changing material out of the always-loaded path shrinks the surface that can rot.

To catch drift mechanically rather than only through your eval, a CI step that compares docs against merged diffs and opens a follow-up pull request is workable, with the caveat that prompt tuning is ongoing and the pattern is not production-grade without care Dosu's documentation drift workflow. Drift detection covers facts; the eval covers behavior.

Keep it small after you prune

A pruned file regrows. The loop is predictable: the agent does something you dislike, you add a rule, and after enough cycles you have a ball of mud Matt Pocock.

Three habits hold the line. Give the file a token ceiling, and require every new section to fit inside it or displace an existing one through the same eval process. Keep the eval set in version control beside the file, so a proposed rule arrives with evidence. Review composition as well as size: a small file that is all style rules and no landmines is badly allocated. The five-theme taxonomy of what developers actually write in these files, covering conventions, guidelines, project information, LLM directives and examples, is a useful checklist for spotting a missing category the empirical study of developer-provided context.

The case in one sentence: excessive or unoptimized context produces more complex and less accurate responses along with higher cost and latency the same study. Context is a finite resource with diminishing marginal returns, and recall accuracy degrades as token count grows, across models Anthropic's context engineering guide. The guide frames this as an attention budget every new token depletes. Pruning spends that budget on instructions that change output.

If the eval runs across several models, route the harness through one interface so verdicts are attributable to the context file rather than to plumbing. Quanta Inference puts text, image, video, audio and embedding models behind one OpenAI-compatible key, keeping the harness stable while the model underneath changes.

Once the file is pruned and the eval is green, the remaining decision is which dropped sections should become on-demand skills rather than deleted knowledge. That routing work is what Quanta Skills covers: install a skill into a coding agent, or hand the job to an expert that reads your context and returns finished deliverables.

FAQ

FAQ

How large should the eval set be before pruning?

Twenty to fifty representative tasks is a workable start, and the binding constraint is the noise band rather than the count. Run the eval twice on the untouched file; if three tasks swing with no edits, the set is too small or the scoring too loose. Grow it until a single removal produces a visible signal.

What if a section's verdict flips between runs?

You do not have a measurement yet. Grow the eval or widen the band and mark the section unresolved. Do not delete a section with inconsistent verdicts; leave it, flag it, and revisit once coverage is sufficient.

Should I delete a section or move it?

Ask whether the agent can rediscover the content by reading the repository. Directory listings and stack names are discoverable, so delete them. Exact commands, known gaps and non-obvious conventions are not, so route those to an on-demand document or skill rather than deleting.

Does a smaller file always raise the pass rate?

No. The worked example gained three tasks from rewrites, while deletions held or moved the rate within noise. A smaller file reliably buys lower cost and less attention dilution; accuracy comes from removing competing instructions. Expect tokens from dropping and accuracy from compressing.

How do I know when to stop?

Stop at the first removal whose accuracy cost exceeds the value of the freed tokens, and record that point with its eval numbers. In the example this was a cascade delete section that cost two tasks to remove and could not be compressed. Writing it down stops the next editor relitigating a settled trade.

Sources

Sources

  1. What is prompt evaluation? How to test prompts with metrics ...
  2. Evaluation-Driven Iteration for LLM Applications A ...
  3. How to track LLM token usage (2026): Prompt, completion ...
  4. A Complete Guide To AGENTS.md
  5. How a CONTEXT.md file can yield better AI coding results ... - GitHub
  6. Stop Using /init for AGENTS.md
  7. Context Engineering Best Practices for AI-Powered Dev Teams (2026)
  8. Context Engineering for Coding Agents - Martin Fowler
  9. markdown-analysis
  10. Detecting Outdated Code Element References in Software ...
  11. How to Catch Documentation Drift with Claude Code and ...
  12. An Empirical Study of Developer-Provided Context for AI ...
  13. Effective context engineering for AI agents - Anthropic
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles