A live band above the Claude Code prompt: model, context, 5-hour and weekly plan limits, real prompt-cache status and session cost, plus a one-click Handoff.

A live status band above the Claude Code prompt. It shows what you're spending and how close you are to your limits while you work, without running /cost or /context.

Works in the terminal and in the Claude desktop app's Code tab.
| Segment | Example | Meaning |
|---|---|---|
| Model | Sonnet 5.5 | The model the session is on. |
| Context | ███░░░░░░░ 3% 32.3k/1M | How full the context window is. Green, then amber from 50%, red from 80%. |
| 5-hour limit | 5h 9% 11m | Your plan's 5-hour usage window and the time until it resets. |
| Weekly limit | 7d 32% 3d 4h | Your plan's weekly usage window and the time until it resets. |
| Prompt cache | ⏳ 59m 70% hit | Time left before the prompt cache expires, and how much of the last request came from cache. See below. |
| Cost | 💰 $0.13 | What the session would cost at API prices. |
| Button | Handoff | Has Haiku write a handoff summary, runs /clear, and puts the summary in the prompt box of the fresh session. |
Every message re-sends the whole conversation. Anthropic caches it, so while the cache is warm each message is faster and much cheaper; once it expires, the next message pays full price to rebuild it. Every request resets the timer.
The band reads this from the API's own usage data in the session transcript, not from a guess:
1h or 5m).cold, new model appears after switching models: each model has its own cache.5m TTL appears if the API fell back to the 5-minute cache.claude plugin marketplace add Rishit30G/usage-band
claude plugin install usage-band@rishit-plugins
Then start a new session (or restart the app).
claude plugin marketplace update rishit-plugins
claude plugin update usage-band@rishit-plugins
claude plugin uninstall usage-band@rishit-plugins
claude plugin marketplace remove rishit-plugins
ui.render, $.session.usage). Older versions won't load it.sh, tail and grep. On Windows that segment stays hidden; the rest works.MIT
hooks/register.tsx 284 lines1import { atom, read, update } from 'claude-code'
2import type { Register } from 'claude-code'
3
4import type { Cache, Snap } from '../types'
5
6const snap = atom({ plugin: 'usage-band', key: 'snap' } as const, null)
7
8const TTL_MS = { '5m': 5 * 60 * 1000, '1h': 60 * 60 * 1000 }
9const CTX_WARN = 50
10const CTX_CRIT = 80
11const LIM_WARN = 60
12const LIM_CRIT = 85
13const LABEL: Record<string, string> = { five_hour: '5h', seven_day: '7d', spend_limit: 'spend' }
14
15// claude-sonnet-5-5 -> Sonnet 5.5; claude-haiku-4-5-20251001 -> Haiku 4.5; unknown ids pass through
16const modelName = (id: string) => {
17 const m = id.match(/^claude-(opus|sonnet|haiku|fable)-(\d+)(?:-(\d{1,2}))?(?:-\d{8})?(\[.*\])?$/)
18 if (!m) return id
19 const [, fam, major, minor, suffix] = m
20 return `${fam[0].toUpperCase()}${fam.slice(1)} ${major}${minor ? `.${minor}` : ''}${suffix ?? ''}`
21}
22
23// one hue per segment so the band reads at a glance; green/amber/red are reserved for severity
24const C = {
25 claude: '#D97757',
26 sky: '#7cc4ff',
27 amber: '#ffb454',
28 teal: '#4fd1c5',
29 gold: '#f6d365',
30 rose: '#ff8fab',
31 green: '#7ee787',
32 red: '#ff6b6b',
33 muted: '#8b93a7',
34 line: '#4b5266',
35}
36
37const level = (pct: number, warn: number, crit: number) =>
38 pct >= crit ? C.red : pct >= warn ? C.amber : C.green
39
40const tok = (n: number) =>
41 n >= 1e6 ? `${+(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${+(n / 1e3).toFixed(1)}k` : `${Math.round(n)}`
42
43const dur = (sec: number) => {
44 const s = Math.max(0, Math.floor(sec))
45 const d = Math.floor(s / 86400)
46 const h = Math.floor((s % 86400) / 3600)
47 const m = Math.floor((s % 3600) / 60)
48 return d ? `${d}d ${h}h` : h ? `${h}h ${m}m` : m ? `${m}m` : `${s}s`
49}
50
51const clock = (sec: number) => {
52 const s = Math.max(0, Math.floor(sec))
53 if (s >= 600) return dur(s)
54 return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`
55}
56
57const bar = (pct: number, width = 10) => {
58 const n = Math.round((Math.min(100, Math.max(0, pct)) / 100) * width)
59 return '█'.repeat(n) + '░'.repeat(width - n)
60}
61
62// The plugin API doesn't report the prompt cache, but every API response in the
63// transcript does: when it was made, which model, the TTL it wrote and what it read.
64async function readCache($: any, prev: Cache | null): Promise<Cache | null> {
65 const id = await $.session.id()
66 if (!/^[0-9a-f-]{36}$/.test(id)) return prev
67 const r = await $.process.run([
68 'sh',
69 '-c',
70 `tail -n 400 "$HOME"/.claude/projects/*/${id}.jsonl 2>/dev/null | grep '"cache_creation"' | tail -n 30`,
71 ])
72 let last: any = null
73 let ttlMs: number | null = null
74 for (const line of r.stdout.split('\n').reverse()) {
75 let d: any
76 try {
77 d = JSON.parse(line)
78 } catch {
79 continue
80 }
81 const u = d?.message?.usage
82 if (d.type !== 'assistant' || d.isSidechain || !u) continue
83 last ??= d
84 // a pure cache hit writes nothing, so the TTL comes from the latest response that wrote
85 const cc = u.cache_creation ?? {}
86 if (cc.ephemeral_1h_input_tokens > 0) ttlMs = TTL_MS['1h']
87 else if (cc.ephemeral_5m_input_tokens > 0) ttlMs = TTL_MS['5m']
88 if (ttlMs !== null) break
89 }
90 if (!last) return prev
91 const u = last.message.usage
92 const read = u.cache_read_input_tokens ?? 0
93 const total = (u.input_tokens ?? 0) + read + (u.cache_creation_input_tokens ?? 0)
94 return {
95 at: Date.parse(last.timestamp),
96 ttlMs: ttlMs ?? prev?.ttlMs ?? TTL_MS['1h'],
97 model: last.message.model,
98 hitPct: total ? (read / total) * 100 : 0,
99 }
100}
101
102async function refresh($: any) {
103 try {
104 const u = await $.session.usage()
105 const prev = await read($, snap)
106 const now = await $.clock.now()
107 let model: string | null = null
108 try {
109 model = await $.session.model()
110 } catch {}
111 let cache = prev?.cache ?? null
112 try {
113 cache = await readCache($, cache)
114 } catch {}
115 const next: Snap = {
116 at: now,
117 model,
118 cache,
119 startedAt: u.startedAt,
120 ctxPercent: u.context.percent ?? null,
121 ctxTokens: u.context.tokens ?? null,
122 ctxWindow: u.context.window,
123 usd: u.cost?.usd ?? null,
124 limits: u.rateLimits,
125 }
126 await update($, snap, () => next)
127 } catch {
128 // session not bound yet; the next tick tries again
129 }
130}
131
132async function tick($: any) {
133 try {
134 const prev = await read($, snap)
135 if (!prev?.cache) return
136 if (prev.cache.at + prev.cache.ttlMs - prev.at < -1000) return // already expired, nothing moves
137 const now = await $.clock.now()
138 await update($, snap, (cur: any) => (cur ? { ...cur, at: now } : cur))
139 } catch {}
140}
141
142let isBusy = false
143
144async function handoff($: any) {
145 if (isBusy) return
146 isBusy = true
147 try {
148 $.ui.toast('Writing handoff…')
149 const msgs = await $.session.messages()
150 const transcript = msgs
151 .map((m: any) => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.text}`)
152 .filter((t: string) => t.length > 12)
153 .join('\n\n')
154 .slice(-60000)
155 if (!transcript) {
156 $.ui.toast('Nothing to hand off yet')
157 return
158 }
159 const r = await $.model.complete({
160 model: 'haiku',
161 maxTokens: 1500,
162 timeoutMs: 90000,
163 system: 'You write concise hand-off notes so a fresh coding session can continue seamlessly.',
164 prompt:
165 'Summarize this session as a hand-off: goal, what was done (files, decisions), current state, open issues, and next steps. Be specific and brief.\n\n' +
166 transcript,
167 })
168 if (!r.isAnswered) {
169 $.ui.toast('Handoff failed; session kept')
170 return
171 }
172 await $.command.run({ command: 'clear' })
173 await $.prompt.fill({
174 text: `Handoff from my previous session:\n\n${r.text}\n\nContinue from here.`,
175 })
176 $.ui.toast('New session started. Handoff is in the prompt box; press Enter to send.')
177 } catch {
178 $.ui.toast('Handoff failed; session kept')
179 } finally {
180 isBusy = false
181 }
182}
183
184export const register: Register = on => {
185 let stopFull: (() => void) | undefined
186 let stopTick: (() => void) | undefined
187
188 on('session.start', async ($, e, next) => {
189 stopFull?.()
190 stopTick?.()
191 stopFull = $.clock.every(10000, () => refresh($))
192 // cheap 1s tick so the cache countdown moves between full refreshes
193 stopTick = $.clock.every(1000, () => tick($))
194 await refresh($)
195 return next(e)
196 })
197
198 on('turn.complete', async ($, e, next) => {
199 const r = await next(e)
200 await refresh($)
201 return r
202 })
203
204 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
205 const s = await read($, snap)
206 if (e.props.hasSurvey || s === null) return next(e)
207
208 const { Box, Button, Text } = $.ui.resolve(e)
209 const sep = <Text> </Text>
210 const parts: any[] = []
211
212 if (s.model) {
213 parts.push(
214 <Text color={C.claude} bold>{modelName(s.model)}</Text>,
215 )
216 }
217
218 if (s.ctxPercent !== null) {
219 const c = level(s.ctxPercent, CTX_WARN, CTX_CRIT)
220 parts.push(
221 <Text>
222 <Text color={c}>{bar(s.ctxPercent)}</Text>
223 <Text color={c} bold> {Math.round(s.ctxPercent)}%</Text>
224 <Text color={C.muted}> {tok(s.ctxTokens ?? 0)}/{tok(s.ctxWindow)}</Text>
225 </Text>,
226 )
227 }
228
229 for (const l of s.limits) {
230 const left = l.resetsAt ? Math.max(0, (Date.parse(l.resetsAt) - s.at) / 1000) : null
231 const c = level(l.percentUsed, LIM_WARN, LIM_CRIT)
232 parts.push(
233 <Text>
234 <Text color={C.amber}>{LABEL[l.kind] ?? l.kind} </Text>
235 <Text color={c} bold>{Math.round(l.percentUsed)}%</Text>
236 {left !== null ? <Text color={C.muted}> {dur(left)}</Text> : null}
237 </Text>,
238 )
239 }
240
241 if (s.cache) {
242 const c = s.cache
243 const left = (c.at + c.ttlMs - s.at) / 1000
244 // each model has its own cache: after a switch the next request starts cold
245 const switched = !!s.model && modelName(s.model) !== modelName(c.model)
246 const hitColor = c.hitPct >= 80 ? C.green : c.hitPct >= 40 ? C.amber : C.red
247 parts.push(
248 <Text>
249 <Text color={C.teal}>⏳ </Text>
250 {e.props.isWorking ? (
251 <Text color={C.green} bold>warm</Text>
252 ) : switched ? (
253 <Text color={C.amber} bold>cold, new model</Text>
254 ) : left > 0 ? (
255 <Text color={left < 300 ? C.amber : C.green} bold>{clock(left)}</Text>
256 ) : (
257 <Text color={C.muted}>expired</Text>
258 )}
259 <Text color={hitColor}> {Math.round(c.hitPct)}% hit</Text>
260 {c.ttlMs === TTL_MS['5m'] ? <Text color={C.amber}> 5m TTL</Text> : null}
261 </Text>,
262 )
263 }
264
265 if (s.usd !== null) {
266 parts.push(
267 <Text>
268 <Text>💰 </Text>
269 <Text color={C.gold} bold>${s.usd.toFixed(2)}</Text>
270 </Text>,
271 )
272 }
273
274 if (!parts.length) return next(e)
275
276 return (
277 <Box justifyContent="space-between">
278 <Text>{parts.flatMap((p, i) => (i ? [sep, p] : [p]))}</Text>
279 <Button key="handoff" label="Handoff" variant="primary" onPress={() => handoff($)} />
280 </Box>
281 )
282 })
283}
284types/index.d.ts 21 lines1export type Limit = { kind: string; percentUsed: number; resetsAt?: string }
2// the last main-thread API response, read from the session's transcript
3export type Cache = { at: number; ttlMs: number; model: string; hitPct: number }
4export type Snap = {
5 at: number
6 model: string | null
7 cache: Cache | null
8 startedAt: number
9 ctxPercent: number | null
10 ctxTokens: number | null
11 ctxWindow: number
12 usd: number | null
13 limits: Limit[]
14}
15
16declare module 'claude-code' {
17 interface PluginState {
18 'usage-band': { snap: Snap | null }
19 }
20}
21