🤖 AI Hot

Claude-thermos Keeps Prompt Cache Alive, Saves 20%

A
Alex Chen

Claude Code’s prompt cache saves you 90% on input token costs. The catch? It expires after 5 minutes of inactivity. If you use subagents — which nearly everyone doing serious work does — your main agent’s cache dies while it waits for subagents to finish. That’s 20% of your Anthropic bill evaporating into cache misses, according to the developer who built the fix.

The fix is claude-thermos, a new open-source tool that keeps your Claude session cache warm. Here are the tips and tricks for setting it up and the best practices for cutting your Anthropic bill without changing your workflow.

Why prompt caching matters (and why it keeps breaking)

Anthropic’s prompt caching gives you a 90% discount on input tokens when the same prefix appears in consecutive requests. In practice, this means your entire conversation history — system prompt, tool definitions, and all previous messages — gets cached after the first request. Every subsequent turn hits the cache instead of re-processing the full context.

The numbers are substantial. Claude Code sessions routinely push 10,000+ tokens of system context. Without caching, you pay full price for every token on every turn. With caching, input costs drop from $3.00/million tokens to $0.30/million tokens for Claude Sonnet.

But the cache has a five-minute time-to-live. Each new request on the same prefix resets the clock — as long as you keep sending messages within five minutes of each other, the cache stays warm. In a normal coding session where you’re reading output, thinking, and responding, this rarely matters. You send a message every minute or two, cache stays alive, everything is fine.

The problem shows up when you use subagents. Claude Code spins up subagents for complex tasks — searching codebases, running tests, linting, anything that benefits from a fresh context. Subagents use different system prompts and tool sets, which means their requests create new cache prefixes. The main agent sits idle while subagents work, and if a subagent takes more than five minutes, the main cache expires. The next message you send to the main agent re-processes everything from scratch at full price.

The developer behind claude-thermos, Ize Igerman, found that cache misses from subagent timeouts accounted for roughly 20% of his total Anthropic bill. For teams running Claude Code heavily, this isn’t pocket change — it’s hundreds or thousands of dollars a month in avoidable costs.

How claude-thermos works

The tool is conceptually straightforward. It uses Claude Code’s Stop hook mechanism to detect when a subagent is about to block the main agent. Just before the five-minute cache TTL expires, claude-thermos injects a tiny “keepalive” turn — a minimal request that hits the main agent’s cache prefix and resets the clock.

The keepalive request is deliberately cheap. It’s not asking Claude to do real work. It’s just pinging the cache with a lightweight message that costs a fraction of a cent. The alternative — letting the cache expire and re-sending the full context — costs orders of magnitude more.

The implementation relies on Claude Code’s plugin system. claude-thermos installs as a single plugin that hooks into the Stop event. When Claude Code is about to pause and wait for a subagent, the plugin checks how long it’s been since the last cache refresh. If the five-minute window is close to expiring, it fires off a keepalive turn before the main agent blocks.

A few technical details worth noting:

  • The keepalive messages use the same cache prefix as the main agent, so they benefit from the same 90% discount. A typical keepalive turn costs less than $0.001.
  • claude-thermos is smart enough to detect when subagents are actually running versus when the session is genuinely idle. If you walk away from your desk for an hour, it won’t spam keepalive requests indefinitely — the cache will expire and that’s fine.
  • The tool works with any Claude Code session, including sessions using custom system prompts or extended tool sets. It doesn’t modify your workflow or change how you interact with Claude.

For context, Anthropic offers two cache TTL tiers: 5 minutes (automatic, for dynamically generated prefixes) and 1 hour (explicit, for manually specified breakpoints). Claude Code uses the automatic 5-minute tier because conversation prefixes change with every turn. The 1-hour tier is available through the API’s cache_control parameter, but it requires you to explicitly mark cache breakpoints in your prompt structure — something Claude Code’s dynamic conversation model doesn’t support natively.

This is one of those situations where the API design makes sense in isolation but doesn’t quite fit how people actually use the tool. Subagents are Claude Code’s killer feature for complex work, but they interact badly with the caching model. Tools like claude-thermos bridge that gap until Anthropic addresses it at the platform level.

Other AI providers handle caching differently. OpenAI’s prompt caching is automatic and doesn’t expose a TTL — the cache persists as long as the prefix remains in memory on their servers. Google’s Gemini caching uses a similar model with automatic prefix matching. Anthropic’s explicit TTL approach gives developers more control but also creates failure modes that other providers avoid entirely. Whether you see that as a bug or a feature depends on your priorities around cost predictability versus operational simplicity.

Setting it up: step by step

Installation takes less than two minutes. You need Claude Code installed and a Claude API key configured.

# 1. Install the plugin from the marketplace
claude plugins install claude-thermos

# 2. Verify it's active
claude plugins list | grep thermos

That’s it. The plugin activates automatically in every Claude Code session. There’s no configuration file to tweak and no environment variables to set for basic use.

If you want to adjust the keepalive interval (default is 4 minutes — one minute before cache expiry), you can override it:

# In your .claude/settings.json
{
  "plugins": {
    "claude-thermos": {
      "keepaliveInterval": 240,
      "maxIdleTime": 1800
    }
  }
}
  • keepaliveInterval: seconds between keepalive pings. Default 240 (4 minutes). Lower values cost slightly more but provide a safety margin.
  • maxIdleTime: seconds before the plugin stops sending keepalive requests entirely. Default 1800 (30 minutes). After this, claude-thermos assumes you’ve stepped away and lets the cache expire naturally.

For most users, the defaults work perfectly. The only reason to adjust is if you have unusually long subagent runs or very tight cost constraints.

What you actually save

The savings depend on your usage pattern, but Igerman’s numbers line up with what I’ve seen. If you use Claude Code with subagents (the default for any non-trivial task), cache misses from subagent timeouts represent 15-25% of your total input costs.

A concrete example: my team runs Claude Code for code review, refactoring, and test generation. Our typical session involves 3-5 subagents, each running for 2-8 minutes. Before claude-thermos, roughly one in three sessions hit a cache expiration during subagent work. At our volume — about 2 million input tokens per day — that translated to an extra $60-80/month in cache-miss charges.

After installing claude-thermos, our cache miss rate dropped to near zero. The keepalive requests themselves added about $0.50/month to our bill. Net savings: roughly $60/month for a team of three developers.

The break-even point is low. If you’re spending more than $50/month on Claude API and using subagents, claude-thermos almost certainly pays for itself within the first week. For solo developers using Claude Code casually, the savings are smaller but still real — maybe $5-10/month.

One more thing I’ve noticed: there’s a psychological benefit that doesn’t show up in the numbers. Before installing claude-thermos, I’d sometimes rush through subagent work — checking the clock, worrying about cache expiration. Now I don’t think about it. The tool handles that in the background while I focus on the code. That mental overhead might seem trivial, but it adds up across dozens of sessions. Good tools make you forget they exist.

Limitations and caveats

claude-thermos is not magic. A few things to be aware of:

It only helps with subagent-induced cache misses. If your cache expires because you genuinely stepped away for 10 minutes, claude-thermos won’t help — its maxIdleTime setting intentionally lets those expire. This is by design. Wasting keepalive requests on genuinely idle sessions burns money for no reason.

It requires Claude Code’s plugin system. If you’re using the Anthropic API directly (not through Claude Code), claude-thermos won’t work. You’d need to implement your own cache-warming logic using the cache_control API parameter.

Keepalive requests still cost something. They’re cheap — fractions of a cent each — but at extreme scale they add up. If you’re running dozens of concurrent Claude Code sessions 24/7, monitor your usage. The tool’s sampling logic should keep this manageable for almost everyone.

There’s a philosophical question here. Anthropic could fix this problem server-side by maintaining caches across subagent boundaries. The fact that they haven’t suggests either an architectural limitation or a business decision. Using claude-thermos is working around that, which is fine for now, but keep an eye on Anthropic’s caching roadmap.

Who should use this (and who shouldn’t)

Use claude-thermos if:

  • You use Claude Code with subagents (the default for any task involving search, testing, or multi-step operations)
  • Your monthly Anthropic bill is over $50
  • You want to optimize costs without changing your workflow

Skip it if:

  • You use Claude Code for simple, single-turn tasks with no subagents
  • Your sessions are short enough that cache expirations rarely happen
  • You’re using the Anthropic API directly (build your own cache-warming logic)

There are also alternatives worth knowing about. claude-code-cache-keepalive by yujiachen-y takes a similar approach but uses a different hook mechanism. The core idea is the same across both tools: ping the cache before it dies. Pick whichever one fits your setup better.

The broader point: prompt caching is one of the most impactful cost optimizations available for LLM applications, but it’s also one of the most fragile. Tools like claude-thermos paper over the fragility. Long-term, I’d rather see Anthropic offer longer cache TTLs or smarter cache persistence across subagents. Until then, keep your cache warm.

If you’re evaluating whether to install this, here’s my take after a few weeks of using it: it’s the rare kind of tool that you install once and then forget about. It doesn’t change your workflow. It doesn’t add latency. It just quietly saves you money. Those are the best tools. The only downside is that you’ll stop seeing those 20% cache-miss line items on your Anthropic bill and wonder why your costs went down — and then remember this tool is running in the background, doing exactly what it says on the tin.

Disclosure: CarCare Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission at no extra cost to you. Learn more.
A
Alex Chen