Cache hits and compaction: what a long Claude session really costs

Last week, we published A Week With Haiku, Sonnet and Opus: Which Model for Which Job. One finding was that about nine dollars in ten went to context, not to the words the model wrote back. A reader asked a sharp follow-up question on LinkedIn. If most of the money is context, isn’t caching a bigger lever than picking the model? And were most of those context tokens already cache hits?

We were already debating our own compaction strategy. We would compact constantly, except that compaction itself costs money. So, we went back to the logs to settle it with numbers.

Who this applies to: anyone who uses Claude Chat directly, uses Claude Code directly, puts their own harness around one of them, or runs a full agent on the Claude API. Our numbers come from Claude Code only. Near the end, we say which findings carry over to the other three and which don’t.

What a cache hit saves

When a request starts with the same text as a recent one, Claude can read that text from a cache instead of processing it again. Anthropic bills three prices for input:

  1. Cache hit: 0.05 times the normal input price on Claude Opus 5.5 and Claude Sonnet 5.5, and 0.1 times on most other models, including Claude Haiku 5.5. On Opus 5.5, that is $0.20 per million tokens instead of $4.
  2. Cache write with a 5-minute lifetime: 1.25 times the normal input price.
  3. Cache write with a 1-hour lifetime: 2 times the normal input price, or $8 per million tokens on Opus 5.5.

Each hit resets the lifetime clock at no extra cost. This is stated in Anthropic’s pricing and prompt caching documentation, which we checked on December 4, 2026.

The ratio that matters is between the write and the hit. On Opus 5.5 and Sonnet 5.5, a 1-hour write costs 40 times as much as a hit.

Bar chart of Claude Opus 5.5 prices per million tokens: cache hit $0.20, normal input $4, 5-minute write $5, 1-hour write $8, output $20. A 1-hour cache write costs 40 times a cache hit.

What we measured

We read every Claude Code session on one PC from October 21 to December 4, 2026: 429 sessions and about 43,800 replies. Each reply records how many input tokens were cache hits, cache writes, or plain uncached input. We priced them all at Anthropic’s list API prices.

The reader was right about the tokens. Cache hits were 97% of context tokens on Opus 5.5 and Sonnet 5.5, and 95% on Haiku 5.5. Cache writes were the rest, and uncached input was close to zero.

The dollars tell a different story. At list prices, the whole period came to $4,558:

  1. Cache writes: 47% of the dollars, from only about 3% of the tokens.
  2. Cache hits: 42%.
  3. Output: 11%.

Two stacked bars. Context tokens: 97% cache hits, 3% writes. Dollars ($4,558): 42% cache hits, 47% cache writes, 11% output.

Opus 5.5 and Sonnet 5.5 split almost exactly the same way, and Haiku 5.5 leaned a bit more toward hits. Claude Code wrote 95% of its cache with the 1-hour lifetime, so every write cost 40 times a hit. Caching was already doing its job. The money was in the misses.

Why caches miss

Some writes can’t be avoided. Every reply adds new text to the end of the conversation, and that new text gets written to the cache once. That came to $450, about 10% of the total. Starting a session or a subagent cost another $112.

The big one was idle time. When a session sat for more than an hour, the cache expired, and the next reply wrote the whole conversation again at the 1-hour write price. That happened 825 times. The median conversation was 207,000 tokens long, and the median gap was almost seven hours: overnight, a meeting, or a background session waiting for its next message. Those rebuilds cost $1,486, a third of everything we spent.

Horizontal bars of where $4,558 went: cache hits $1,920, rebuilds after a gap over 1 hour $1,486, output $492, new text written to cache $450, session and subagent starts $112, model switches $72, rebuilds after compaction $12.

Gaps shorter than an hour almost never missed. We counted about 2,400 gaps between five minutes and an hour, and only 18 led to a rebuild. Past the hour, nearly every gap did. That matches the 1-hour lifetime.

Share of replies that rebuilt the cache by gap length: under 1% for gaps up to 30 minutes, 3% at 30 to 60 minutes, then 93% at 1 to 2 hours and 98% beyond. An hourglass sits beside the chart.

The size of the conversation sets the price of each miss. On Opus 5.5, our median rebuild of 207,000 tokens cost $1.66. A 500,000-token session costs $4 to pick up again the next morning.

Line chart of the cost of the first reply after the cache expires, by conversation size: Opus 5.5 reaches $4 at 500,000 tokens and $8 at 1 million; Sonnet 5.5 is half. Our median, 207,000 tokens, cost $1.66.

Model switches mattered less than we expected. A cache belongs to one model, so a switch starts over. In our logs that happened 61 times and cost $72, under 2% of the total.

What compaction costs

Compaction replaces a long conversation with a short summary and carries on. Our first count found 46 compaction markers. They turned out to be 28 compactions, because a compaction can leave more than one marker. We checked all 28: each had the compaction boundary, the summary, and a large cache write on the next reply. All 28 were automatic, at about 370,000 or about 970,000 tokens.

Each compaction has two costs:

  1. The summary call: the model reads the long conversation and writes a summary of about 4,500 tokens. Claude Code doesn’t log this call, so we estimated it from the conversation size and the summary length: a median of $0.15. That figure is our inference.
  2. The rebuild: the next reply writes the new, shorter conversation to the cache. We measured this: a median of $0.44.

So, a compaction cost about $0.59, and all 28 together cost about $17.

What it buys is a smaller conversation to carry. After compaction, the context dropped from about 370,000 tokens to about 100,000 in most sessions. Every later reply reads fewer cached tokens. At the median, compaction paid for itself after 11 replies, with a range of 4 to 28. Every one of the 28 was followed by at least 15 replies, and the median was 127, so all of them paid back.

Running net saving after one compaction: it starts at minus $0.59 (summary call $0.15 plus cache rebuild $0.44), breaks even at reply 11 and keeps rising.

The break-even depends on how big the conversation is when you compact. Compacting a 970,000-token conversation pays back in about 5 replies. At 370,000 tokens, it takes about 13. At 150,000 tokens, it takes about 70, because there is little to drop and the rebuild costs the same. The ratio between hit and write prices is the same on Opus 5.5 and Sonnet 5.5, so the curve is the same for both.

Curve of replies needed to pay back a compaction by conversation size: about 70 at 150,000 tokens, about 13 at 370,000 and about 5 at 970,000.

The strategy, with numbers

Compacting constantly doesn’t pay. Below about 200,000 tokens, it takes dozens of replies to earn the cost back, and every compaction loses some detail.

Compacting before you leave is a different story. Take a 400,000-token session on Opus 5.5 that sits overnight. Walk away, and the first reply in the morning rewrites all of it: $3.20. Compact first, and you pay for the summary and a rewrite of about 100,000 tokens: $0.97.

Two ways to leave a 400,000-token Opus 5.5 session for the night: walk away and the next reply rewrites 400,000 tokens for $3.20, or compact first and pay $0.97.

Had we done this before each of the 540 long idle gaps with more than 150,000 tokens in context, we estimate we would have saved about $914, or 20% of the total. This is one PC, one workload, and one person’s working pattern over six weeks.

For the groups at the top, the findings carry over like this:

  1. Claude Code: these are your numbers, if your sessions look like ours.
  2. A harness or a full agent on the Claude API: the prices and the break-even math apply as they are. The default cache lifetime there is 5 minutes, not an hour, so any gap over 5 minutes is a rebuild unless you choose the 1-hour lifetime. The idle-gap rule matters even more.
  3. Claude Chat: we have no logs from it, and its cache behavior isn’t visible to us, so treat the rule as reasoning, not measurement.

The bottom line

The reader’s question had a good answer. Caching was already working: 97% of the tokens were hits. The bill came from the moments the cache was lost, and most of those were us walking away from big sessions.

The short version

1. Leaving for more than an hour? Compact or end any session over about 150,000 tokens. For us, that was worth about 20% of the bill.

2. Still working? Compact once the conversation passes about 350,000 tokens and you expect at least 15 more replies. It pays back in about 13. Claude Code already does this on its own near that point.

3. Switching models? Don’t worry about it. It cost us under 2%.

4. Building on the API? Your cache lasts 5 minutes by default, so the same rule applies after a coffee break, not just overnight.

 

Three rule cards. Leaving: over 150K tokens, compact or end the session, about $1.70 saved per long gap. Working: over 350K tokens with 15 or more replies to go, compact. Switching models: do not worry, under 2% of our bill.

Sources

  1. Anthropic, “Pricing,” Claude Platform documentation, accessed December 4, 2026.
  2. Anthropic, “Prompt caching,” Claude Platform documentation, accessed December 4, 2026.
  3. Anthropic, “Compaction,” Claude Platform documentation, accessed December 4, 2026.
  4. Distributed Logic, Claude Code session logs on one PC, October 21 to December 4, 2026 (measured, aggregates only).

Leave a Reply

© Copyright 2021 Distributed Logic Corp.

contact via web form  |  info@distributedlogic.com   |    (866) 229-8621