A coding agent reads a 20,000-token failing build log, patches three files, and gets the tests passing. You ask for the next change. Deleting that obsolete log cuts 25% of the prompt and looks like free savings.
It usually backfires. On late-2026 frontier APIs, deleting an old block from the middle of a warm session multiplies the next turn's input cost by 5.7x to 8.0x - and takes 37 to 97 more warm turns to earn back. Prompt caches across OpenAI, Anthropic and Google match strictly from token zero: cut the middle, and every surviving token after the cut loses its cache hit.
Why editing the middle multiplies the bill #
Coding agents are overwhelmingly read-heavy. Manus reported an average ~100:1 input-to-output token ratio and called KV-cache hit rate the single most important metric for a production agent. An October 2026 study of coding-agent runs measured 98% to 99% prefix-cache reuse when histories stay append-only.
Today's pricing makes breaking that prefix far harsher than older 10x cache tiers. Frontier cache reads now cost 0.05x to 0.025x base input, while cache writes add a 1.25x surcharge on OpenAI's 30-minute cache and Anthropic's 5-minute cache. Invalidating a surviving block does not move it from 0.1x to 1x - it swings every token 20x to 50x higher.
The break-even math across frontier models #
Delete D tokens ahead of S surviving cached tokens, with cache-write rate w and cache-read rate r. The edit adds S * (w - r) - D * r on that turn, while each later warm turn saves only D * r. Total prompt size and dollar price cancel out completely:
break-even turns = (S / D) * (w / r - 1) - 1
Only two ratios decide the outcome: how much surviving context follows the cut (`S / D`), and the provider's rewrite-to-read spread (` w / r`). For our 80,000-token session (` S / D = 2`):
| Model | Read / M | Rewrite / M | Ratio | Next turn (keep → cut) | Break-even |
|---|---|---|---|---|---|
| GPT-6.2 Sol | $0.10 | $2.50 | 25x | 1.76¢ → 11.16¢ (6.3x) | 47 turns |
| GPT-6.2 Astra | $0.40 | $10.00 | 25x | 7.04¢ → 44.64¢ (6.3x) | 47 turns |
| Claude Sonnet 5.5 | $0.10 | $2.50 | 25x | 1.76¢ → 11.16¢ (6.3x) | 47 turns |
| Claude Opus 5.5 | $0.20 | $5.00 | 25x | 3.52¢ → 22.32¢ (6.3x) | 47 turns |
| Claude Fable 5.2 | $0.20 | $10.00 | 50x | 5.52¢ → 44.32¢ (8.0x) | 97 turns |
| Gemini 4 Neon | $0.15 | $3.00 | 20x | 2.34¢ → 13.44¢ (5.7x) | 37 turns |
Standard short-context rates checked November 29, 2026 (OpenAI, Anthropic, Google). Uses default write TTLs: 30m (1.25x) on OpenAI, 5m (1.25x) on Anthropic, implicit (1x) on Google. Extended TTLs (12h OpenAI at 2.5x, 1h Anthropic at 2x) raise break-even to 97 and 77-157 turns.
Every deeper cache discount makes mid-prompt editing more expensive, not less.
What the 2026 benchmarks show #
- Pruning flips from savings to a loss under caching. In aNovember 2026 study of 20,000+ coding-agent runs on SWE-bench Verified, SWE-bench and Loc-Bench, dropping old tool outputs saved19% to 36% without a cache discount - yetincreased cost by 38% to 116% with a tenth-price cache, partly because pruned agents took extra steps to recover lost context.
- Clean prefixes dominate cost and latency. Across 500+ multi-turn runs on OpenAI, Anthropic and Google, aJanuary 2026 agent caching evaluation found intact prefixes cut API cost by41% to 80% and time to first token by13% to 31% .
- Batching beats per-turn trimming. TheOctober 2026 prefix-preserving compaction study found periodic batched masking preserved95% to 98% prefix reuse, cutting serving cost up to 18% and completion time up to 21%.
When trimming actually pays #
- Leave stale logs alone on short tails. If only a few turns remain, append to the warm prefix and keep the cache hit.
- Compact at rare boundaries, not every step. Pay the rewrite penalty once so dozens of warm turns amortize it, asAnthropic's context engineering guide recommends.
- Keep volatile fields at the tail. Editing tools, system text, or timestamps near token zero wipes everything after them (Anthropic invalidation rules ;OpenAI prefix rules ).
- Override cache math only for hard limits. Trim immediately when you hit the context ceiling, approach a long-context pricing cliff (likeOpenAI's 272K-token tier , where rates double), or see stale noise hurting accuracy.
Verify it in your own responses: track cached_tokens and cache_write_tokens on OpenAI, cache_read_input_tokens and cache_creation_input_tokens on Anthropic, or total_cached_tokens on Google. In a cached agent loop, shorter only means cheaper when the prefix survives.
Sources and pricing snapshot #
Primary sources and pricing were checked on November 29, 2026. The worked example uses published standard short-context rates, not proprietary TheGitAI telemetry.
- Provider docs & pricing: OpenAI (prompt caching ,GPT-6.2 Sol ,GPT-6.2 Astra ) · Anthropic (prompt caching ,API pricing ) · Google (Gemini caching ,API pricing )
- 2026 empirical studies:Context Has a Price (arXiv:2611.22238) ·Break Later or Never (Oct 2026) ·Don't Break the Cache (arXiv:2601.06007)
- Agent engineering notes:Manus: Context Engineering for AI Agents ·Anthropic: Effective context engineering for AI agents
Try TheGitAI
Every frontier model with a frontier harness. #
Use OpenAI, Anthropic, Google, xAI and more in one desktop app and CLI, zero config. Code, drive your browser and computer, and keep your files and memory local.
Keep reading #
FrontierCode vs. Terminal-Bench vs. SWE-Bench: Why No Single Model Wins
Compare FrontierCode, Terminal-Bench, and SWE-Bench for coding agents. See why scores differ and how to choose an LLM.
No, Stanford’s NCM Won’t Kill LLMs Yet! Here’s the Engineering Catch
Stanford's Next-Concept Modeling promises faster generation. See what the NCM results show, what they do not, and the coding-agent tests still needed.