AI Coding Agents
Cache bust break-even for context compression
The cache bust break-even for context compression is the minimum share of a warm prefix you must remove to recover the cost of writing it again. Divide the write multiplier minus the read multiplier by the write multiplier plus the read multiplier times the number of later reuse turns, then compress only if your measured reduction exceeds that threshold.
The cache bust break-even for context compression is the minimum share of a warm prefix you must remove to recover the cost of writing it again. Divide the write multiplier minus the read multiplier by the write multiplier plus the read multiplier times the number of later reuse turns, then compress only if your measured reduction exceeds that threshold and the retained context still serves the task.
Define the prefix and the turns you are pricing
A rewrite that changes a cached prefix can turn a cheap read into a new write. The rewrite can still pay if it removes enough tokens for later reads to offset that first-turn premium. This calculation isolates the prefix you are choosing whether to rewrite. Start with a prefix that is warm now, then choose the horizon over which both versions would otherwise stay readable. For the application behavior that can trigger a rewrite, see context compaction and prompt cache cost.
| Symbol | Meaning in the estimate |
|---|---|
P | Input tokens in the warm prefix that the rewrite would displace. |
r | Fraction of those tokens removed, so the rewritten prefix contains (1 - r) * P tokens. |
α | Cache-read price divided by ordinary input price. |
β | Cache-write price divided by ordinary input price. |
K | Remaining requests before the next forced rewrite, including the request on which you would rewrite now. |
q | Ordinary input price per token, or the price per million divided by one million. |
Use token counts from the model and endpoint you actually call. A summary that is half the length in characters may retain a different fraction of tokens. If a separately written earlier section stays warm in both options, its equal read costs cancel. Use the affected suffix of the cached prefix as P only when you have verified that the earlier section still reads. Otherwise estimate the whole portion whose write you are replacing. The calculation assumes the shortened prefix remains eligible for caching and uses the intended breakpoint.
Keep the horizon tied to reuse. If a route change, idle gap that expires the cache, or another rewrite ends the sequence early, counting later turns as reads overstates the savings. The model treats the ordinary input and any new cache writes after the affected prefix as equal on both paths. In particular, compressing a newly appended tool result before its first send does not rewrite any already-cached tokens. Evaluate that delta separately from the decision to rewrite a warm prefix.
Derive the minimum compression ratio
- Price keeping the warm prefix. All
Krequests read the originalPtokens at multiplierα. The cost isq P K * α. - Price rewriting now. The first request writes
(1 - r) Ptokens at multiplierβ. Each of the remainingK - 1requests reads that shortened prefix at multiplierα. The cost isq P (1 - r) (β + (K - 1) * α). - Set the two costs equal. Cancel the common positive factor
q P. This givesK α = (1 - r) (β + (K - 1) α). - Solve for the removed fraction. Divide both sides by
β + (K - 1) αand rearrange. Thenr = 1 - (K α) / (β + (K - 1) * α). Combining the terms in the numerator leavesβ - α. - Use the threshold. The result is
r_min = (β - α) / (β + (K - 1) * α). Above it, rewriting saves prefix input cost. At equality, the two costs match. Below it, keeping the warm prefix costs less.
The one-turn result is a useful check. Set K = 1 and the threshold is 1 - α / β. Writing the shortened prefix once must cost less than reading the original prefix once for the rewrite to win. As the number of verified future reads grows, the denominator grows and the threshold falls. A very cheap read rate can make a warm rewrite difficult to justify because the unchanged prefix was already inexpensive to reuse.
You can also solve for the horizon if the candidate compression ratio is fixed. For 0 < r < 1 and positive α, a strict saving requires K > (β - α) (1 - r) / (r α). Use the first integer strictly above that value. With hypothetical 65% compression and multipliers of 0.05 and 1.25, you need at least 13 requests including the rewrite request. Count only requests that would share the relevant prefix on both paths.
Compare break-even points for Claude and OpenAI
These estimates use the committed ByteCosts rates and documented lifetime multipliers as of November 30, 2026. The percentages indicate the share of tokens removed at equality. Use the full-precision formula for a decision close to a displayed threshold. AI provider pricing index
| Claude model and write lifetime | Read α | Write β | K = 2 | K = 5 | K = 15 | K = 50 |
|---|---|---|---|---|---|---|
| Sonnet 5.5 or Opus 5.5, five minutes | 0.05 | 1.25 | 92.31% | 82.76% | 61.54% | 32.43% |
| Sonnet 5.5 or Opus 5.5, one hour | 0.05 | 2.00 | 95.12% | 88.64% | 72.22% | 43.82% |
| Haiku 5.5, five minutes | 0.10 | 1.25 | 85.19% | 69.70% | 43.40% | 18.70% |
| Haiku 5.5, one hour | 0.10 | 2.00 | 90.48% | 79.17% | 55.88% | 27.54% |
| OpenAI or reference case | Read α | Write β | K = 2 | K = 5 | K = 15 | K = 50 |
|---|---|---|---|---|---|---|
| GPT-6.2 Sol, default 30 minutes | 0.05 | 1.25 | 92.31% | 82.76% | 61.54% | 32.43% |
| Reference | 0.10 | 1.25 | 85.19% | 69.70% | 43.40% | 18.70% |
The same multipliers give the same threshold regardless of base input price. Convert the modeled savings to dollars before deciding whether any compression work is worth doing. Also keep a write lifetime and a reuse horizon distinct. A more expensive write can buy a longer opportunity for reuse. The tables hold the number of reads fixed in each column to show what that write premium does to the minimum required compression.
Price a warm rewrite with assumed token counts
Assume a 60,000-token warm Claude Sonnet 5.5 prefix, a candidate summary that removes 65% of it, and 15 requests before the next forced rewrite. The summary leaves 21,000 tokens. Use the committed $2 per million ordinary input tokens, with a read multiplier of 0.05 and a five-minute write multiplier of 1.25. Assume each follow-up hits within the lifetime on either path.
| Option | Ordinary-input token equivalents | Estimated prefix cost |
|---|---|---|
| Keep the warm prefix | 60,000 15 0.05 = 45,000 | $0.09000 |
| Write a shorter prefix, then read it 14 times | 21,000 (1.25 + 14 0.05) = 40,950 | $0.08190 |
| Write a shorter prefix for one hour, then read it 14 times | 21,000 (2 + 14 0.05) = 56,700 | $0.11340 |
Each estimate multiplies the middle column by $2 and divides by one million. The five-minute rewrite saves an estimated $0.00810 before any compression cost. At the same horizon, the one-hour rewrite costs an estimated $0.02340 more than retaining the warm prefix. The one-hour write rate for Sonnet 5.5 is a derived $4 per million tokens, using its $2 base rate and Anthropic’s 2× multiplier.
A separate model call to generate a summary can erase a thin margin. Include its own input, output, and any storage or other separately metered charges when comparing alternatives. For Claude Code, the docs describe a distinct summarization request that can reuse warm history, then a following turn that rebuilds the shorter conversation layer. Record both when timing a compaction. Consider whether the change also affects task quality or causes the agent to fetch the same context again. Context compression versus prompt caching
Use the same estimate to set a budget for the compression step. In the five-minute example, a summary that costs more than the estimated $0.00810 margin makes the whole operation more expensive on input and compression alone. That is a ceiling for this assumed horizon. If the application compresses to fit a context limit, the operation can still serve that purpose. Record the added cost as the price of fitting the task.
For a rollout, compare a group of sessions that keeps its warm prefix with a group that rewrites at the candidate point. Summing input costs from the rewrite through the next forced rebuild captures both the immediate write and the later savings. Look at shorter sessions separately. A long session can recover a write that ends up as overhead for users who stop after the next few turns.
Keep separate counts for any unchanged prefix and the part the summary replaces. After Claude Code compacts a conversation, the next turn can still read a current system prompt from cache. It rebuilds both the conversation and project context, even if the project files are unchanged. The total read count can therefore stay high while the turn incurs a fresh write. Compare usage from the summarization call and the following turn with usage from equivalent turns on the unchanged path. Use the observed write size to check your estimate of the affected prefix.
Rewrite cold prefixes when the write is already due
If the old prefix is already cold and either option writes on the next request, both paths have the same rate factor, β + (K - 1) α. Keeping the original costs q P (β + (K - 1) α). Rewriting costs that amount times 1 - r. Any positive reduction saves prefix input cost under those assumptions. This is the cost rationale for cold-only rewriting. Check that the shorter prefix still qualifies and include the cost of generating the summary before using the result as a session-wide estimate.
Headroom’s merged July 25, 2026 documentation PR describes cold-prefix recompaction as opt-in. Cold detection is a separate engineering problem. As of November 30, 2026, an open Headroom PR from October 27 reports that an idle-compaction request’s shorter lifetime can make its tracker classify still-warm context as cold. The reported case shows why you should verify the provider’s read and write usage before treating an idle timer as evidence of expiration. Headroom cold recompaction
Choose when to compress
- Measure how much warm context the rewrite would replace. If an earlier boundary remains readable, evaluate only the part that would be written again.
- Estimate
Kfrom observed turns between rewrites and cache expirations. Run the estimate with a short and a longer horizon if reuse is uncertain. - Apply the rates for the chosen model and write lifetime. When the cache is warm and the candidate falls below the threshold, retain the prefix and look for savings in new deltas.
- When the cache is cold and both versions would write, estimate the reduction in prefix cost, then include any separate compression expense and check that the output remains useful.
- After rollout, measure cache reads, writes, and effective input cost over a full interval. Confirm that later reads repay the initial write on the turns you actually observe.
Sources
- Prompt caching (Anthropic, accessed 2026-11-30)
- Prompt caching (OpenAI, accessed 2026-11-30)
- Prompt caching in Claude Code (Anthropic, accessed 2026-11-30)
- docs(configuration): document cold-prefix hook flags + bound the TTL observation log (Headroom, accessed 2026-11-30)
- fix(cache): judge a cold prefix by the conversation’s longest cache TTL (Headroom, accessed 2026-11-30)
Interactive report
- Do Token Savers Actually Save?: RTK reported saving 74.7% of the tokens on the commands it touched. In tokbench’s pilot, the RTK run still used 27% more provider-billed input than the unmodified run. The comparison shows why a tool’s savings counter and the provider’s meter can move in opposite directions.
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Cache bust break-even for context compression. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/cache-bust-break-even-compression/