Context window forecast plus 5h/7d rate-limit usage with reset countdowns, drawn above the prompt.

Claude Code mods (Claude Code ≥ 2.1.287), packaged as a plugin marketplace named salik-mods.

Band above the prompt: context window forecast, plus 5h/7d rate-limit meters with a pace icon, reset countdown, and an "out ~Xm" projection when usage is on track to run out before reset. Toasts at 80% and 90%. Nerd Font icons by default; set the icons option to plain otherwise.
Reads only what Claude Code already has ($.session.usage(), session.measure); makes no API calls.
Based on token-weather (Apache-2.0).
From GitHub:
claude plugin marketplace add imsalik/claude-mods
claude plugin install usage-weather@salik-mods --scope user
Or live from a clone, so edits hot-reload. Clone anywhere, then point the env block of ~/.claude/settings.json at the mod folder:
git clone https://github.com/imsalik/claude-mods.git <clone-dir>
"CLAUDE_CODE_PLUGIN_DIRS": "<clone-dir>/usage-weather"
Use one, not both.
cd usage-weather
claude plugin validate .
claude plugin test .hooks/register.tsx 225 lines1// Usage Weather: context forecast and rate-limit windows, above the prompt.
2// Based on token-weather from anthropics/claude-code-playground (Apache-2.0).
3
4import type { EngineInterface, Register, SessionContextUsage, SessionRateLimit } from 'claude-code'
5
6type Reading = { tokens: number; window: number; percent: number }
7type IconSet = typeof ICONS.nerd
8type Pace = 'cool' | 'steady' | 'hot'
9
10const HISTORY = 12
11const BARS = '▁▂▃▄▅▆▇█'
12const EIGHTHS = '▏▎▍▌▋▊▉'
13const TRACK = 'subtle'
14const TOAST_AT = [80, 90]
15const HOUR = 3_600_000
16const WINDOW_MS: Record<string, number> = { five_hour: 5 * HOUR, seven_day: 168 * HOUR }
17const LIMIT_LABEL: Record<string, string> = { five_hour: '5h', seven_day: '7d', spend_limit: '$' }
18
19const ICONS = {
20 nerd: {
21 forecast: ['\u{F0599}', '\u{F0590}', '\u{F0596}', '\u{F0593}', '\u{F0898}'],
22 limit: { five_hour: '\u{F0150}', seven_day: '\u{F0A33}' } as Record<string, string>,
23 limitDefault: '\u{F029A}',
24 pace: { cool: '\u{F0CD7}', steady: '\u{F0F85}', hot: '\u{F0238}' },
25 reset: '\u{F051F}',
26 empty: '\u{F0083}',
27 },
28 plain: {
29 forecast: ['☀', '☁', '☂', '☇', '↯'],
30 limit: { five_hour: '◷', seven_day: '▦' } as Record<string, string>,
31 limitDefault: '◈',
32 pace: { cool: '◡', steady: '•', hot: '▲' },
33 reset: '↻',
34 empty: '!',
35 },
36}
37
38const FORECAST = [
39 { upTo: 25, word: 'Clear', color: 'yellow' },
40 { upTo: 50, word: 'Cloudy', color: 'cyan' },
41 { upTo: 75, word: 'Showers', color: 'blue' },
42 { upTo: 90, word: 'Storm', color: 'magenta' },
43 { upTo: Infinity, word: 'Compact soon', color: 'red' },
44] as const
45
46const PACE_COLOR: Record<Pace, string> = { cool: 'green', steady: 'yellow', hot: 'red' }
47
48let readings: Reading[] = []
49let limits: SessionRateLimit[] = []
50let toasted = new Set<string>()
51let hasSeeded = false
52let tick: { cancel: () => void } | undefined
53
54export const register: Register = (on, options) => {
55 const icons: IconSet = options.icons === 'plain' ? ICONS.plain : ICONS.nerd
56
57 on('session.start', async ($, e, next) => {
58 const result = await next(e)
59 readings = []
60 limits = []
61 toasted = new Set()
62 hasSeeded = false
63 tick?.cancel()
64 tick = $.clock.every(60_000, () => $.ui.invalidate('ui.render'))
65 await seed($)
66 return result
67 })
68
69 on('session.measure', async ($, e, next) => {
70 const result = await next(e)
71 if (e.changed.includes('context')) addReading(e.context)
72 if (e.changed.includes('rateLimits')) {
73 limits = e.rateLimits
74 warn($)
75 }
76 hasSeeded = true
77 $.ui.invalidate('ui.render')
78 return result
79 })
80
81 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
82 if (e.props.hasSurvey || (readings.length === 0 && limits.length === 0)) return next(e)
83 const { Box, Text } = $.ui.resolve(e)
84 const now = await $.clock.now()
85 const cols = e.props.bodyColumns
86 const gaugeCells = cols >= 80 ? 5 : 0
87 const last = readings[readings.length - 1]
88 const fi = last ? forecastIndex(last.percent) : 0
89 const f = FORECAST[fi] ?? FORECAST[0]
90 const trend = trendText()
91
92 return (
93 <Box flexDirection="row" paddingX={1}>
94 {last && (
95 <Box flexDirection="row">
96 <Text color={f.color} bold>{`${icons.forecast[fi]} ${f.word}`}</Text>
97 <Text>{` ${last.percent}% ctx`}</Text>
98 {cols >= 60 && <Text dimColor>{` ${short(last.tokens)}/${short(last.window)}`}</Text>}
99 {cols >= 100 && readings.length > 1 && <Text color={f.color}>{` ${chart()}`}</Text>}
100 {cols >= 100 && trend && <Text dimColor>{` ${trend}`}</Text>}
101 </Box>
102 )}
103 {limits.map((l, i) => {
104 const w = windowState(l, now)
105 const color = pctColor(l.percentUsed)
106 const g = gaugeCells > 0 ? gauge(l.percentUsed, gaugeCells) : undefined
107 return (
108 <Box key={l.kind} flexDirection="row">
109 {(last || i > 0) && <Text dimColor>{' │ '}</Text>}
110 <Text color={color}>{`${icons.limit[l.kind] ?? icons.limitDefault} `}</Text>
111 {g && <Text color={color}>{g.used}</Text>}
112 {g?.part && <Text color={color} backgroundColor={TRACK}>{g.part}</Text>}
113 {g?.rest && <Text backgroundColor={TRACK}>{g.rest}</Text>}
114 {g && <Text>{' '}</Text>}
115 <Text color={color} bold>{`${Math.round(l.percentUsed)}%`}</Text>
116 {w.pace && <Text color={PACE_COLOR[w.pace]}>{` ${icons.pace[w.pace]}`}</Text>}
117 {w.emptyInMs !== undefined ? (
118 <Text color="red">{` ${icons.empty} out ~${fmtDuration(w.emptyInMs)}`}</Text>
119 ) : (
120 w.resetInMs > 0 && <Text dimColor>{` ${icons.reset} ${fmtDuration(w.resetInMs)}`}</Text>
121 )}
122 </Box>
123 )
124 })}
125 </Box>
126 )
127 })
128}
129
130async function seed($: EngineInterface) {
131 try {
132 const usage = await $.session.usage()
133 addReading(usage.context)
134 limits = usage.rateLimits
135 for (const l of limits) for (const at of TOAST_AT) if (l.percentUsed >= at) toasted.add(toastKey(l, at))
136 $.ui.invalidate('ui.render')
137 } catch {
138 // No reading yet; the first session.measure fills it.
139 }
140}
141
142function warn($: EngineInterface) {
143 for (const l of limits) {
144 for (const at of TOAST_AT) {
145 const key = toastKey(l, at)
146 if (l.percentUsed < at || toasted.has(key)) continue
147 toasted.add(key)
148 if (hasSeeded) $.ui.toast(`${LIMIT_LABEL[l.kind] ?? l.kind} usage at ${Math.round(l.percentUsed)}%`, { timeoutMs: 8000 })
149 }
150 }
151}
152
153function toastKey(l: SessionRateLimit, at: number) {
154 return `${l.kind}:${l.resetsAt ?? ''}:${at}`
155}
156
157/** Elapsed share of the window, pace against it, and when usage hits 100% if that beats the reset. */
158function windowState(l: SessionRateLimit, now: number) {
159 const resetInMs = l.resetsAt ? Date.parse(l.resetsAt) - now : 0
160 const span = WINDOW_MS[l.kind]
161 if (!span || !(resetInMs > 0)) return { resetInMs, elapsed: undefined, pace: undefined, emptyInMs: undefined }
162 const elapsedMs = Math.max(0, span - resetInMs)
163 const elapsed = Math.min(1, elapsedMs / span)
164 if (elapsed < 0.05 || l.percentUsed <= 0) return { resetInMs, elapsed, pace: undefined, emptyInMs: undefined }
165 const ratio = l.percentUsed / 100 / elapsed
166 const pace: Pace = ratio > 1.25 ? 'hot' : ratio < 0.75 ? 'cool' : 'steady'
167 const toFull = l.percentUsed < 100 ? ((100 - l.percentUsed) / l.percentUsed) * elapsedMs : 0
168 const emptyInMs = ratio > 1 && toFull < resetInMs ? toFull : undefined
169 return { resetInMs, elapsed, pace, emptyInMs }
170}
171
172/** Block meter of `cells` cells at eighth-cell resolution; any usage fills at least one eighth. */
173function gauge(pct: number, cells: number) {
174 const p = Math.min(100, Math.max(0, pct))
175 const eighths = p > 0 ? Math.max(1, Math.round((p / 100) * cells * 8)) : 0
176 const full = Math.floor(eighths / 8)
177 const part = eighths % 8 ? EIGHTHS[(eighths % 8) - 1] : ''
178 return { used: '█'.repeat(full), part, rest: ' '.repeat(cells - full - (part ? 1 : 0)) }
179}
180
181function addReading(context: SessionContextUsage) {
182 if (!context.window || !context.tokens) return
183 const percent = Math.round(context.percent ?? (context.tokens / context.window) * 100)
184 readings = [...readings, { tokens: context.tokens, window: context.window, percent }].slice(-HISTORY)
185}
186
187function forecastIndex(percent: number) {
188 const i = FORECAST.findIndex(b => percent < b.upTo)
189 return i === -1 ? FORECAST.length - 1 : i
190}
191
192function chart() {
193 const top = Math.max(...readings.map(r => r.tokens), 1)
194 return readings.map(r => BARS[Math.min(BARS.length - 1, Math.floor((r.tokens / top) * (BARS.length - 1)))]).join('')
195}
196
197function trendText() {
198 const [prev, cur] = readings.slice(-2)
199 if (!prev || !cur) return ''
200 const delta = cur.tokens - prev.tokens
201 if (delta > 0) return `▲ +${short(delta)}`
202 if (delta < 0) return `▼ ${short(-delta)}`
203 return ''
204}
205
206function pctColor(p: number) {
207 return p >= 80 ? 'red' : p >= 50 ? 'yellow' : 'green'
208}
209
210function fmtDuration(ms: number) {
211 const s = Math.floor(ms / 1000)
212 const d = Math.floor(s / 86400)
213 const h = Math.floor((s % 86400) / 3600)
214 const m = Math.floor((s % 3600) / 60)
215 if (d > 0) return `${d}d${h}h`
216 if (h > 0) return `${h}h${String(m).padStart(2, '0')}m`
217 return `${m}m`
218}
219
220function short(n: number) {
221 if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n % 1_000_000 === 0 ? 0 : 1)}M`
222 if (n >= 1_000) return `${(n / 1_000).toFixed(n % 1_000 === 0 ? 0 : 1)}k`
223 return String(n)
224}
225