Your subscription usage at the bottom right of Claude Code: the 5-hour and weekly windows, taking turns, side by side or fixed on one of them.

A Claude Code mod: your subscription usage, always at the bottom right, on the same line as the permission mode.
⏵⏵ auto mode on 5h ━━━━━━──── 58% ↻ 2h 10m
By default it switches between the 5-hour window and the weekly one every 8 seconds (rotateSeconds in /config). Set display there to change what it shows: rotate (the default), both (the two windows side by side, separated by |), session (only the 5-hour window) or week (only the weekly one). With a single reading available, every mode shows it. The bar turns yellow from 75% and red from 90%. After it, behind ↻, the time until that window resets.
Every open session shares the latest reading, so a window you are not using catches up within 8 seconds. It only sees what some Claude Code session measures: usage elsewhere (claude.ai, the mobile app) shows up at the next response.
Where the footer is short it fits the row instead of breaking to a second line: first the bar goes, then the reset time, and in a very narrow terminal the meter itself. Beside Narrator, the meter shrinks first, then the switch.
⏵⏵ auto mode on · 5h 58% ↻ 2h 10m · ⏵ narrator on
⏵⏵ auto mode on · 5h 58% · ⏵ narrator
There is no monthly window: Claude Code only reports the 5-hour and the weekly ones. Off a subscription (API key billing) there is nothing to show, so the footer stays as it is.
While it is on, it also drops the (shift+tab to cycle) hint after the permission mode and esc to interrupt while Claude works, to leave room for the meter. Turn either off in /config (hideCycleHint, hideInterruptHint).
/plugin marketplace add midudev/better-claude
/plugin install sub-meter@better-claude
One hooks module (hooks/register.tsx):
session.measure hands it the rate-limit windows after each response (five_hour, seven_day); $.session.usage() gives the first reading at start.$.store with the time it was taken, so a new session shows it before its first response, and every open session reads it back every 8 seconds: what one measures shows up in the others.ui.render hook on SessionMode draws the meter and, after it, what is beneath (the engine's mode labels, another plugin's switch such as Narrator's, which so stays last); $.clock.every redraws the countdown every 8 seconds and, in rotate, switches the window.e.viewport.columns) less the footer's padding, the mode label and the hint, and less what is beneath; the meter takes the widest form that fits.ui.render hook on PromptHint rewrites the hint line without (shift+tab to cycle) and esc to interrupt, and notes its width; the engine still draws it, and the mode label before it.claude plugin validate ./plugins/sub-meter # from the repository root
claude plugin test ./plugins/sub-meter # runs hooks/register.test.tsx against the engine
MIT © Miguel Ángel Durán (midudev)
hooks/register.tsx 267 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register, RenderNode, RenderViewport, SessionRateLimit } from 'claude-code'
3
4import type { Limit } from '../types'
5
6const limits = atom({ plugin: 'sub-meter', key: 'limits' } as const, [] as Limit[])
7const view = atom({ plugin: 'sub-meter', key: 'view' } as const, 0) // which window the rotating meter shows
8const tick = atom({ plugin: 'sub-meter', key: 'tick' } as const, 0) // redraws the countdown
9
10const WINDOWS = ['five_hour', 'seven_day']
11const LABELS: Record<string, string> = { five_hour: '5h', seven_day: 'week' }
12const ROTATE_SECONDS = 8
13const TICK_MS = 8000
14const DISPLAYS = ['rotate', 'both', 'session', 'week']
15const WINDOW_OF: Record<string, string> = { session: 'five_hour', week: 'seven_day' }
16const CELLS = 10
17const CYCLE_HINT = /\s*\([^()]+ to cycle\)/
18const INTERRUPT_HINT = /\s*esc to interrupt/
19// The terminal footer's row: two columns of padding at each end, the mode label at the left
20// (`⏵⏵ accept edits on ·`, the longest but bypass's) and the hint after it, two columns at least
21// between that and what is drawn here.
22const FOOTER_PADDING = 4
23const FOOTER_GAP = 2
24const MODE_LABEL = 20
25const SEPARATOR = ' · '
26const BETWEEN = ' | '
27// Room left, when nothing of another plugin is beneath, for one that may wrap the meter and draw
28// after it: Narrator's narrowest switch (`⏵`) and its separator.
29const AROUND = 1 + SEPARATOR.length
30// The least another plugin's drawing beneath counts for when the meter weighs its bar and reset time
31// (Narrator's `⏵ narrator`): what that plugin gives up where the row is short is not taken back for
32// them, so the meter only shrinks as the row does.
33const BENEATH_FLOOR = 10
34
35// The hint as last drawn on the terminal, in columns.
36let hintWidth = 0
37let lastHint = ''
38let lastTidied = ''
39let windowCount = 0
40let tickTimer: { cancel: () => void } | undefined
41let rotateTimer: { cancel: () => void } | undefined
42
43/** The subscription windows the meter shows, in order, from what the engine measured. */
44const windowsOf = (rateLimits: readonly SessionRateLimit[]): Limit[] =>
45 WINDOWS.flatMap(kind => {
46 const found = rateLimits.find(limit => limit.kind === kind)
47 return found ? [{ kind, percentUsed: found.percentUsed, resetsAt: found.resetsAt }] : []
48 })
49
50/** Whether a drawing beneath shows nothing: no text, no control (the engine's own node draws `modes`, counted apart). */
51function isBlank (node: RenderNode | undefined): boolean {
52 if (node === undefined || node === null) return true
53 if (typeof node === 'string') return node.trim() === ''
54 if (node.type === 'engine') return true
55 return (node.type === 'Box' || node.type === 'Text') && (node.children ?? []).every(isBlank)
56}
57
58/** Columns a text takes: one per character, none for a variation selector. */
59const widthOf = (text: string) => [...text.replace(/[\uFE0E\uFE0F]/g, '')].length
60
61/** Columns a drawing beneath takes on one row; the engine's own node draws `modes`, joined by ` & `. */
62function widthOfNode (node: RenderNode | undefined, modes: readonly string[]): number {
63 if (node === undefined || node === null) return 0
64 if (typeof node === 'string') return widthOf(node)
65 if (node.type === 'engine') return widthOf(modes.join(' & '))
66 return (node.children ?? []).reduce((sum, child) => sum + widthOfNode(child, modes), 0)
67}
68
69/** Whether a drawing beneath holds another plugin's: the engine stamps each hook's root with its plugin. */
70function holdsPlugin (node: RenderNode | undefined): boolean {
71 if (node === undefined || node === null || typeof node === 'string' || node.type === 'engine') return false
72 return 'part' in node || (node.children ?? []).some(holdsPlugin)
73}
74
75/** Columns the footer leaves at its right end on the terminal, beside the mode label and the hint; elsewhere, no limit. */
76function roomOf (e: { surface: string; viewport?: RenderViewport }) {
77 if (e.surface !== 'terminal' || e.viewport === undefined) return Infinity
78 return e.viewport.columns - FOOTER_PADDING - FOOTER_GAP - MODE_LABEL - (hintWidth > 0 ? 1 + hintWidth : 0)
79}
80
81const colorFor = (percent: number) => (percent >= 90 ? 'error' : percent >= 75 ? 'warning' : 'claude')
82
83/** "42m", "3h 5m", "2d 4h": how long until the window resets. */
84function until (ms: number) {
85 const minutes = Math.max(1, Math.round(ms / 60000))
86 if (minutes < 60) return `${minutes}m`
87 const hours = Math.floor(minutes / 60)
88 if (hours < 24) return `${hours}h ${minutes % 60}m`
89 return `${Math.floor(hours / 24)}d ${hours % 24}h`
90}
91
92// When the reading this session shows was taken; the shared store carries the newest one of any session.
93let seenAt = 0
94
95/** Keeps the latest reading for the meter, and for the next session until a response reports again. */
96async function remember ($: EngineInterface, found: Limit[]) {
97 if (found.length === 0) return
98 seenAt = await $.clock.now()
99 windowCount = found.length
100 await update($, limits, () => found)
101 await $.store.set('limits', found)
102 await $.store.set('at', seenAt) // after the limits, so a reader that sees the new time finds the new limits
103}
104
105/** Adopts the reading another session left in the shared store, when it is newer than ours. */
106async function syncFromStore ($: EngineInterface) {
107 const at = Number(await $.store.get('at')) || 0
108 if (at <= seenAt) return
109 const saved = await $.store.get('limits')
110 if (!Array.isArray(saved)) return
111 seenAt = at
112 windowCount = saved.length
113 await update($, limits, () => saved as Limit[])
114}
115
116/** The windows to draw: all of them, the one the rotation is on, or the one chosen. With fewer than two readings, whatever there is. */
117function visible (all: Limit[], display: string, index: number): Limit[] {
118 if (display === 'both' || all.length < 2) return all
119 if (display === 'rotate') return [all[index % all.length]]
120 return all.filter(limit => limit.kind === WINDOW_OF[display])
121}
122
123export const register: Register = (on, options) => {
124 seenAt = 0
125 windowCount = 0
126 lastHint = ''
127 lastTidied = ''
128 const hideCycleHint = options.hideCycleHint !== false
129 const hideInterruptHint = options.hideInterruptHint !== false
130 const rotateSeconds = Number(options.rotateSeconds)
131 const rotateMs = (rotateSeconds > 0 ? rotateSeconds : ROTATE_SECONDS) * 1000
132 const display = DISPLAYS.includes(String(options.display)) ? String(options.display) : 'rotate'
133 const hidden = [...(hideCycleHint ? [CYCLE_HINT] : []), ...(hideInterruptHint ? [INTERRUPT_HINT] : [])]
134
135 /** The hint line without the parts hidden, and without the empty parts they leave. */
136 function tidy (hint: string) {
137 if (!hidden.some(part => part.test(hint))) return hint
138 return hidden
139 .reduce((line, part) => line.replace(part, ' · '), hint)
140 .split('·')
141 .map(part => part.trim())
142 .filter(Boolean)
143 .join(' · ')
144 }
145
146 on('session.start', async ($, e, next) => {
147 tickTimer?.cancel()
148 tickTimer = undefined
149 rotateTimer?.cancel()
150 rotateTimer = undefined
151 const [saved, storedAt, usage] = await Promise.all([
152 $.store.get('limits'),
153 $.store.get('at'),
154 $.session.usage()
155 ])
156 if (Array.isArray(saved)) {
157 windowCount = saved.length
158 await update($, limits, () => saved as Limit[])
159 }
160 seenAt = Number(storedAt) || 0
161
162 await remember($, windowsOf(usage.rateLimits))
163
164 if (e.isInteractive) {
165 // Another session's reading shows up within TICK_MS of being stored.
166 tickTimer = $.clock.every(TICK_MS, () => {
167 void syncFromStore($).catch(() => {}) // a failed read keeps the reading on screen
168 if (windowCount > 0) void update($, tick, n => n + 1)
169 })
170 if (display === 'rotate') {
171 rotateTimer = $.clock.every(rotateMs, () => {
172 if (windowCount >= 2) void update($, view, n => n + 1)
173 })
174 }
175 }
176 return next(e)
177 })
178
179 on('session.end', ($, e, next) => {
180 tickTimer?.cancel()
181 tickTimer = undefined
182 rotateTimer?.cancel()
183 rotateTimer = undefined
184 return next(e)
185 })
186
187 on('session.measure', async ($, e, next) => {
188 await remember($, windowsOf(e.rateLimits))
189 return next(e)
190 })
191
192 // Bottom right of the prompt footer: the meter, then what is beneath it (the engine's mode labels,
193 // another plugin's switch), so a plugin that draws itself last stays last whichever wraps the other.
194 // Where the row is short the meter gives up its bar, then the time until the reset, then itself.
195 on('ui.render', { component: 'SessionMode' }, async ($, e, next) => {
196 const all = await read($, limits)
197 if (all.length === 0) return next(e)
198 const index = display === 'rotate' && all.length >= 2 ? await read($, view) : 0
199 const shown = visible(all, display, index)
200 if (shown.length === 0) return next(e)
201 // Subscribes this drawing to the countdown tick alongside reading the clock and beneath node
202 const [, now, beneath] = await Promise.all([read($, tick), $.clock.now(), next(e)])
203 const hasBeneath = e.props.modes.length > 0 || !isBlank(beneath)
204
205 const windows = shown.map(limit => {
206 const resetsIn = limit.resetsAt === undefined ? undefined : Date.parse(limit.resetsAt) - now
207 const hasReset = resetsIn !== undefined && resetsIn <= 0
208 const percent = hasReset ? 0 : limit.percentUsed
209 const filled = Math.round((Math.min(Math.max(percent, 0), 100) / 100) * CELLS)
210 const label = LABELS[limit.kind] ?? limit.kind
211 const used = ` ${Math.round(percent)}%`
212 const reset = resetsIn !== undefined && !hasReset ? ` ↻ ${until(resetsIn)}` : ''
213 return { kind: limit.kind, label, percent, filled, used, reset, short: widthOf(label + used) }
214 })
215 const below = widthOfNode(beneath, e.props.modes)
216 const hasPlugin = holdsPlugin(beneath)
217 const room = roomOf(e) - (hasBeneath ? below + SEPARATOR.length : 0) - (hasPlugin ? 0 : AROUND)
218 const given = hasPlugin ? Math.max(0, BENEATH_FLOOR - below) : 0
219 const short = windows.reduce((sum, w) => sum + w.short, (windows.length - 1) * BETWEEN.length)
220 const bars = windows.length * (1 + CELLS)
221 const resets = windows.reduce((sum, w) => sum + widthOf(w.reset), 0)
222 const fit = [
223 { hasBar: true, hasReset: true, width: short + bars + resets },
224 { hasBar: false, hasReset: true, width: short + resets },
225 { hasBar: false, hasReset: false, width: short }
226 ].find(({ hasReset, width }) => width <= (hasReset ? room - given : room))
227 if (!fit) return beneath
228
229 const { Box, Text } = $.ui.resolve(e)
230
231 return (
232 <Box flexDirection="row">
233 {windows.map((w, i) => (
234 <Box flexDirection="row" key={w.kind}>
235 {i > 0 ? <Text dimColor>{BETWEEN}</Text> : null}
236 <Text dimColor>{w.label}</Text>
237 {fit.hasBar ? <Text color={colorFor(w.percent)}>{' ' + '━'.repeat(w.filled)}</Text> : null}
238 {fit.hasBar ? <Text dimColor>{'─'.repeat(CELLS - w.filled)}</Text> : null}
239 <Text>{w.used}</Text>
240 {fit.hasReset && w.reset ? <Text dimColor>{w.reset}</Text> : null}
241 </Box>
242 ))}
243 {hasBeneath ? <Text dimColor>{SEPARATOR}</Text> : null}
244 {beneath}
245 </Box>
246 )
247 })
248
249 // The engine draws the mode label itself; the hint line after it starts with "(shift+tab to cycle)",
250 // and while Claude works holds "esc to interrupt". Its width tells the meter how much room is left.
251 on('ui.render', { component: 'PromptHint' }, ($, e, next) => {
252 if (e.props.hint !== lastHint) {
253 lastHint = e.props.hint
254 lastTidied = tidy(e.props.hint)
255 }
256 const hint = lastTidied
257 if (e.surface === 'terminal') {
258 const width = widthOf(hint)
259 if (width !== hintWidth) {
260 hintWidth = width
261 $.ui.invalidate('ui.render')
262 }
263 }
264 return hint === e.props.hint ? next(e) : next({ ...e, props: { ...e.props, hint } })
265 })
266}
267types/index.d.ts 9 lines1/** One rate-limit window of the subscription, as the last API response reported it. */
2export type Limit = { kind: string; percentUsed: number; resetsAt?: string }
3
4declare module 'claude-code' {
5 interface PluginState {
6 'sub-meter': { limits: Limit[]; view: number; tick: number }
7 }
8}
9