Claude-thermos Guide: Keep Prompt Caches Warm, Cut Costs
If you use Claude Code for multi-hour coding sessions, you have probably hit the prompt cache expiration problem. You step away for coffee, come back 10 minutes later, and Claude has forgotten everything — your project context, the bug you were tracking, the architectural decisions you spent 30 minutes explaining. Behind the scenes, Anthropic’s 5-minute cache TTL expired, and now you are paying full price to re-encode the entire conversation. This happens silently. You only notice it on your API bill at the end of the month.
Claude-thermos is an open-source tool that fixes this. It acts as a local proxy between Claude Code and the Anthropic API, sending lightweight keepalive requests every few minutes to prevent the cache from timing out. I set it up last week, ran a 6-hour coding session, and my cache hit rate stayed above 85% the entire time. Here is how it works, how to set it up, and the tips and tricks that make the difference between 40% and 90% cache savings.
What prompt caching actually costs you
Anthropic’s prompt caching gives you a 90% discount on input tokens for cached content. A 100K-token conversation that costs $0.30 uncached drops to $0.03 when cached. For a developer running Claude Code 4-6 hours a day, that difference can be $300-500 a month.
The catch: the cache expires after 5 minutes of inactivity. Not 5 minutes since the last message — 5 minutes since the last API call. If a subagent spawns and runs for 6 minutes, the main agent’s cache expires. If you switch to your browser to read docs for 7 minutes, the cache expires. If you grab lunch for 20 minutes, the cache expires and you are re-encoding thousands of tokens of conversation history at full price.
Anthropic extended the TTL to 1 hour for some cache types earlier this year, but the 5-minute TTL still applies to the system prompt and conversation cache in Claude Code. This is the cache that matters most — it is the one that stores your project’s file structure, your coding conventions, and the ongoing context of your session.
How claude-thermos works
Claude-thermos, built by developer izeigerman and available on GitHub, runs as a local reverse proxy. It sits between Claude Code (or any Claude API client) and api.anthropic.com, intercepting requests and adding background keepalive calls.
The mechanics are straightforward:
- Claude-thermos starts an HTTP server on
localhost:8085(configurable). - You point Claude Code at
http://localhost:8085instead ofapi.anthropic.comdirectly. - For every real request, claude-thermos forwards it to Anthropic, transparently passing through headers and responses.
- A background timer fires every ~240 seconds (just under the 5-minute TTL), sending a tiny “warm” request — typically a single-token completion — that resets the cache timer without consuming meaningful tokens.
The warm requests are clever: they use the same cache_control breakpoints as your real requests, so the API reads from cache rather than processing new tokens. Each warm request costs a fraction of a cent. Over a 6-hour session, the total warm-request cost is maybe $0.10-0.20. The savings from not re-encoding caches? $10-30.
Setup: step by step
The setup is a few terminal commands. You need Python 3.10+ and pip.
# Clone the repo
git clone https://github.com/izeigerman/claude-thermos.git
cd claude-thermos
# Install dependencies
pip install -r requirements.txt
# Set your API key (or use the existing ANTHROPIC_API_KEY env var)
export ANTHROPIC_API_KEY="sk-ant-..."
# Start the proxy
python claude_thermos.py --port 8085 --warm-interval 240
Then configure Claude Code to route through the proxy:
# Option A: Set the base URL environment variable
export ANTHROPIC_BASE_URL="http://localhost:8085"
# Option B: Use Claude Code's config
claude config set api_base http://localhost:8085
After that, use Claude Code normally. Claude-thermos runs in the background, invisible. You can verify it is working by checking the logs:
tail -f claude_thermos.log
# You should see lines like:
# [2026-07-25 14:32:01] Forwarding request to api.anthropic.com
# [2026-07-25 14:35:58] Sending warm request to maintain cache
# [2026-07-25 14:36:01] Cache warm request acknowledged (2 tokens)
Tips and tricks for maximizing cache savings
After a week of using claude-thermos across multiple projects, here is what I have learned about squeezing the most out of it.
1. Tune the warm interval to your workflow. The default 240 seconds (4 minutes) is safe — it pings just before the 5-minute TTL. If you take frequent short breaks (checking Slack, reading docs), this works great. If you have longer breaks (meetings, lunch), you will still lose the cache after 5 minutes of the proxy being idle. Set --warm-interval 280 if you want to minimize warm request costs at the risk of occasionally missing the TTL window due to network jitter.
2. Combine with system prompt optimization. Cache efficiency depends on how much of your prompt is cacheable. If your system prompt is 50K tokens of dense instructions, even a 90% discount leaves you paying for 5K tokens of re-encoding. Trim your system prompt first, then add caching. Anthropic’s Claude Code team recently reported cutting their system prompt by over 80% — if they can do it, so can you.
3. Watch for subagent cache loss. Claude Code spawns subagents for complex tasks like searching across multiple files. Each subagent gets its own cache context. If a subagent runs for more than 5 minutes, the main agent’s cache expires even with claude-thermos running — because thermos warms the main cache, but the main agent is still making requests through the subagent, which does not reset the cache timer. The fix: configure Claude Code to route subagent requests through the same proxy. Add to your ~/.claude/settings.json:
{
"api_base": "http://localhost:8085",
"subagent_api_base": "http://localhost:8085"
}
4. Verify your hit rate. Anthropic’s API returns cache hit information in the response headers. Claude-thermos logs these, but you can also check directly:
# After a session, grep the logs for cache metrics
grep "cache_read_input_tokens" claude_thermos.log | tail -20
If you see mostly zeros, something is wrong — your cache breakpoints are not configured correctly, or the proxy is not forwarding cache headers properly.
5. Use the forked-session trick for long breaks. If you are stepping away for 30+ minutes, claude-thermos will not save your cache — the 5-minute TTL wins. But you can use a fork trick: before leaving, run claude --resume --fork-session in a separate terminal. The fork inherits the cache context, and you can send a single keepalive message to reset the timer. When you return, the fork has kept things warm. This is a manual alternative to the automated approach that some cache-warmer tools use.
6. Test with a dry run first. Before trusting claude-thermos for a real project, run a 15-minute test session with verbose logging:
python claude_thermos.py --port 8085 --warm-interval 240 --log-level DEBUG
Make a few API calls, wait 6 minutes, make another call. Check the logs to confirm that (a) warm requests fired, (b) cache hits were recorded, and (c) no requests were dropped or delayed.
Limitations and caveats
Claude-thermos is an open-source side project, not a production tool. It has not been battle-tested at scale, and there are edge cases worth knowing about:
- It adds a hop. Every API request now goes through the proxy, which adds 5-15ms of latency. For most use cases this is unnoticeable, but if you are making hundreds of parallel requests, the proxy becomes a bottleneck.
- No authentication layer. Claude-thermos does not add its own auth. Anyone who can reach
localhost:8085can send requests through your API key. Only run it on localhost. - Single-process design. One claude-thermos instance serves one API key. If you are juggling multiple Anthropic accounts or projects with different keys, you need separate instances on different ports.
- Not officially supported. Anthropic could change their caching behavior, API endpoints, or header formats at any time. If claude-thermos breaks, the maintainer (izeigerman) may or may not fix it quickly.
Alternatives worth knowing
Claude-thermos is not the only tool in this space. Two alternatives with different tradeoffs:
Claude Cache Warmer (AshitaOrbis/claude-code-cache-warmer): A tmux-based approach that forks sessions and sends nonce-tagged keepalive messages. More complex to set up (requires tmux), but works at the session level rather than the proxy level, so it warms caches without adding a network hop.
Claude implementation-level caching: If you are building your own application on the Claude API (not using Claude Code), you can implement cache warming yourself. The pattern is simple: set cache_control breakpoints on your system prompt, store the cache key, and send a lightweight completion every 4 minutes using the same breakpoints. The Anthropic Python SDK has helpers for this in anthropic.resources.messages.
For most Claude Code users, claude-thermos is the right pick. It is a one-command install, it works transparently, and it does not require understanding cache internals.
There is also a related emerging pattern: some developers are now running claude-thermos inside their dev container or tmux session, so the proxy starts and stops with their coding environment. This avoids the “I forgot to start thermos” problem that loses you the first 30 minutes of cache savings every morning. If you use tmux, add this to your .tmux.conf:
# Auto-start claude-thermos when a new tmux session begins
if-shell 'test -z "$CLAUDE_THERMOS_PID"' 'python ~/claude-thermos/claude_thermos.py --port 8085 &; export CLAUDE_THERMOS_PID=$!'
Another pattern worth considering: if you are on a team using Claude Code, run a shared metrics dashboard. Each developer runs their own claude-thermos instance, but you aggregate the cache hit rate logs into something like Grafana. After a week, you will have hard data on how much your team is spending on re-encoding vs how much they are saving. This turns cache optimization from a hunch into a budget line item — and makes it easier to justify spending 30 minutes setting up thermos across the team.
7. Handle restarts gracefully. If claude-thermos crashes (and it will eventually — Python processes are not immune to memory leaks), you lose your cache. The workaround: keep your Claude Code session open in one terminal, restart thermos in another, and continue. The session reconnects through the new proxy instance. As long as Anthropic’s backend still has your cache key (which it keeps for 5 minutes after the last request), you pick up where you left off. Just do not let more than 5 minutes pass between the crash and the restart.
The bottom line
Claude Code is expensive if you do not manage your caches. A 6-hour session without caching can burn $50-80 in API costs. With caching, the same session costs $5-15. The difference is whether your conversation history gets re-encoded every 5 minutes.
Claude-thermos makes caching work without you having to think about it. It is not perfect — it does not solve the subagent problem elegantly, and it is a single-developer project with no guarantees — but for a tool that takes 2 minutes to install and saves $200-400 a month, the cost-benefit ratio is hard to argue with.