Cold Cache Detection - patrickbykov/claude-telemetry-widget GitHub Wiki
Cold-cache detection
TL;DR: A "cold restart" is a request that rewrote almost the whole context to the cache when it should have read it from the cache. The widget counts these and estimates the money they wasted. (H)
The rule
A main-thread request is cold when all 6 checks pass. Each check compares it with the previous main-thread request in the same session.
| # | Check | Why |
|---|---|---|
| 1 | Not a subagent | Subagents have their own cache |
| 2 | Same session | Needs a previous request to compare with |
| 3 | ctx > 20,000 |
Small contexts aren't worth flagging |
| 4 | cr < 10% of ctx |
Almost nothing came from the cache |
| 5 | Same model | A model switch rewrites legitimately |
| 6 | ctx >= 80% of previous ctx |
About the same size, so not a /clear or /compact |
Checks 5 and 6 separate "the cache expired" from "you started over on purpose".
Overspend
over = write cost − cost of reading the same tokens from the cache
= (c5 × 1.25 + c1 × 2.0) × price_in − (c5 + c1) × price_read
Worked example
Opus 5.5 (in $4, read $0.20). The previous request had 150k context. This request:
| Value | |
|---|---|
| ctx | 160,000 ✅ > 20k, ✅ ≥ 120k (80% of 150k) |
| cr | 5,000 ✅ < 16,000 (10% of 160k) |
| c1 | 153,000 |
write = 153,000 × 2.0 × 4 / 1M = $1.224
read = 153,000 × 0.20 / 1M = $0.031
over = $1.224 − $0.031 = $1.19
Replying within the TTL would have saved $1.19 on that single request.
When it's flagged
| Where | Trigger |
|---|---|
| Menu "Today" warning | ≥ 3 cold restarts today (warn_cold_restarts_at_least) |
| Session report | Any cold restart. Severity is "med" if the total overspend is above $5 |
What to do: reply before the TTL runs out, or run /compact before you step away.
Next: Menu advice →