{"slug": "shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents", "title": "Shorter Prompts Cost More: The Prompt Caching Trap in Coding Agents", "summary": "Deleting an obsolete block from the middle of a warm coding-agent 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, because prompt caches from OpenAI, Anthropic and Google match strictly from token zero, according to an analysis of late-2026 frontier API pricing. A November 2026 study of 20,000+ coding-agent runs on SWE-bench Verified, SWE-bench and Loc-Bench found that dropping old tool outputs saved 19% to 36% without a cache discount but increased cost by 38% to 116% with one, while an October 2026 study measured 98% to 99% prefix-cache reuse when histories stay append-only. The break-even formula (S / D) * (w / r - 1) - 1 yields 47 turns for GPT-6.2 Sol, GPT-6.2 Astra, Claude Sonnet 5.5 and Claude Opus 5.5, 97 turns for Claude Fable 5.2 and 37 turns for Gemini 4 Neon in an 80,000-token session.", "body_md": "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.\n\n**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](https://developers.openai.com/api/docs/guides/prompt-caching), [Anthropic](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) and [Google](https://aistudio.google.com/docs/caching) match strictly from token zero: cut the middle, and every surviving token after the cut loses its cache hit.\n\n## [Why editing the middle multiplies the bill](#why-editing-the-middle-multiplies-the-bill)\n\nCoding agents are overwhelmingly read-heavy. [Manus reported an average ~100:1 input-to-output token ratio](https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus) and called KV-cache hit rate the single most important metric for a production agent. An [October 2026 study of coding-agent runs](https://figshare.com/articles/preprint/Break_Later_or_Never_Prefix-Preserving_Context_Compaction_for_Coding_Agents/34791231) measured **98% to 99% prefix-cache reuse** when histories stay append-only.\n\nToday'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](https://developers.openai.com/api/docs/guides/prompt-caching) and [Anthropic's 5-minute cache](https://platform.claude.com/docs/en/build-with-claude/prompt-caching). Invalidating a surviving block does not move it from 0.1x to 1x - it swings every token **20x to 50x** higher.\n\n## [The break-even math across frontier models](#the-break-even-math-across-frontier-models)\n\nDelete `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:\n\nbreak-even turns = (S / D) * (w / r - 1) - 1\n\nOnly 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`):\n\n| Model | Read / M | Rewrite / M | Ratio | Next turn (keep → cut) | Break-even | \n|---|---|---|---|---|---|\n| **GPT-6.2 Sol** | $0.10 | $2.50 | 25x | 1.76¢ → 11.16¢ (6.3x) | 47 turns | \n| **GPT-6.2 Astra** | $0.40 | $10.00 | 25x | 7.04¢ → 44.64¢ (6.3x) | 47 turns | \n| **Claude Sonnet 5.5** | $0.10 | $2.50 | 25x | 1.76¢ → 11.16¢ (6.3x) | 47 turns | \n| **Claude Opus 5.5** | $0.20 | $5.00 | 25x | 3.52¢ → 22.32¢ (6.3x) | 47 turns | \n| **Claude Fable 5.2** | $0.20 | $10.00 | 50x | 5.52¢ → 44.32¢ (8.0x) | 97 turns | \n| **Gemini 4 Neon** | $0.15 | $3.00 | 20x | 2.34¢ → 13.44¢ (5.7x) | 37 turns | \n\n*Standard short-context rates checked November 29, 2026 ([OpenAI](https://developers.openai.com/api/docs/models/gpt-6.2-sol), [Anthropic](https://platform.claude.com/docs/en/about-claude/pricing), [Google](https://aistudio.google.com/docs/pricing)). 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.*\n\n**Every deeper cache discount makes mid-prompt editing more expensive, not less.**\n\n## [What the 2026 benchmarks show](#what-the-2026-benchmarks-show)\n\n- **Pruning flips from savings to a loss under caching.** In a[November 2026 study of 20,000+ coding-agent runs](https://arxiv.org/abs/2611.22238) on SWE-bench Verified, SWE-bench and Loc-Bench, dropping old tool outputs saved**19% to 36%** without a cache discount - yet**increased cost by 38% to 116%** with a tenth-price cache, partly because pruned agents took extra steps to recover lost context.\n- **Clean prefixes dominate cost and latency.** Across 500+ multi-turn runs on OpenAI, Anthropic and Google, a[January 2026 agent caching evaluation](https://arxiv.org/abs/2601.06007) found intact prefixes cut API cost by**41% to 80%** and time to first token by**13% to 31%** .\n- **Batching beats per-turn trimming.** The[October 2026 prefix-preserving compaction study](https://figshare.com/articles/preprint/Break_Later_or_Never_Prefix-Preserving_Context_Compaction_for_Coding_Agents/34791231) found periodic batched masking preserved**95% to 98%** prefix reuse, cutting serving cost up to 18% and completion time up to 21%.\n\n## [When trimming actually pays](#when-trimming-actually-pays)\n\n1. **Leave stale logs alone on short tails.** If only a few turns remain, append to the warm prefix and keep the cache hit.\n2. **Compact at rare boundaries, not every step.** Pay the rewrite penalty once so dozens of warm turns amortize it, as[Anthropic's context engineering guide](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents) recommends.\n3. **Keep volatile fields at the tail.** Editing tools, system text, or timestamps near token zero wipes everything after them ([Anthropic invalidation rules](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) ;[OpenAI prefix rules](https://developers.openai.com/api/docs/guides/prompt-caching) ).\n4. **Override cache math only for hard limits.** Trim immediately when you hit the context ceiling, approach a long-context pricing cliff (like[OpenAI's 272K-token tier](https://developers.openai.com/api/docs/models/gpt-6.2-sol) , where rates double), or see stale noise hurting accuracy.\n\nVerify it in your own responses: track `cached_tokens` and `cache_write_tokens` on [OpenAI](https://developers.openai.com/api/docs/guides/prompt-caching), `cache_read_input_tokens` and `cache_creation_input_tokens` on [Anthropic](https://platform.claude.com/docs/en/build-with-claude/prompt-caching), or `total_cached_tokens` on [Google](https://aistudio.google.com/docs/caching). In a cached agent loop, shorter only means cheaper when the prefix survives.\n\n## [Sources and pricing snapshot](#sources-and-pricing-snapshot)\n\nPrimary sources and pricing were checked on **November 29, 2026**. The worked example uses published standard short-context rates, not proprietary TheGitAI telemetry.\n\n- **Provider docs & pricing:** OpenAI ([prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) ,[GPT-6.2 Sol](https://developers.openai.com/api/docs/models/gpt-6.2-sol) ,[GPT-6.2 Astra](https://developers.openai.com/api/docs/models/gpt-6.2-astra) ) · Anthropic ([prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) ,[API pricing](https://platform.claude.com/docs/en/about-claude/pricing) ) · Google ([Gemini caching](https://aistudio.google.com/docs/caching) ,[API pricing](https://aistudio.google.com/docs/pricing) )\n- **2026 empirical studies:**[Context Has a Price (arXiv:2611.22238)](https://arxiv.org/abs/2611.22238) ·[Break Later or Never (Oct 2026)](https://figshare.com/articles/preprint/Break_Later_or_Never_Prefix-Preserving_Context_Compaction_for_Coding_Agents/34791231) ·[Don't Break the Cache (arXiv:2601.06007)](https://arxiv.org/abs/2601.06007)\n- **Agent engineering notes:**[Manus: Context Engineering for AI Agents](https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus) ·[Anthropic: Effective context engineering for AI agents](https://www.anthropic.com/research/effective-context-engineering-for-ai-agents)\n\nTry TheGitAI\n\n## Every frontier model with a frontier harness.\n\nUse 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.\n\n## Keep reading\n\nFrontierCode vs. Terminal-Bench vs. SWE-Bench: Why No Single Model Wins\n\nCompare FrontierCode, Terminal-Bench, and SWE-Bench for coding agents. See why scores differ and how to choose an LLM.\n\nNo, Stanford’s NCM Won’t Kill LLMs Yet! Here’s the Engineering Catch\n\nStanford's Next-Concept Modeling promises faster generation. See what the NCM results show, what they do not, and the coding-agent tests still needed.", "url": "https://wpnews.pro/news/shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents", "canonical_source": "https://thegit.ai/blog/when-a-shorter-prompt-costs-more", "published_at": "2026-11-29 13:11:00+00:00", "updated_at": "2026-11-29 13:15:26.678054+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "large-language-models"], "entities": ["OpenAI", "Anthropic", "Google", "GPT-6.2 Sol", "Claude Sonnet 5.5", "Claude Fable 5.2", "Gemini 4 Neon", "Manus"], "also_reported_by": [], "takeaway": "Keep coding-agent histories append-only: deleting D tokens ahead of S surviving cached tokens adds S*(w-r) - D*r on that turn and saves only D*r per later turn, so with S/D=2 and a 25x rewrite-to-read spread the edit needs 47 warm turns to break even.", "recommendation": {"advice": "Append to coding-agent context instead of deleting mid-prompt blocks; with S/D=2 and a 25x cache spread, a mid-prompt cut costs 6.3x on the next turn and needs 47 warm turns to repay.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents", "markdown": "https://wpnews.pro/news/shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents.md", "text": "https://wpnews.pro/news/shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents.txt", "jsonld": "https://wpnews.pro/news/shorter-prompts-cost-more-the-prompt-caching-trap-in-coding-agents.jsonld"}}