Keep-Warm: Use Prompt Caching to Keep Claude Code Costs Low
Claude Code's prompt cache is a timer. Step away long enough and it expires, so the first answer back re-reads the whole conversation at the full write price. Keep-Warm is a small Claude Code mod that sends a cheap real turn just before expiry, keeps going while a question sits unanswered, and stops before the context fills. Here is the cache theory, the measured attempt that failed, and the one command that installs it.
You ask Claude Code for a big refactor, then leave for lunch. The session stays open, but the prompt cache behind it is a timer, and the timer runs out while you are away. When you come back, your first question can’t reuse anything. The model re-reads the whole conversation from zero, you pay the full cache-write price for it, and the answer is slow. It gets worse when the model asked you a question before you left: the chat is stuck waiting for you, so nothing can touch the cache at all. The work was done. The cache was not, and the bill and the wait land on the first thing you type.
Architecture: Keep-Warm, from the chat
Keep-Warm is a mod for Claude Code. It watches the cache timer, and when the chat is idle and
the cache has about 75 seconds left, it submits one short real turn. That turn reads the cached
conversation, and reading resets the timer. Click through the loop below. The meter stays at
$0 for every local step and moves once, on the single paid step: the model reading a 100k-token
cached conversation.
Five pieces, each doing one job:
| Piece | Job |
|---|---|
| Status line chip | Shows warm or cold and time left, and saves the expiry to a small file per session |
| Expiry watcher | Every 15 s: is the chat idle, the prompt box empty, and under 75 s left? |
| Nudge turn | One short message. The reply ends with idle, working or blocked. Max 12 in a row |
| Open-question release | After 20 min of an unanswered question, answers for the model, keeps the dialog open |
| Handoff band | At 65% context and an idle chat, moves the work to a fresh session |
The chip turns yellow under 15 minutes and red under 5. Inside 10 minutes it also shows the dollar cost of a rebuild, so you can see what the cold cache would charge before it does.
Why prompt caching matters
Every request to the model carries the whole conversation: system prompt, tools, and every earlier turn. Prompt caching lets the API reuse the part of the prompt it has already processed instead of computing it again. The API matches the start of the new request against recent ones, so the reused part must be an exact prefix. Change anything early and everything after it is a miss.
Two things follow, and both are in Anthropic’s prompt-caching documentation:
- Cost. A cache read costs a fraction of a normal input token. A cache write costs more than a normal input token. Warm means you pay the small read price. Cold means you pay the write price for the whole conversation again.
- Time. A cache entry has a lifetime. Each use refreshes it at no extra charge, and the timer counts from the start of the request. When the lifetime passes with no use, the entry is gone.
| Fact | Value |
|---|---|
| Default lifetime | 5 minutes |
| Optional lifetime | 1 hour, at extra cost |
| 5-minute cache write | 1.25 times the base input price |
| 1-hour cache write | 2 times the base input price |
| Cache read | 0.1 times the base input price on most models; 0.05 times on Claude Opus 5.5 and Claude Sonnet 5.5; 0.025 times on Claude Fable 5.1 |
| Example, Claude Opus 5.5 per million tokens | input $4, 5-minute write $5, 1-hour write $8, read $0.20 |
Claude Code adds its own rule. Per
its prompt-caching page, it asks for the 1-hour
lifetime on the main conversation only on a Claude subscription within your plan’s included usage.
With an API key, cloud provider or usage credits the main conversation gets 5 minutes unless you
set promptCacheTtl or CLAUDE_CODE_PROMPT_CACHE_TTL to 1h. The same page says each model has
its own cache, so switching models with /model means the next request reads the whole history
with no hits. Keep-Warm reads the real lifetime from the status line, so it follows whichever one
you have.
Move the sliders. The point to notice: at these prices one cold rebuild costs as much as 25 to 80 warm reads, depending on the model and the lifetime.
- Illustrative: the nudge turn does no tool work and adds about 600 new tokens.
- The cap of 12 nudges covers about 12.8 h at this lifetime.
- Prices per million tokens from Anthropic's prompt-caching table: write 1h, read at the model's hit rate.
What you see when the cap runs out
Push the “You are away” slider past the cap point and the Keep-Warm bar jumps above the other bar. That is the design, and it is honest: the cap is a brake, not a promise. After 12 nudges in a row Keep-Warm stops sending them. If you are still away, the cache then expires and the next message pays the rebuild, on top of the nudges already spent. At the default 1-hour lifetime that point is about 12.8 hours. With Claude Opus 5.5 and 100k tokens, 12 hours costs $0.32 with Keep-Warm against $0.80 without, and 13 hours costs $1.10 against $0.80. Here is what the screen shows and what you can do.
| Moment | What you see |
|---|---|
| Each nudge | A normal message in the chat that starts with Keep-warm check., and the toast Keep-warm nudge sent (N of 12) |
| Cache is healthy | Status chip is green above 15 minutes left, yellow from 15 to 5, red under 5 |
| Last 10 minutes of the cache | The chip adds the rebuild price, for example $0.80 if cold |
| Cap reached | The toast Keep-warm paused after the nudge limit. Send a message to resume. It appears when the 13th nudge would have been due, up to 75 seconds before expiry |
| Cache expired | The chip turns red and reads COLD, with the price as $0.80 to rewarm |
These are the real status line script run on made-up input, not a mock-up. The sample is a 1-hour cache on Claude Opus 5.5 with an illustrative 100,000-token conversation.



- The nudge is a real message. Keep-Warm types a short prompt into the chat for you and submits it. It is a normal turn: it shows in the conversation, the model answers it, and you pay for it. Nothing is hidden.
- Nothing runs on its own after the cap. No more nudges are sent. The chip keeps counting down
and then shows
COLDwith the price. The cost is your choice from there. - Choice 1: reply. Any message you send resets the count to zero and Keep-Warm starts nudging
again. If you send it while the chip still shows time left, the reply reads the warm cache and
is cheap. If the chip says
COLD, that reply pays the rebuild shown on the chip. - Choice 2: start fresh with
/handoff. It writes a handoff note and continues in a new, smaller session instead of carrying the full conversation. The prep step is itself one turn in the current session, so on a cold cache it reads the old conversation once at the rebuild price. This guide has not measured whether a handoff is cheaper than a rebuild, so it does not claim it. - Choice 3: raise the cap. Keep-Warm reads
~/.claude/keepwarm.jsonwhen a session starts. Set{ "max_consecutive": 24 }there, then start a new session. The value must be a whole number above zero; anything else falls back to 12.KEEPWARM_CONFIGpoints to a different file. The same file takes"enabled": falseto turn Keep-Warm off. - Closing the chat stops all nudges. Keep-Warm runs inside the open session, so the wasted
case is a chat that stays open and nobody returns to. Close it, or run
/keepwarm off, and the spending ends.
How the design got here
The first idea was wrong, and measuring it is the reason the design looks the way it does. Click through the five stages. Each one is what was tried, what broke, and what was learned.
Leave a long session open and walk away. The cache entry behind it lives for one hour.
The hour runs out. The first answer when you return re-reads the whole conversation at the cache-write price, and it is slow.
The cache is a timer, not storage. Only a request that reads the cached prefix resets it.
The decision logic is small. A clean-room sketch of the ping rule, not the shipped code:
const WINDOW_S = 75; // ping when the cache has this long left
const MAX_IN_A_ROW = 12; // hard brake
const FULL_PCT = 90; // too full to keep paying for
function nextAction({ chatIdle, draft, secondsLeft, pings, contextPct }) {
if (!chatIdle || draft) return "wait"; // never interrupt you
if (secondsLeft <= 0) return "too-late"; // already cold
if (secondsLeft > WINDOW_S) return "wait"; // still warm enough
if (contextPct >= FULL_PCT) return "hand-off";
if (pings >= MAX_IN_A_ROW) return "stop";
return "ping";
}
And the trick for the open question, as a clean-room sketch: race the human against a timer, and if the timer wins, answer for the model but keep the dialog alive.
const RELEASE_MS = 20 * 60 * 1000;
async function guardQuestion(question, showDialog, nextEvent) {
const winner = await Promise.race([showDialog(question), timeout(RELEASE_MS)]);
if (winner !== TIMEOUT) return winner; // you answered in time
showDialog(question).then((late) => // dialog stays on screen
sendAsMessage("My answer to your open question: " + late)); // resets the count
return { answer: "not answered yet, end your turn" }; // frees the chat
}
Install Keep-Warm
Keep-Warm is one part of the handoff mod, and the @yasaswy.nagavolu/agents npm package has no
keep-warm-only bundle. This command installs the handoff mod, which contains Keep-Warm, and sets
the CLAUDE_CODE_PLUGIN_DIRS setting so Claude Code loads it:
npx '@yasaswy.nagavolu/agents' install --bundle handoff
The mod needs Claude Code 2.1.287 or later, because mods are early access. Start a new Claude Code session after installing. The same mod also has a one-click handoff, which this article does not cover.
Keep-Warm separately needs a status line script that saves the cache timer to a small file. The
package’s harness-hygiene bundle ships one. Without it Keep-Warm stays quiet.
| You want to | Type |
|---|---|
| Turn keep-warm on, off, or check it | /keepwarm on, /keepwarm off, /keepwarm status |
Keep-Warm is on by default. Environment knobs, all optional. Set them in PowerShell before you start Claude Code:
$env:KEEPWARM_RELEASE_MS = 600000 # release an open question after 10 min instead of 20
$env:KEEPWARM_WINDOW_MS = 90000 # start nudging 90 s before expiry instead of 75
$env:KEEPWARM_TICK_MS = 10000 # check every 10 s instead of 15
The honest limits
Questions the model asks (AskUserQuestion). After the release time the mod answers for the model, keeps the dialog on screen, and delivers your late answer as a normal message. Plan approval and permission prompts cannot be parked and re-shown by the plugin API, so while one is open the nudge cannot run and the cache can expire.
Technicals
The real stack behind this build, on record:
- Agentic harness: Claude Code, using its mod API (early access, needs 2.1.287 or later).
- Skill/mod name: Keep-Warm, a part of the
handoffmod. Installed withnpx '@yasaswy.nagavolu/agents' install --bundle handoff; there is no keep-warm-only bundle. It also needs the status line script from theharness-hygienebundle. - Memory/RAG system: one-brain, a local memory MCP. The fork measurement and the design decisions were saved there, not in a hosted vector store.
- Source: the
mods/handofffolder inside the@yasaswy.nagavolu/agentsnpm package. There is no separate companion repository.
The cheat sheet
- The cache is a timer. Only a request that reads the cached prefix resets it.
- Cold costs the write price for the whole conversation. Warm costs the read price.
- Measure before you build. A silent fork ping read 16,942 of 48,975 tokens and rewrote 32,036.
- Waiting for a human is not busy. Release the open question, keep the dialog.
- Brakes are code, not hope: 12 nudges, a stop at 90% context, a pause on
idleorblocked. When the cap runs out the chip showsCOLDand the price, and you choose: reply,/handoff, or raisemax_consecutive. - It stops before the context fills. At 90% context it skips the nudge and says
hand off now.