← Back to Blog

Claude Code Rewrote 314k Tokens for a Two-Line Recap

The cache had expired. I built cache-tax to show the cold-cache price at send time, or keep selected sessions warm until I return.

Skip to the install →

I asked a 330,316-token Claude Code session for a two-line recap. cache-tax stopped the message first and estimated a $6.61 cache write. I sent it again. Claude Code reported 314k cache-write tokens, worth $6.28 at Fable 5.1 API rates, before counting the answer.

Within included subscription usage, that dollar figure is a public cost yardstick, not an extra charge. The practical value is the guard before a cold return and keeping a selected long session cached. Anthropic does not document how cache reads and writes count against plan limits, so I do not claim quota savings.

Real Claude Code recording of cache-tax stopping a recap request and showing a $6.61 estimated cache-write cost before the user resends it
Real run, recorded with cache-tax 2.1.1. The estimate used the engine's 330,316-token context figure. The write that followed was 314k tokens.

Why minute 61 is different

Claude Code sends the system prompt, project context, conversation and tool results with each turn. Prompt caching makes the unchanged prefix cheap. A cache hit resets its timer. After the time-to-live expires, the next request processes that prefix again and establishes a fresh cache.

Within included subscription usage, Claude Code gives the main conversation a one-hour cache by default. At Fable 5.1 list prices, a one-hour write is $20 per million tokens and a read is $0.25. That is an 80x difference per cached token.

Timeline comparing a warm 314k-token cache read at about eight cents with a $6.28 rewrite after one hour of inactivity
The same 314k-token prefix is about $0.08 to read or $6.28 to write on Fable 5.1. Output and new input still cost tokens.

What you see before a cold send

Both forms watch for an ordinary message after a large context has been idle past its cache lifetime. The hook warns by default. Set CACHE_TAX_BLOCK=1 and it refuses once. The Mod refuses once by default. Slash commands still pass, so you can run /clear and start from a handoff note.

The README example shows the current refusal.

cache-tax: the prompt cache went cold 2h00m ago.
Sending this re-writes up to 200,502 tokens at $20/MTok = $4.01
(a warm turn would have cost $0.05).
Send it again to pay it, and keepwarm will then hold the cache for 3h00m. Or /clear and start from a note.

Resending is unconditional. The guard does not trap you in a loop or silently replace your prompt. Its job is to move the decision to the moment before the expensive request.

The keep-warm loop has to prove itself

The Mod adds the part a shell hook cannot. Run /keepwarm 90m for a short return window or bare /keepwarm for six hours. A timer inside Claude Code waits for 50 idle minutes, then sends one tool-less fork over the session. No heartbeat prompt or answer appears in the visible conversation. A looped hi adds a user turn and a model reply. cache-tax reads the fork's usage and stops when the readback says the cache was already cold.

cache-tax Mod lifecycle from a bounded keep-warm window through the idle timer, tool-less fork, usage readback, rearm on a cache hit and stop on a cold result
The loop only rearms after usage says the ping read cached context. It stops after an empty read or a write at least one tenth of the read.

The 62-minute return

Mock tests can prove the timer and stop rules. They cannot prove that a fork shares the server-side cache. I needed a live run.

On September 19, the main conversation sat idle while a separate background agent kept working. The default ping fired at minute 50, read 157k cached tokens and reset Claude Code's native cache countdown to 58 minutes. My message at minute 62 then read 156,886 cached tokens and wrote 2,255.

Real Claude Code status line after a keep-warm ping, showing 157k cached tokens read and the next ping in 50 minutes
The visible ping receipt from the same session. Claude Code's cache countdown reset to 58 minutes. The returning request's 156,886-token read comes from the session transcript.

That run proves the session stayed readable past the original hour in this setup. It does not prove net savings for every session. Prefix changes can break the cache regardless of time, and a ping has its own read, uncached input and uncapped output cost.

Use it on sessions you will resume

If the work is finished, let the cache die. Keeping every abandoned session warm wastes tokens. The useful cases are long sessions you plan to return to after lunch, or a main conversation waiting while another agent or workflow finishes.

At Fable 5.1 rates, the read-only upper bound is 80 cache reads for the price of writing the same context once with the one-hour tier. Real pings cost a little more because the fork can answer. This is why cache-tax uses bounded windows and why /keepwarm off exists.

Anthropic documents cache pre-warming as an API pattern for loading a prompt before the real request. The host must remain running for cache-tax. Included subscription usage gives the main conversation a one-hour cache by default. For API keys, cloud providers and usage credits, set promptCacheTtl to 1h; the main conversation otherwise uses a five-minute cache, shorter than the 50-minute timer.

Pick the form you need

Warm the session and guard the return

Use the Mod. It runs inside Claude Code, verifies each ping and refuses a cold send once.

Warn, block or show a countdown

Use the hook. It works without the function-hooks flag and never sends a keep-warm request.

Install the Mod

claude plugin marketplace add karanb192/claude-code-mods
claude plugin install cache-tax@claude-code-mods

If you use an API key, cloud provider or usage credits, add promptCacheTtl to the existing object in ~/.claude/settings.json. Included subscription usage does not need this setting. The setting requires Claude Code 2.1.242 or later.

{
  "promptCacheTtl": "1h"
}
CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude

In the session you want to preserve, run /keepwarm. The cache-tax page has every command, the validator footprint and the limits.

Install the hook

claude plugin marketplace add karanb192/claude-code-hooks
claude plugin install cache-tax@claude-code-hooks

The hook README includes the optional block setting and the standalone status-line row. Both forms are free, open source and explicit about what they can touch.


Sources and code