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.
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 " 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:
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.
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:
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:
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.
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 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
PRICES = {
"claude-opus-5-5": (4.00, 5.00, 0.20),
"claude-sonnet-5-5": (2.00, 2.50, 0.10),
}
_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 _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 > _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 = _misses(load(sys.argv[1]))
for ts, minutes, tokens, usd in misses:
print(f"{ts} idle {minutes} min rebuilt {tokens:,} tokens avoidable ${usd}")
print(f" 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:10Z idle 8.0 min rebuilt 210,000 tokens avoidable $1.01
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.
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.
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 .
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:
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.
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.
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 minutes, and pings sent after a developer has stopped for the day are wasted. In their replay, 43% to 52% of long sessions spent more on pings than they saved, even though the total bill went down.
Anthropic's own docs lean the other way for long gaps. The pre-warm section says that for longer gaps between requests, use the one-hour duration instead. In Requesty's tests the pings saved more, but one hour is simpler if your code cannot store request bodies.
A few habits help regardless of setup.
Compact before you leave, not after. Claude Code's docs explain that /compact while the cache is warm reads most of the history from cache, so it is cheap. After the cache expires, the same command reprocesses the full history as uncached input. On the one-hour TTL, Claude Code can also compact a long idle conversation automatically before the cache expires (the idleCompaction setting).
Pick the model and effort level at the start. Each model has its own cache, so a mid-task /model switch rebuilds everything, even when the content is identical.
The HN discussion pushed back on several points, and some of the pushback is fair.
The data comes from one gateway's customers, and those customers pay API rates by definition. It says nothing about Claude Code on a subscription, where the main conversation already uses one hour. One commenter called the article "Chicken Little", arguing that it describes a cost that only hits you if you walk away for more than five minutes between requests. Another replied that the cost became real once they were steering four or five chats that each waited minutes for feedback: "Pretty soon you're juggling a bunch of 5 min timers."
Both points hold. The 23.1% is an average over real coding traffic, not a law. If your agent runs long autonomous loops and you rarely mid-session, your number will be smaller. If you review every diff by hand, run long builds, or run several sessions at once, it can be larger. Among active coding teams (over $100 a month in spend) in Requesty's data, the median Claude team lost 23.3%, but the middle half ranged from 11.1% to 29.4%.
That is why Step 1 comes first. The defaults are documented and the fixes are small. The missing piece is your own number.
How often does your agent sit idle for 5 to 30 minutes in the middle of a session, and have you checked what those turns cost?