What this was based on
The starting point was NVIDIA's paper You Don't Need Long Context (Belcak et al., November 2026). It reports that compacting an agent's context often, replacing the history with a short brief and continuing in a fresh context, keeps accuracy while cutting cost. Its cost figures are modelled, not billed: the paper builds them from GPU throughput measurements and an assumed per-token price that rises with context length. Anthropic's prices for Sonnet and Opus 5.5 do not rise with context length, and Claude Code relies heavily on prompt caching, so it was unclear whether the saving carries over to a Claude Code subscription.
- Belcak et al., You Don’t Need Long Context, arXiv:2611.05306 (NVIDIA): the claim under test. Its own limitations section calls the cost numbers an estimate
- CliffCompaction, Nguyen et al., arXiv:2609.26779: autocompaction on Terminal-Bench cut cost by “up to 50%” with performance kept, on open-weight models. The closest prior work. Its existence and the 50% figure were checked against the paper; the details of its cache accounting come from a secondary review and are unverified
- TokenPilot, Xu et al., arXiv:2606.17016: argues that pruning which changes the prompt layout breaks prefix caching (existence checked)
- Anthropic prompt-caching documentation: cache reads cost 0.05× the input price on Opus and Sonnet 5.5, one-hour cache writes 2×, and of the three models tested only Haiku 5.5 is priced higher above 100K tokens
- Claude Code documentation on prompt caching and costs: how /compact, /clear and the cache lifetime behave, and that /usage reports plan usage
Background
Does compacting the context reduce Claude Code subscription usage without hurting task quality? If it does, for which model, at what context size, and with which compaction strategy?
Method
- A headless Claude Code harness runs scripted multi-turn conversations on small deterministic repositories and grades the answers automatically
- Long tasks: T3 (9 turns, 17 checks) and T5 (11 turns, 18 checks) are coding tasks; T4 (8 turns, 15 checks) is a research-analysis task. They contain facts and rules that change mid-conversation, buried requirements, and exact numbers that must be recalled at the end
- Models: Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5. All conditions ran on Sonnet; Opus and Haiku ran G0 and G5
- 83 graded runs: a 20-run pilot (1 rep, direction only), Phase 3 (54 runs) and Phase 4 (9 runs), 3 reps per cell in the main phases. About $71.6 API-equivalent in total
- Success criteria were written before the runs: a strategy counts as better only if it saves at least 20% and loses no more than 5 score points, with no loss on critical-constraint checks
- Usage: plan usage was read with /usage before and after each batch. It has a resolution of one percentage point, so a single run is below resolution, and the whole study used a few percent of a weekly plan limit. Per-condition comparisons therefore use API-equivalent cost from Claude Code's cache-aware per-session cost record. This is a proxy, not plan usage; aggregate plan usage tracked it roughly linearly
- A harness bug was caught and fixed: the per-call cost field is cumulative and was double-counted when a session resumed
- G0
- Full history (baseline)
- G1
- Free-form brief at a threshold, then a fresh session
- G2
- The same, aggressive (10K threshold; pilot only)
- G3
- Single action per context (pilot only)
- G5
- Structured state plus a raw-history archive
- GN
- Claude Code's built-in /compact at the threshold
- G6 / G0F
- Full history with the author's real CLI setup: settings, hooks, plugins, MCP servers
Cost relative to full history (G0) Measured
| Model · task (G0 peak context) | G1 | G5 | GN | G0F (real setup) |
|---|---|---|---|---|
| Sonnet T4 (98K) | 1.40 (0.90–1.82) | 1.52 (1.11–1.88) | 1.25 (0.57–1.86) | 1.93 (1.62–2.31) |
| Sonnet T3 (127K) | 0.96 (0.88–1.06) | 1.03 (0.93–1.19) | 1.14 (1.07–1.24) | 1.66 (1.63–1.71) |
| Sonnet T5 (235K) | – | 0.99 (0.95–1.03) | 0.98 (0.94–1.03) | – |
| Opus T4 (109K) | – | 1.04 (0.93–1.17) | – | – |
| Opus T3 (206K) | – | 0.76 (0.65–1.01) | – | – |
| Haiku T4 (147K) | – | 0.73 (0.54–1.16) | – | – |
| Haiku T3 (247K) | – | 0.33 (0.30–0.36) | – | – |
Mean of 3 reps with a bootstrap 95% CI; below 1 is cheaper than full history. No compaction cell scored lower than G0. Sonnet T5 used a 150K threshold. In the short pilot (1 rep), G2 cost 1.31× and single-action compaction (G3) 4.72×.
Why the saving does not carry over Judgment
- Cache writes dominate. In Claude Code every new token is written to the cache once at 2× the input price, and old history is re-read at 0.05×. A fit of the run costs puts cache writes at about 60–65% of cost, reads about 20% and output 15–20% (Sonnet and Opus). Compaction only removes reads, so its saving is capped near the read share, about 20%, and it adds a brief-writing call, more output and a rewrite of the prefix. In T5, reads fell 32% (3.7M → 2.5M tokens) and cost fell only 1–2%
- Prices are flat in context length. NVIDIA's saving comes from a modelled price that rises with context. Sonnet and Opus 5.5 are priced flat. Haiku 5.5 is the exception: its price is 5× higher above 100K tokens, and staying under that line is why G5 cost 0.33× on the 247K task
- Fixed overhead is paid on every call. The author's real CLI setup raised the first call from 7.7K to 31.6K tokens and cost 1.66–1.93× the trimmed setup, with identical scores. The interactive session used during the study started at about 117K tokens per call, 62K of them MCP tool definitions
Information loss and failures Measured
- No compaction-induced loss was seen in G1, G5 or GN across one or two compactions, including superseded facts (a port changed from 54329 to 54417, a cap from 37.5% to 35%), amended exclusion rules, buried requirements and exact numbers. Caveat: most runs scored at the ceiling, there were at most two compactions, and the tasks are synthetic
- Single-action compaction (G3) lost the reason a design had been rejected in 1 of 2 runs and cost 4–7× full history
- Haiku 5.5 failed the same feature checks with and without compaction: a capability limit, not a context effect
- A grader bug was found and fixed: Korean answers such as “9개” broke word-boundary matching of numbers
A pre-registered prediction, falsified Measured
Phase 3 suggested that compaction pays off only when full history would exceed about 150K tokens. Before Phase 4 this was written down as a prediction: on a longer task (T5, peak 235K), G5 and GN with a 150K threshold would cost at most 0.8× G0 with no quality loss, and the prediction would count as falsified if both cost at least 0.95×. Result: G5 0.99× and GN 0.98×, with all 9 runs at full score. The prediction is falsified for Sonnet 5.5.
Recommendation: adopt with conditions Judgment
- Trim fixed overhead first: disable unused plugins, MCP servers and skills, and keep global instructions short. Measured: 40–48% less cost for identical results
- Sonnet and Opus: do not compact mid-task to save usage. Start a fresh session at natural task boundaries when the old context is no longer needed (this follows from the mechanism and was not tested separately)
- Haiku: keep sessions under 100K tokens, and compact with a structured brief at about 80K when work continues
- When compacting, use a structured brief (rules verbatim, exact values, decisions and rejected options, file paths) and keep the raw history retrievable. G5 and the built-in /compact cost the same; never compact after every action
- Avoid long (over 150K), subagent-heavy sessions for routine work; the author's own usage breakdown showed that most usage went there
Limitations
- Synthetic tasks only; the findings were not validated on a real workload
- 3 reps per cell and wide confidence intervals on T4. Opus T3's 0.76× has an interval that reaches 1.01, so it is not significant
- Plan usage has a one-point resolution, so per-condition results rest on API-equivalent cost. How subscription plans weigh cached tokens is not disclosed; the roughly linear tracking is consistent with, but does not prove, cost-proportional accounting
- Thresholds were fixed, not adaptive, and there were at most two compactions per run, so compounding loss over many compactions is untested
- One Claude Code version and three models
- Novelty is limited: the cache-aware bound and the Haiku price-tier effect are useful practical findings, but CliffCompaction and TokenPilot cover similar ground. The project's own assessment is that this supports a short technical note, not a research paper
Verification and AI use
The table figures were copied from the project's final report and its auto-generated Phase 3 analysis, which agree; the Phase 4 ratios were re-summed from the batch result files. The analysis was not otherwise re-run. AI-assisted implementation: an AI agent (Claude Code) built the harness, ran the experiments and wrote the analysis and report; the author set the question, approved the usage budget and chose the Phase 3 design. The models under test belong to the same family as the agent that ran the study. The literature review was web-based, and only the sources marked as checked above were confirmed against the original. Code and raw data are kept private. No independent review.