Claude Code's API billing depends on how often the cache expires
This analysis examines how prompt caching mechanics govern real-world operational costs for engineering teams running Claude Code on complex programming tasks.
By Dillip Chowdary • Nov 13, 2026 • Source: HN Claude/Codex/Fable
In this post
Cloud optimization company Hystax open-sourced cache-management updates in its proxy tool Kompressor to cut prompt fees for developers running autonomous coding agents. Detailed in HN Claude/Codex/Fable's report, the utility tackles the five-minute cache expiration window in Anthropic API billing rather than relying solely on payload compression. By isolating uncached text fragments and keeping active prefixes warm during tool executions, the proxy addresses a primary driver of recurring token expenses in Claude Code workflows.
This analysis examines how prompt caching mechanics govern real-world operational costs for engineering teams running Claude Code on complex programming tasks. The findings apply directly to software engineers, machine learning practitioners, and platform architects running multi-turn autonomous coding agents against Anthropic models. Readers will learn the precise token economics behind prefix invalidation, the mechanics of automated cache warming, and how to configure proxy wrappers for long development workloads.
01Prefix caching and five minute timer expiration
Claude Code marks conversational turns with explicit caching points, producing outgoing API requests that pair an extended cached prefix with a truncated final payload. Anthropic bills Opus 5.5 cache reads at $0.20 per million tokens, representing approximately 92 to 95 percent of all prompt tokens billed during agent workflows. Initial five-minute cache writes cost $5 per million tokens, creating a twenty-five-fold pricing gap between reading established conversational history and writing new cache entries.
Autonomous agents frequently trigger complete cache rewrites when executing external tools that run for more than five minutes, such as test suites, model training routines, and compilation tasks. Once the five-minute inactivity window lapses, the subsequent agent turn must write the entire historical prefix back into memory at the full write price. In an uncompressed benchmark evaluation spanning 89 tasks, the agent experienced 33 separate cache expirations that forced the rewrite of 927,000 prompt tokens.
Traditional data compression methods fail across prefix-cached dialogues because altering a single byte within an existing cached prefix immediately invalidates the entire cache block. Kompressor prevents invalidation by leaving historical conversational segments byte-for-byte identical while compressing only newly generated, uncached fragments. In addition, fragments measuring under 4,000 characters bypass compression entirely because processing miniature chunks individually costs more than transmitting standard dialogue.
02Terminal Bench results and token rewrite reductions
Benchmark evaluations conducted on Terminal-Bench 2.1 across 89 programming tasks demonstrate substantial cost reductions when pairing Claude Code with active cache management. Running Opus 5.5 without proxy assistance incurred an aggregate run cost of $35.35 and suffered 927,000 discarded cache tokens. With Kompressor actively managing conversational prefixes and payload compression, overall execution costs dropped to $28.30, marking a 20 percent net savings.
| Metric | Baseline Claude Code | Kompressor Claude Code | Change |
|---|---|---|---|
| Run Cost | $35.35 | $28.30 | -20.0% |
| Lost Cache Tokens | 927,000 | 13,000 | -98.6% |
| Task Success Rate | 89.9% | 90.6% | +0.7% |
| Long-Task Cost | Baseline | -34.0% | -34.0% |
| Codex Cost | Baseline | -22.7% | -22.7% |
The benchmark revealed that eliminated cache invalidations accounted for the overwhelming majority of recovered tokens. Expired tokens plummeted from 927,000 down to 13,000 across the identical 89-task test suite, reducing wasted cache writes by over 98 percent. The intervention preserved agent reliability throughout testing, posting a 90.6 percent task completion rate compared to 89.9 percent on the uncompressed baseline.
Cost metrics separated cleanly between cache retention and raw text compression. Preserving prompt cache continuity contributed approximately 11 percentage points of overall savings, while selective payload compression contributed the remaining margin. The combined approach outperformed standalone compression results previously recorded on OpenAI Codex, where compression alone delivered a 22.7 percent expense reduction.

03Cost reductions on compilation and model training
Financial savings concentrated heavily within development tasks where the coding agent paused while awaiting tool completion. Long-running CLI operations such as compilation, deep learning training cycles, and extensive simulation sweeps routinely exceed the default five-minute API cache lifetime. On tasks featuring tool pauses longer than five minutes, Kompressor reduced total execution billing by 34 percent.
To maintain cache continuity across lengthy background processes, the proxy dispatches keep-warm requests every 4.5 minutes while the agent waits on tools. These pings transmit the prior request using a max_tokens limit of 1, prompting Anthropic infrastructure to re-read the existing cached dialogue and restart the five-minute timer. The ping cycle terminates automatically upon the agent's next request, after approximately 50 minutes of inactivity, upon any network failure, or if a ping detects an empty cache.
Advertisement
Tech Pulse Daily
Get tomorrow's pulse first
Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.
For extended development pauses exceeding five minutes, the proxy shifts caching strategy by requesting Anthropic's one-hour cache tier for that specific conversation. This dual-action mechanism prevents expensive prefix rewrites during prolonged compilation steps without requiring developers to manually budget token allowances. Workflows characterized by rapid tool interactions saw modest gains, whereas build-heavy environments captured the highest proportional savings.
04Kompressor proxy setup and warm cache configuration
Developers can deploy Kompressor as an intercepting proxy wrapper around the standard Claude Code command-line interface. Installation requires cloning the open-source repository from GitHub and following the setup instructions in the project documentation. The default configuration automatically compresses newly generated text fragments exceeding 4,000 characters and manages dynamic transitions to hourly caching tiers during prolonged session pauses.
Automated cache warming requires an explicit configuration flag because it authorizes the proxy to send periodic background ping requests to the Anthropic API. Users enable background keep-warm pings by adding a provider stanza to the local configuration file:
[proxy.providers.anthropic]
cache_keep_warm = trueDevelopers then execute Claude Code through the proxy wrapper using the standard execution command:
kompressor wrap claudeStandard Claude Code management commands operate normally through the proxy layer. Engineers can update the underlying CLI package, select specific model tiers, or launch pinned agent sessions directly:
npm install -g @anthropic-ai/claude-code
claude update/model opusclaude --model opus05Path variance across agent execution runs
Engineers evaluating cache optimization metrics must account for non-deterministic agent pathing between benchmark iterations. Autonomous coding models rarely execute identical tool paths, terminal commands, or token sequences when presented with the same development prompt multiple times. Across the 89 benchmark evaluations, the entire observed difference in overall task solution paths traced back to just 4 distinct tasks.
Despite execution path divergences, structural savings generated by preventing cache expirations remain consistent across subsequent runs. The primary financial benefit stems from deterministic infrastructure behavior: retaining an active cache prefix at $0.20 per million tokens consistently avoids paying the $5 per million token write penalty. Baseline compression adds incremental efficiency, but infrastructure timing controls the broader expenditure curve.
Developers should monitor command runtimes and API billing dashboards when implementing automated proxy wrappers. Workflows dominated by quick feedback loops under three minutes capture minimal benefit from automated keep-warm pings while incurring slight request overhead. Teams operating prolonged test matrices, multi-stage container builds, or remote compilation toolchains stand to recover the largest share of prompt expenditures.
Claude Code's API billing depends on how FAQ
Why does prompt cache expiration increase Claude Code API costs?
Reading from the Opus 5.5 cache costs $0.20 per million tokens, whereas writing a new five-minute cache entry costs $5 per million tokens. When tools run longer than five minutes, the cache expires and forces the agent to rewrite the entire prefix at twenty-five times the cost.
How does Kompressor keep Anthropic prompt caches warm during long builds?
While an agent waits for a tool to complete, the proxy sends a ping request every 4.5 minutes with max_tokens set to 1. This prompts Anthropic to read the existing dialogue from cache, resetting the five-minute expiration timer for up to 50 minutes.
Does Kompressor compress existing conversational prefixes in Claude Code?
No, existing prefixes remain completely uncompressed because modifying a single byte invalidates cached blocks. The proxy compresses only new uncached text longer than 4,000 characters, leaving established conversational context byte-for-byte identical.
How much money does cache warming save on Claude Code tasks?
In Terminal-Bench 2.1 tests across 89 tasks on Opus 5.5, total costs fell 20 percent from $35.35 to $28.30, while tasks involving tool waits longer than five minutes saw costs drop 34 percent.
Sources
Author
Dillip Chowdary
Writes Tech Bytes coverage of AI, engineering, and the tools that actually ship. Editor of Tech Pulse Daily.
Related on Tech Bytes
Advertisement