Band above the prompt showing prompt-cache age, hit rate, and a Compact button before the cache expires.

A Claude Code mod that shows how much time is left on the prompt cache, so you can keep a session going (or compact it) before the cache expires.
Desktop app:

Terminal:

Claude Code caches your conversation between requests, for an hour or for five minutes depending on your account (see Which cache length you have). While the cache is warm, each new message reads the conversation back from the cache at a tenth of the normal input price or less, so it is at least 90% cheaper (95% on Opus 5.5).
If you go longer than that without sending anything, the cache expires. Your next message has to write the whole conversation back into the cache, which costs twice the normal input price on the 1-hour cache. That one message costs about 20 times what it would have with a warm cache (40 times on Opus 5.5), and the more context you have built up, the bigger that bill.
This mod shows how long you have before that happens. If you have a long session going and know you'll be away past the hour, press Compact first (in the desktop app, type /compact). The conversation shrinks to a short summary, so the message that starts it up again is cheap.
Prices are from the Claude pricing page, checked 2026-10-02.
The goal is two things: keep the cache from expiring, and keep the hit rate high on each request. Each piece of the row helps with one of them.
How close the cache is to expiring.
| Color | Means | What to do |
|---|---|---|
| Green | Plenty of time | Nothing |
| Yellow | Running low (15 minutes left on the 1-hour cache, 2 minutes on the 5-minute cache) | If you're about to step away, decide now whether to compact |
| Red | About to expire (5 minutes left, or 1 minute on the 5-minute cache) | Send a message to keep the cache, or compact |
How long until the cache expires, counted from the last request Claude Code sent for this conversation. Every request refreshes the cache, so the bar refills to full each time Claude replies. It drains one block every 3 minutes on the 1-hour cache. Remaining blocks take the dot's color, and used blocks turn gray. At zero the label reads expired, and your next message pays the full price described in Why.
Requests made by subagents don't refresh it, since they don't use the main conversation's cache.
The share of the last request's input that was read from the cache instead of processed fresh. Higher is better: cached input costs a tenth of the normal price or less, while fresh input costs full price, or twice that when it's written into the 1-hour cache.
| Hit rate | Usually means |
|---|---|
| 90% to 100% | Normal. Almost the whole conversation came from the cache. |
Low, right after a new session, /clear, or a compact | Expected. Nothing was cached yet, and the next request should be back up near 100%. |
| Near 0% in the middle of a session | The cache was lost. Either it expired, or something invalidated it: switching models, connecting or removing an MCP server, or a Claude Code upgrade. See Actions that invalidate the cache. |
It only describes the last request. It says nothing about time left; the countdown covers that.
How many tokens the last request sent, which is the size of the conversation so far (for example 142k ctx). It turns yellow past 200k. That is a rule of thumb, not a hard limit: answers tend to get less focused as context grows, so past this point it is worth compacting or starting fresh. It turns red at 80% of the model's context window, near where Claude Code auto-compacts.
Runs the same thing as /compact. It replaces the conversation with a short summary, so the next request only has to cache that summary instead of the whole history. Use it when the dot is yellow or red and you know you'll be away past the cache length. Compacting while the cache is still warm is cheap, because the summarizing request reads the conversation from the cache. Compacting after it expires costs a full uncached read of the history.
The row hides after any compact (the button, /compact, or an automatic one) and comes back with the next reply. If Claude is mid-reply, the button waits and compacts as soon as the reply finishes.
The button shows only when Claude Code runs in a terminal. The desktop app and other SDK hosts can't compact from a mod, so there the row has no button. In its place, a dim type /compact hint appears once the dot turns yellow or red.
Appears once when the dot turns red: "Cache expires in ~5m. Compact or send something." (~1m on the 5-minute cache). In the desktop app it says "Type /compact or send something." instead. It shows once per idle stretch and resets with the next request.
From How Claude Code uses prompt caching, checked 2026-10-02:
| How you use Claude Code | Main conversation cache |
|---|---|
| Claude subscription, within your plan's included usage | 1 hour |
| Claude subscription after you go over your plan's limit and draw on usage credits | 5 minutes |
| API key | 5 minutes |
| Amazon Bedrock, Google Cloud, or Microsoft Foundry | 5 minutes |
You can override the default with the promptCacheTtl setting ("5m" or "1h") in ~/.claude/settings.json, or the CLAUDE_CODE_PROMPT_CACHE_TTL environment variable. Both need Claude Code v2.1.242 or later. FORCE_PROMPT_CACHING_5M=1 forces five minutes, and ENABLE_PROMPT_CACHING_1H=1 asks for an hour.
If you're on the 5-minute cache, set cache-buster's cache length to 5 (see Notes). The mod can't detect which one you have, so it won't notice if a subscription switches to 5 minutes partway through a session because you went over your plan's limit.
To check which one your sessions use, run this and look at usage.cache_creation. Tokens under ephemeral_1h_input_tokens mean the 1-hour cache, and tokens under ephemeral_5m_input_tokens mean the 5-minute cache.
claude -p "hello" --output-format json
Run these in Claude Code:
/plugin marketplace add dblanken-yale/cache-buster
/plugin install cache-buster@cache-buster
Or from a terminal:
claude plugin marketplace add dblanken-yale/cache-buster
claude plugin install cache-buster@cache-buster
Start a new Claude Code session, in the terminal or the desktop app. The row appears above the prompt after the first reply.
Turn on auto-update for the cache-buster marketplace in /plugin (Marketplaces tab), and new versions install when Claude Code starts. To update by hand:
claude plugin marketplace update cache-buster
Desktop app sessions pick up the new version when you start a new one.
Clone the repo and load it from the folder, so edits reload as you save:
git clone git@github.com:dblanken-yale/cache-buster.git ~/code/cache-buster
claude --plugin-dir ~/code/cache-buster
To load it in every session, add the folder to CLAUDE_CODE_PLUGIN_DIRS in the env block of ~/.claude/settings.json (folders separated by :). Don't also install it from the marketplace, or it loads twice.
Bump version in .claude-plugin/plugin.json with every release. Installed copies only update when the version changes.
~/.claude/settings.json: { "pluginConfigs": { "cache-buster": { "options": { "cacheMinutes": "5" } } } }
The display updates once a minute, so the 5-minute cache is coarse.
next(e). cache-buster calls next(e), gets back whatever the mods beneath drew, and stacks it under its own bar in a column (hooks/register.tsx, the AbovePrompt hook). Before this, it returned only its own bar, which hid any other mod's row once the first reply came in. A mod that draws in this row should do the same: const below = await next(e)
return (
<Box flexDirection="column">
<Box>{/* this mod's row */}</Box>
{below}
</Box>
)
When there's nothing to show, call return next(e) instead, as the hook already does before the first reply.
claude plugin validate ~/code/cache-buster and claude plugin test ~/code/cache-buster.tsconfig.json points at .claude-plugin/types/, which Claude Code generates and git ignores, so type-checking a fresh clone needs those files regenerated first.hooks/register.tsx 160 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4const CELLS = 20
5// Past this many tokens of context, models tend to lose focus.
6const CONTEXT_WARN = 200_000
7// Red at this fraction of the model's context window: close to auto-compact.
8// ponytail: 80% of the window approximates the auto-compact point; the exact threshold is only
9// in $.session.usage({ breakdown: 'summary' }) (rawMaxTokens), if precision ever matters.
10const CONTEXT_ALARM = 0.8
11
12const lastAt = atom({ plugin: 'cache-buster', key: 'lastAt' } as const, null)
13const hitRate = atom({ plugin: 'cache-buster', key: 'hitRate' } as const, 0)
14const context = atom({ plugin: 'cache-buster', key: 'context' } as const, 0)
15const window = atom({ plugin: 'cache-buster', key: 'window' } as const, 0)
16const now = atom({ plugin: 'cache-buster', key: 'now' } as const, 0)
17
18let warned = false
19
20// Set when Compact is pressed mid-turn; the compact runs at the next turn.complete.
21let pending = false
22
23// $.session.compact() rejects in a headless session (-p, the SDK, the desktop app), so the
24// Compact button shows only under the terminal REPL; elsewhere the row hints at /compact.
25let interactive = false
26
27async function reset($: EngineInterface) {
28 warned = false
29 pending = false
30 await update($, lastAt, () => null)
31}
32
33// The engine refuses to compact while a turn runs, so hold it for the end of the turn.
34function queue($: EngineInterface) {
35 if (!pending) $.ui.toast('Will compact when this reply finishes.')
36 pending = true
37}
38
39async function compact($: EngineInterface) {
40 try {
41 const r = await $.session.compact()
42 pending = false
43 if (r.skip) $.ui.toast(`Compact skipped: ${r.skip}`)
44 } catch (err) {
45 const msg = err instanceof Error ? err.message : String(err)
46 if (msg.includes('a turn is running')) return queue($)
47 pending = false
48 $.ui.toast(msg)
49 }
50}
51
52export const register: Register = (on, options) => {
53 const ttl = Number(options.cacheMinutes) || 60
54 const warn = Math.max(1, Math.round(ttl / 12))
55 const caution = Math.max(warn + 1, ttl / 4)
56
57 on('session.start', async ($, e, next) => {
58 interactive = e.isInteractive
59 const started = await next(e)
60 const t0 = await $.clock.now()
61 await update($, now, () => t0)
62 $.clock.every(60_000, async () => {
63 const t = await $.clock.now()
64 await update($, now, () => t)
65 const at = await read($, lastAt)
66 if (at !== null && !warned && ttl - (t - at) / 60_000 <= warn) {
67 warned = true
68 $.ui.toast(`Cache expires in ~${warn}m. ${interactive ? 'Compact' : 'Type /compact'} or send something.`)
69 }
70 })
71 return started
72 })
73
74 on('session.end', async ($, e, next) => {
75 if (e.reason === 'clear') await reset($)
76 return next(e)
77 })
78
79 on('session.compact', async ($, e, next) => {
80 const r = await next(e)
81 if (!e.agentId && e.trigger !== 'precompute' && !r.skip) await reset($)
82 return r
83 })
84
85 on('turn.complete', async ($, e, next) => {
86 const r = await next(e)
87 if (pending && !e.agentId) void compact($)
88 return r
89 })
90
91 on('turn.step', async function* ($, e, next) {
92 const r = yield* next(e)
93 if (e.agentId || !r.usage) return r
94
95 const u = r.usage
96 const total = u.input_tokens + u.cache_read_input_tokens + u.cache_creation_input_tokens
97 const t = await $.clock.now()
98 warned = false
99 await update($, lastAt, () => t)
100 await update($, now, () => t)
101 await update($, hitRate, () => (total ? u.cache_read_input_tokens / total : 0))
102 await update($, context, () => total)
103 const { context: c } = await $.session.usage()
104 await update($, window, () => c.window)
105 return r
106 })
107
108 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
109 const at = await read($, lastAt)
110 if (e.props.hasSurvey || at === null) return next(e)
111
112 const [t, hit, ctx, win] = await Promise.all([
113 read($, now),
114 read($, hitRate),
115 read($, context),
116 read($, window),
117 ])
118 const ageMin = Math.max(0, Math.floor((t - at) / 60_000))
119 const leftMin = Math.max(0, ttl - ageMin)
120 const filled = Math.round((leftMin / ttl) * CELLS)
121 const color = leftMin <= warn ? 'red' : leftMin <= caution ? 'yellow' : 'green'
122 const ctxColor = win && ctx >= win * CONTEXT_ALARM ? 'red' : ctx > CONTEXT_WARN ? 'yellow' : undefined
123 const rate = Math.round(hit * 100)
124 const { Box, Button, Text } = $.ui.resolve(e)
125 // Stack whatever the bands beneath draw (other mods), instead of hiding it.
126 const below = await next(e)
127
128 return (
129 <Box flexDirection="column">
130 <Box>
131 <Text color={color}>● </Text>
132 <Text dimColor>cache </Text>
133 <Text color={color}>{leftMin === 0 ? 'expired' : `${leftMin}m left`} </Text>
134 <Box gap={1}>
135 {Array.from({ length: CELLS }, (_, i) => (
136 <Text key={`cell${i}`} backgroundColor={i < filled ? color : 'gray'}>
137 {' '}
138 </Text>
139 ))}
140 </Box>
141 <Text dimColor> {rate}% hit </Text>
142 <Text color={ctxColor} dimColor={!ctxColor}>
143 {Math.round(ctx / 1000)}k ctx{' '}
144 </Text>
145 {interactive ? (
146 <Button
147 key="compact"
148 label="Compact"
149 onPress={() => (e.props.isWorking ? queue($) : compact($))}
150 />
151 ) : (
152 color !== 'green' && <Text dimColor>type /compact</Text>
153 )}
154 </Box>
155 {below}
156 </Box>
157 )
158 })
159}
160types/index.d.ts 17 lines1declare module 'claude-code' {
2 interface PluginState {
3 'cache-buster': {
4 /** Epoch ms of the last main-thread request; null before the first. */
5 lastAt: number | null
6 /** Cache hit rate of that request, 0 to 1. */
7 hitRate: number
8 /** Input tokens of that request: the conversation's context size. */
9 context: number
10 /** The model's context window in tokens, read after each request; 0 before the first. */
11 window: number
12 /** Epoch ms, refreshed every minute so the band redraws. */
13 now: number
14 }
15 }
16}
17