Skip to content

Keep-Warm

When a session pauses longer than its prompt-cache lifetime and then resumes, most of the prefix is written again at the cache-write rate. A Keep-Warm ping reads the cached prefix just before it expires, which refreshes it for another hour at roughly a tenth of the input price.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py keepwarm-decide set off # in session and headless
python3 measure.py keepwarm-decide set on # both on, without waiting for the line
python3 measure.py keepwarm-decide set budget 3 # dollars per 24 hours; 0 is off
python3 measure.py keepwarm-decide status # what is on, why not, and today's spend

The line is printed only in an interactive terminal session of Claude Code on macOS or Linux. Print mode, agents, cloud sessions, desktop-only use, Windows and other tools never print it, so nothing pings there until you run set on. A settings file that cannot be read, or a saved value or environment switch Token Optimizer does not know, turns Keep-Warm off.

Approving Keep-Warm in the savings plan is the same as set on. One other thing counts as a yes, for headless pings only: a consent of enabled saved by an earlier version. An environment variable is never a yes. TOKEN_OPTIMIZER_KEEPWARM_HEADLESS=on, which 5.13.85 and earlier accepted, now does nothing: run keepwarm-decide set on instead.

Your newest choice wins, in session and headless:

  • keepwarm-decide set on is a fresh yes. It clears an earlier decline.
  • keepwarm-decide set off and keepwarm-disable stop both paths and clear an earlier yes.

If an older version saved both a yes and a decline, the decline wins until you choose again.

The off switches in the environment beat any choice:

  • TOKEN_OPTIMIZER_KEEPWARM=off stops both paths.
  • TOKEN_OPTIMIZER_KEEPWARM_HEADLESS=off stops headless pings.

A watcher that is already running reads your choice again before each ping. One started by 5.13.76 through 5.13.85 keeps the old code in memory and stops when its pause ends, at most about two hours, or when you close that session.

A repository’s .claude/token-optimizer.json can turn Keep-Warm off. It cannot turn it on, stand in for the notice, or change the daily limit. A project’s .claude/settings.json can set environment variables for the whole Claude Code process, and Token Optimizer cannot tell those from your own. None of them is a yes, but one that moves the config folder could point at a file the repository carries. Review a repository’s settings before you trust it, as you would its hooks.

keepwarm-enable is paused in this release and changes nothing.

A ping is a cache read of the whole session prefix, a small write of up to 5%, and about 1,000 fresh input tokens, at your model’s price. These limits apply to every automatic path together:

CapLimit
Per pause2 pings
Per session, 24 hours4 pings
Whole installation, 24 hours8 pings
Money, 24 hoursAPI billing: a $3.00 rolling budget unless you raise it (set budget), checked before each ping; an in-flight reply can run past it, after which automatic pings pause for 24 hours. Subscription: plan allowance, not dollars

Subscription pings also need fresh readings of both limits, under 80% of the 5-hour limit and under 90% of the weekly limit. API billing has no such meter, so the caps and the daily dollar limit protect it.

On API billing, or when Token Optimizer cannot tell how a session is billed, a ping goes out only if what pings cost in the last 24 hours plus the whole worst case of the next one fits your limit. The worst case is a missed cache, the full prefix written again for an hour, plus a reply of up to 4,096 tokens. A session too large to rewrite inside the limit is not pinged. Token Optimizer cannot cap a single reply, so an in-flight reply can run past the budget. Paid pings go one at a time: the next waits up to 10 minutes for the bill of the last. A long reply is still counted in full, and automatic pings then pause for 24 hours.

A subscription counts as proven only when Claude Code is signed in with an account, fresh 5-hour and weekly meters exist, and no API key, gateway or cloud provider is set in the environment or in user, project or managed settings. Pings there use plan allowance, not dollars, and the meters above protect it.

The default of $3 comes from a 30-day replay of one heavy user’s history: under the API rule, $3 a day came out ahead and $1 a day forecast a small loss. It is an estimate from one user, not a guarantee. No real ping has been measured yet.

A ping goes out only when all of this is true:

  • The session has a measured one-hour cache and at least 100,000 tokens of prefix.
  • The cache is close to expiry (55 minutes) and has not expired.
  • Your own history has at least 20 comparable pauses, and the chance of a return times the avoided rewrite is at least three times the ping cost.
  • The model has a known price and the session is still paused.
  • The ping fits in what is left of the daily limit.

Nothing pings a subagent or an ended session. The fork runs one turn, disables hooks, blocks permission prompts and is not saved.

PathWhereNeeds
In-sessionClaude Code desktop modthe notice, or keepwarm-decide set on
Desktop fallbackClaude Code desktop modthe notice, or any yes
Terminal watcheran open terminal session on macOS or Linuxthe notice, or any yes; no scheduler needed
Scheduler ticklaunchd (macOS) or systemd (Linux)the notice or any yes, and the scheduler installed

The scheduler is not implemented on Windows.

  • Proof. Each ping must show that it read at least 90% of the prefix and wrote at most 5%. A failed proof stops that session, and stops headless pings for the installation.
  • Tripwire. At least five pings and a negative verified net over seven days stop automatic pings.
  • Ledger. Spend is reserved before the request runs, so a crash cannot hide it. Savings show the signed net: every ping’s cost is deducted, including pings that never led to a return. No forecast enters a savings total.
Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py keepwarm-tick --dry-run # what would be pinged and why, without firing
python3 measure.py keepwarm-scheduler status # install | uninstall | status
python3 measure.py keepwarm-consent-status # billing mode and saved consent
python3 measure.py keepwarm-forecast --days 30 # projection from your own history
python3 measure.py keepwarm-backfill --days 30 # replay over your real history
python3 measure.py keepwarm-report # pings, spend, realized and net
python3 measure.py keepwarm-quota-value # subscription value in quota

keepwarm-scheduler install refuses while Keep-Warm is off or its notice has not been shown. keepwarm-arm is kept for older hooks and does nothing.

On a subscription the plan is flat-rate, so a ping does not save money. The scarce resource is rate-limit quota, and a cold resume spends it. keepwarm-quota-value reports Keep-Warm in that currency.

Terminal window
cd ~/.claude/skills/token-optimizer/scripts
python3 measure.py keepwarm-quota-value --json

The effect on subscription limits is measured separately and has no proven conversion to dollars.

On in Claude Code after the notice, inside the daily limit, for anyone who has not chosen. Reporting commands work either way. keepwarm-backfill reads history and can write its own sidecar file.

The Claude desktop status bar (part of the Token Optimizer plugin) has a Keep warm button. It is separate from automatic Keep-Warm.

Automatic Keep-WarmKeep warm button
Runson its own, after the notice or your yesonly when you click
Billingany planany plan
Costplan limits or API credits per ping, within the caps and the daily limita small amount of your usage per click; it tells you how many tokens it re-read from the cache
After expiryno pingdisappears

The button never fires on its own. See the desktop status bar.

Low. The cost of being wrong is a capped spend that shows in keepwarm-report. If a ping fails you fall back to an ordinary cold resume.