Keep Claude Code's prompt cache warm while idle — meet cwarm
Keep Claude Code's prompt cache warm while idle — meet cwarm
If you use Claude Code, you've probably hit this: you're deep in a session, step away for a meeting, come back — and it feels like it re-reads the entire conversation before answering. That's a prompt-cache miss.
Why it happens
Anthropic's prompt cache has a time-to-live: roughly 1 hour on Max and 5 minutes on Pro. Idle past that and the cache expires, so your next turn pays the full cost of re-reading the context. On macOS/Linux you can poke the session with something like tmux to keep it warm — but on Windows-native (Git Bash) there was no clean path. That's where cwarm started.
What cwarm does
It runs claude inside a pseudo-terminal (PTY) it controls, and when you've been idle past your plan's threshold it injects a tiny keepalive so the cache stays warm. The key part: the injection is an in-process PTY write, unrelated to window state — so it keeps working when the window is unfocused, minimized, or in the background. Only closing the window stops it.
A fun technical rabbit hole
My first instinct was "just send keystrokes to the terminal window." It turns out mintty (Git Bash's terminal), like PuTTY, ignores synthetic window messages entirely — PostMessage, SendMessage, even WM_PASTE: all tested, all no-ops. And SendInput needs the window to be focused. The only robust answer is the same one tmux, expect, and VS Code's terminal all use: own the PTY yourself.
Features
- Cross-platform: Windows / macOS / Linux, no tmux required (verified on Windows and a Raspberry Pi 4 / Linux aarch64).
- Plan-aware: injects only after a long idle (Max ~58 min, Pro ~4 min), with a cooldown.
- Focus/minimize independent: background and minimized both keep working.
- Optional cache-countdown statusline that wraps your existing one (with backup and one-command restore).
Install & use
npm i -g claude-cache-keepalive
cwarm # use it instead of `claude` (all args pass through)
An honest note
Keeping the cache warm means sending a tiny message (
hi) when you go idle, which counts against your plan usage and leaveshiturns in the conversation. It only fires after a long idle, with a cooldown — conservative and opt-in by design. If that trade-off isn't for you, don't use it. (It's spelled out plainly in the README.)
Open source (MIT)
If it saves you a few cache misses, a ⭐ on GitHub is appreciated. PRs and macOS/Linux reports welcome.
留言