Claude's 5-Minute Prompt Cache: Find Your Pause Bill and Cut It
DEV Community

Claude's 5-Minute Prompt Cache: Find Your Pause Bill and Cut It

A coding agent does not remember anything between turns. Every request sends the whole conversation again. That includes the system prompt, the tool definitions, and every file, diff and test log so far.

Prompt caching is what makes that affordable. The provider keeps the processed prefix for a while and bills the next read at a small fraction of the input price. "For a while" is the problem. On the Claude API the default is five minutes. Step away for eight minutes to read a diff or get coffee, and the next turn pays to rebuild the entire prefix.

On December 1, the LLM gateway company Requesty published 30 days of production numbers on what that costs. The post passed 330 points on Hacker News. This article checks that data against Anthropic's documentation. Then it covers who is affected, how to measure the cost in your own logs, and which fixes pay off.

A note on the source: Requesty sells a gateway that routes and optimizes LLM traffic, so it has a commercial interest in this topic. The numbers below are Requesty's measurements, not independent ones.

What the data says

Requesty looked at coding-agent traffic from October 24 to November 22, 2026. The tools were Claude Code, OpenCode, Codex, Pi and Kilo. It counted token and billing fields only, not prompt text. A "pause miss" is a turn after a gap of more than five minutes that reads less than 10% of the previous prompt from cache.

The headline results:

  • 23.1% of the Claude bill went to rebuilding caches after breaks longer than five minutes. On GPT models the figure was 9.3%.
  • Breaks of 5 to 30 minutes cost 15.2% of the Claude bill and 0.8% of the GPT bill.
  • Past 30 minutes both caches are gone, and the two families lose about the same share (7.8% and 8.5%).
  • The 5 to 10 minute slice alone cost 8.0% of the Claude bill. That is more than every break over an hour combined (5.3%).

One 8-minute break on a 210,000-token Claude Opus 5.5 session turns a $0.04 cache read into a $1.05 cache write at list price.

The comparison that explains it uses two models with the same price sheet. Claude Sonnet 5.5 and GPT-6.1 Sol both list at $2 per million input tokens and $10 per million output tokens, and both bill 1.25x to write the cache and 0.05x to read it. When a miss happens, the damage is almost identical: $0.35 on Sonnet 5.5, $0.37 on GPT-6.1 Sol.

The difference is how often it happens. Sonnet 5.5 missed on 81.2% of 5 to 30 minute breaks. GPT-6.1 Sol missed on 2.3%. Per break, that is $0.28 against $0.008.

Requesty's own estimate for a developer who takes four such breaks a day: about $23 a month per seat on Sonnet 5.5 and about $69 a month on Opus 5.5. That is an assumption about break habits applied to measured miss rates, so treat it as a rough figure.

Who this applies to, and who it does not

The original post does not mention this, but it decides whether the numbers apply to you. Anthropic's Claude Code documentation has a section called which TTL each request gets. TTL (time to live) is how long the cache survives without a read.

Claude Code puts each request in one of two buckets:

  • Claude subscription, within plan usage: the main conversation gets a one-hour TTL. Subagents, workflows and other side requests get five minutes, except a few helper requests Anthropic controls on the server.
  • API key, cloud provider, or usage credits: everything gets five minutes.

An Anthropic employee made the same point in the HN thread: the data "looks like API-billed traffic only", and Claude Code on a plan defaults to the one-hour cache. He also pointed out that the 23% figure includes breaks over 30 minutes, where Claude and GPT lose about the same.

So the people who pay this cost are:

  • Teams running Claude Code with an API key, through Amazon Bedrock, Google Cloud, or Microsoft Foundry.
  • Anyone running a third-party coding agent (OpenCode, Pi, Kilo, or a custom one) against the Claude API.
  • Subscription users after they pass their plan limit and start drawing on usage credits. The docs say Claude Code then drops the main conversation to five minutes.
  • Everyone, for subagents. One HN commenter noted that subagents stay on five minutes even on a subscription, and the docs confirm it.

Why five minutes runs out sooner than you think

The Claude API prompt caching docs list three rules that make the timer tighter than it sounds.

First, the clock starts when a request begins, not when the response ends. The docs give an example: if a response takes four minutes to stream, the next request must start within about one minute of it finishing.

Second, every read refreshes the timer at no extra cost. While the agent loops on its own (edit, run tests, read output), requests arrive seconds apart and the cache stays warm. The bill only jumps when the loop stops and waits for a human.

Third, the cache key is the exact prefix. Switching models, changing effort on some models, or adding an MCP server while tool search is off can also force a full rebuild. Claude Code's docs list these under actions that invalidate the cache.

The prices make the cliff steep. For Claude Opus 5.5, the pricing table lists $4 per million base input tokens, $5 for a five-minute cache write, $8 for a one-hour cache write, and $0.20 for a cache read. A miss costs 25 times a warm read on the same prefix.

On the OpenAI side, the prompt caching guide says GPT-5.6 and later models keep cache entries for a minimum of 30 minutes at a 1.25x write rate, with a 12-hour option in the Responses API at 2.5x. Requesty's data matched that: GPT-6.1 Sol cache hits held until about minute 29 and were gone by minute 31 to 33.

Step 1: Measure your own pause bill

Requesty's advice is to check your own logs before changing anything. Each Claude API response includes two usage fields: cache_read_input_tokens (tokens served from cache) and cache_creation_input_tokens (tokens written to cache). A pause miss looks like a turn that comes more than 300 seconds after the previous one, where reads drop near zero and writes jump to the full prompt size.

If your agent or gateway logs each response's start time and usage block as one JSON line, this short script finds those turns and prices them. It uses the same rule as the Requesty post: gap over five minutes, less than 10% of the previous prompt read from cache, cost counted as write price minus read price.

import json
import sys
from datetime import datetime
# USD per million tokens: (base input, 5m write, cache read)
PRICES = {
"claude-opus-5-5" : ( 4.00 , 5.00 , 0.20 ) ,
"claude-sonnet-5-5" : ( 2.00 , 2.50 , 0.10 ) ,
}
PAUSE_SECONDS = 300 # the default 5-minute TTL
def load ( path ) :
 rows = [ ]
 with open ( path ) as f :
  for line in f :
   if line . strip ( ) :
    r = json . loads ( line )
    r [ "t" ] = datetime . fromisoformat ( r [ "ts" ] . replace ( "Z" , "+00:00" ) )
    rows . append ( r )
 return sorted ( rows , key = lambda r : r [ "t" ] )
def pause_misses ( rows ) :
 misses , total_waste = [ ] , 0.0
 for prev , cur in zip ( rows , rows [ 1 : ] ) :
  gap = ( cur [ "t" ] - prev [ "t" ] ) . total_seconds ( )
  prev_prompt = ( prev [ "cache_read_input_tokens" ] + prev [ "cache_creation_input_tokens" ] )
  read = cur [ "cache_read_input_tokens" ]
  if gap > PAUSE_SECONDS and prev_prompt and read < 0.1 * prev_prompt :
   _ , write_price , read_price = PRICES [ cur [ "model" ] ]
   rebuilt = cur [ "cache_creation_input_tokens" ]
   waste = rebuilt * ( write_price - read_price ) / 1_000_000
   total_waste += waste
   misses . append ( ( cur [ "ts" ] , round ( gap / 60 , 1 ) , rebuilt , round ( waste , 2 ) ) )
 return misses , total_waste
if __name__ == "__main__" :
 misses , waste = pause_misses ( load ( sys . argv [ 1 ] ) )
 for ts , minutes , tokens , usd in misses :
  print ( f "{ts}idle {minutes} minrebuilt {tokens:,} tokensavoidable ${usd}" )
 print ( f "pause misses: {len(misses)}, avoidable cost: ${waste:.2f}" )

Run against a five-line sample log (made-up numbers that recreate the 210,000-token, 8-minute case), it prints:

2026-12-01T10:10:10Zidle 8.0 minrebuilt 210,000 tokensavoidable $1.01
pause misses: 1, avoidable cost: $1.01

The $1.01 is the $1.05 write minus the $0.04 read the turn would have paid on a warm cache. The script is a starting point: it treats one log file as one conversation, so split by session ID first if you log several at once. Add your models' prices from the pricing table.

If you use Claude Code itself, you do not need a script for a first look. The costs page says /usage shows a Prompt cache (main) line with the hit ratio, the number of misses, and whether the cache is warm right now (Claude Code v2.1.251 or later). Newer versions (v2.1.260 or later) also name the likely cause of the last miss.

Step 2: In Claude Code, choose the TTL yourself

If you run Claude Code with an API key or a cloud provider, the docs say to set promptCacheTtl to 1h in your settings file to give the main conversation a one-hour cache. A second key, subagentPromptCacheTtl, covers subagents and other side requests. Both need Claude Code v2.1.242 or later.

This is the example from the settings reference:

{ "promptCacheTtl" : "1h" , "subagentPromptCacheTtl" : "5m" }

The environment variables CLAUDE_CODE_PROMPT_CACHE_TTL and CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL do the same thing and take precedence over the settings.

To confirm which TTL your writes used, run claude -p "hello" --output-format json and look at usage.cache_creation. One-hour writes appear under ephemeral_1h_input_tokens, five-minute writes under ephemeral_5m_input_tokens.

Keeping subagents on five minutes is usually right. They tend to run in tight loops and finish quickly, so the higher one-hour write rate buys nothing. The exception is subagents that sit idle waiting on long builds or on a queue. One HN commenter described that case: many subagents that "end up having to wait for a long time for their turn to build and run the game".

If you route Claude Code through your own gateway with ANTHROPIC_BASE_URL, check one more detail. The docs say part of the one-hour request travels in the anthropic-beta header, so the gateway must forward that header unchanged.

Step 3: On the API, use one hour carefully

The raw API has the same switch: add "ttl": "1h" inside cache_control. But a one-hour write costs 2x base input instead of 1.25x, and you pay it on every write, including the short sessions that never pause. Requesty replayed its 30 days of traffic with several strategies. Turning on one hour from the first turn for everything made most sessions more expensive, not less: 87% to 89% of sessions paid more.

Two patterns did better:

  1. Split the prefix by how often it changes. The docs allow both TTLs in one request, with one rule: one-hour entries must come before five-minute entries. So you can put the static part (tools and system prompt) on one hour and let the growing message history use five minutes:
response = client . messages . create (
model = "claude-opus-5-5" ,
max_tokens = 1024 ,
cache_control = { "type" : "ephemeral" } , # automatic 5m breakpoint on the conversation
system = [ { "type" : "text" , "text" : SYSTEM_PROMPT , "cache_control" : { "type" : "ephemeral" , "ttl" : "1h" } , } ] ,
messages = history ,
)

After a long break, the system prompt and tools still read from cache, and only the conversation part is rebuilt.

  1. Switch to one hour only after the first miss. Requesty found that moving a session to one hour on the first turn after a five-minute miss (on turn 10 or later) saved about 5% to 7% net. The cache is cold at that point anyway, so the switch costs nothing extra.

What not to do: upgrade a warm five-minute cache to one hour in the middle of a session. Requesty's live tests on the Anthropic API and Vertex read zero tokens and rewrote the whole prompt at the 2x rate. This follows from a billing rule in the docs' mixing TTLs section: a hit on a five-minute entry does not count if a one-hour block after it is a cache miss. Requesty reported that Bedrock behaved differently in 4 of 4 runs, which is not documented.

Step 4: Keep the cache warm with a zero-token ping

The fix that saved the most in Requesty's tests was a keep-alive ping. After about 4.5 minutes of idle time, resend the exact last request with max_tokens set to 0. The API reads the cached prefix, generates nothing, and the read restarts the five-minute timer.

max_tokens: 0 is an official feature. Anthropic's docs describe it under pre-warming the cache: the response comes back with an empty content array and stop_reason: "max_tokens", and zero output tokens are billed. The docs list the limits too. A zero-token request is rejected if it sets stream: true, extended thinking (thinking.type: "enabled"), structured outputs, or a forced tool_choice, and it is not allowed inside Message Batches. The request must also match the real one exactly, since thinking and effort settings are part of the cache key.

A ping is not free. It pays for a full-prefix read every time. So the question is when it is worth it. Requesty gives the break-even point as read cost divided by (write cost minus read cost). The ping pays off when the chance the user comes back within the next window is higher than that number:

def ping_break_even ( read_mult , write_mult ) :
 return read_mult / ( write_mult - read_mult )
for name , read_mult in [ ( "Opus 5.5 / Sonnet 5.5" , 0.05 ) , ( "models with 0.1x reads" , 0.10 ) , ( "Fable 5.2" , 0.025 ) ] :
 print ( f "{name}: ping pays off above {ping_break_even(read_mult, 1.25):.1%}" )
Opus 5.5 / Sonnet 5.5: ping pays off above 4.2%
models with 0.1x reads: ping pays off above 8.7%
Fable 5.2: ping pays off above 2.0%

The bar is low, but early in a session it is still not met. In Requesty's data, the chance of a developer returning was 2.7% on turns 1 to 5 and rose to 30.8% past turn 100. Their best schedule used no pings on short threads and 2 to 6 pings on deeper ones, and it cut about 8% to 9% net off the Claude coding bill.

The catch: your agent code must keep the last request body for up to about 30

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.