SLOPSHOPPER

usage-limits

Context bar plus 5h and 7d rate limits with time left until each resets, above the prompt

bandtimer
v0.2.2no licenseupdated 2026-10-15katipally/modz/mods/ui/usage-limits
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · usage-limits
› fix the failing auth test and add an audit log call ⏺ Read(src/auth.ts) ⎿ Read 6 lines ⏺ Update(src/auth.ts) ⎿ Added 2 lines, removed 1 line ⏺ Bash(bun test) ⎿ 3 pass, 1 fail ● Done. refresh now rejects expired claims and logs an audit event. ✻ Worked for 42s · done 4:20 PM ctx ░░░░░░░░ 49% 5h 31% · NaNm ⟨Claude Code's own drawing⟩ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
ctx ░░░░░░░░ 49% 5h 31% · NaNm ⟨Claude Code's own drawing⟩
README

usage-limits

Context bar plus your 5-hour and weekly rate limits, each with time left until it resets. Shown above the prompt; updates after every turn and ticks every 30s.

ctx   ████░░░░░░ 41%   5h 42% · 27m   7d 6% · 6d 18h

Install

/plugin install usage-limits --marketplace katipally/modz

Update, then restart your sessions (more in the main README):

claude plugin marketplace update modz
claude plugin update usage-limits@modz

Percentages turn yellow at 60% and red at 85%: the context bar is orange below that, the 5h and 7d values green. Labels and reset times stay uncolored; the time after each limit is how long until it resets. Rate limits show on subscription accounts only. The numbers are read when the session starts, on resume and after /clear, then follow every turn; Claude Code reports the context fill and the limits only after its first response, so a brand-new session shows placeholders until then. Before they arrive (and for limits your account does not report) the tile draws ctx ░░░░░░░░░░ – 5h – 7d – instead of hiding.

Source 2 files
hooks/register.tsx 190 lines
1import { atom, read, update } from 'claude-code'
2import type { Register, BoxProps, ElementConstructor, EngineInterface, RenderElement, RenderNode, SessionRateLimit, Timer } from 'claude-code'
3
4import type { Limit } from '../types'
5
6// Reset countdowns read in minutes, so a 30s tick keeps them honest.
7const TICK_MS = 30_000
8const LABELS: Record<string, string> = { five_hour: '5h', seven_day: '7d', spend_limit: 'spend' }
9
10const usage = atom({ plugin: 'usage-limits', key: 'usage' } as const, { limits: [] })
11const now = atom({ plugin: 'usage-limits', key: 'now' } as const, 0)
12const shownPct = atom({ plugin: 'usage-limits', key: 'shownPct' } as const, 0)
13
14// The bar eases toward a new value over a few frames instead of jumping.
15const GROW_MS = 40
16let grower: Timer | undefined
17const grow = async ($: EngineInterface, target: number) => {
18  grower?.cancel()
19  grower = $.clock.every(GROW_MS, async () => {
20    const shown = await read($, shownPct)
21    const step = Math.sign(target - shown) * Math.max(0.5, Math.abs(target - shown) / 5)
22    const nextPct = Math.abs(target - shown) <= 0.5 ? target : shown + step
23    await update($, shownPct, () => nextPct)
24    if (nextPct === target) grower?.cancel()
25  })
26}
27
28const toLimits = (limits: SessionRateLimit[]): Limit[] => limits.map(({ kind, percentUsed, resetsAt }) => ({ kind, percentUsed, resetsAt }))
29
30// Limits of the last session that saw any, so a new one shows them before its first response reports. They are marked stale
31// (other sessions may have used the window since), and a window that has reset since shows its placeholder.
32const seed = async ($: EngineInterface) => {
33  const saved = await $.store.get('limits').catch(() => undefined)
34  if (!Array.isArray(saved)) return
35  const t = Date.now()
36  const limits = (saved as Limit[]).map(l => (!l.resetsAt || Date.parse(l.resetsAt) > t ? { ...l, isStale: true } : { kind: l.kind, isStale: true }))
37  await update($, usage, u => (u.limits.length ? u : { ...u, limits }))
38}
39
40// An engine reading with no limits (a fresh session) keeps the stale ones shown; a live reading replaces them.
41const apply = async ($: EngineInterface, percent: number | undefined, limits: SessionRateLimit[]) => {
42  const live = toLimits(limits)
43  await update($, usage, u => ({ contextPercent: percent, limits: live.length ? live : u.limits.filter(l => l.isStale) }))
44  if (percent !== undefined) await grow($, percent)
45  if (live.length) await $.store.set('limits', live).catch(() => undefined)
46}
47
48// "6d 18h" past a day, "2h 5m" past an hour, else "27m".
49const span = (ms: number) => {
50  const m = Math.max(0, Math.round(ms / 60_000))
51  const [d, h] = [Math.floor(m / 1440), Math.floor((m % 1440) / 60)]
52  return d ? `${d}d ${h}h` : h ? `${h}h ${m % 60}m` : `${m}m`
53}
54
55// Every modz mod places its tile in one shared band: a lead column (the bot), then a column of tiles, then an optional
56// right column. A column with no tiles is not drawn, and columns wrap under each other when the width runs out.
57const BAND = 'modz-band'
58const SLOTS: Record<string, 'lead' | 'left' | 'right'> = {
59  buddy: 'lead',
60  'usage-limits': 'left',
61  'cache-timer': 'left',
62  'model-info': 'left',
63  orchestrator: 'left',
64}
65const ORDER = Object.keys(SLOTS)
66const keyOf = (n: RenderNode) => (typeof n !== 'string' && n.type === 'Box' ? String(n.props?.key ?? '') : '')
67const rank = (n: RenderNode) => {
68  const i = ORDER.indexOf(keyOf(n))
69  return i < 0 ? ORDER.length : i
70}
71const pack = (Box: ElementConstructor<BoxProps>, below: RenderElement, tile: RenderElement) => {
72  const isEmpty = below.type === 'Box' && !below.children?.length
73  const tiles = keyOf(below) === BAND
74    ? (below.type === 'Box' ? below.children ?? [] : []).flatMap(col => (typeof col !== 'string' && col.type === 'Box' ? col.children ?? [] : [col]))
75    : isEmpty ? [] : [below]
76  const all = [...tiles, tile].sort((a, b) => rank(a) - rank(b))
77  const [lead, left, right] = (['lead', 'left', 'right'] as const).map(slot => all.filter(n => (SLOTS[keyOf(n)] ?? 'left') === slot))
78  return (
79    <Box key={BAND} flexDirection="row" flexWrap="wrap" columnGap={3}>
80      {lead!.length > 0 && <Box key="modz-lead" flexDirection="column" justifyContent="center">{lead}</Box>}
81      {left!.length > 0 && <Box key="modz-left" flexDirection="column" flexGrow={right!.length > 0 ? 1 : 0}>{left}</Box>}
82      {right!.length > 0 && <Box key="modz-right" flexDirection="column" alignItems="flex-end">{right}</Box>}
83    </Box>
84  )
85}
86
87// Each tile has its own Claude theme color; values turn yellow at 60% and red at 85% as they fill.
88const TINT = 'claude'
89const tone = (pct: number, calm: string) => (pct >= 85 ? 'error' : pct >= 60 ? 'warning' : calm)
90
91// The session binds around session.start, so the first read waits for next(e); one that still rejects is retried on the tick.
92// Every reload clears isLoaded first, so a failed one is retried the same way.
93let isLoaded = false
94// A resumed session has no live window until its first response, so the last response's size from classic.SessionStart stands in;
95// that count includes the output, so it reads a hair above the status line's own figure. A session with no prompts is 0% full.
96let resumedTokens: number | undefined
97const load = async ($: EngineInterface) => {
98  try {
99    const [u, turns] = await Promise.all([$.session.usage(), $.session.turns().catch(() => undefined)])
100    const { percent, window } = u.context
101    const seeded = resumedTokens && window ? Math.min(100, Math.round((resumedTokens / window) * 100)) : undefined
102    await apply($, percent ?? seeded ?? (turns === 0 && window ? 0 : undefined), u.rateLimits)
103    isLoaded = true
104  } catch (err) {
105    $.ui.log(`usage-limits: ${err}`, { to: 'debug' })
106  }
107}
108
109const reload = ($: EngineInterface) => {
110  isLoaded = false
111  return load($)
112}
113
114export const register: Register = on => {
115  on('session.start', async ($, e, next) => {
116    const started = await next(e)
117    await update($, now, () => Date.now())
118    $.clock.every(TICK_MS, () => {
119      void update($, now, () => Date.now())
120      if (!isLoaded) void load($)
121    })
122    await seed($)
123    await load($)
124    return started
125  })
126
127  // /clear and a resume end the session before the next one binds, so the tile resets and the tick loads it.
128  on('session.end', async ($, e, next) => {
129    if (e.reason === 'clear' || e.reason === 'resume') {
130      isLoaded = false
131      resumedTokens = undefined
132      await update($, usage, () => ({ limits: [] }))
133      await seed($)
134    }
135    return next(e)
136  })
137
138  on('session.compact', async ($, e, next) => {
139    const compacted = await next(e)
140    if (e.trigger !== 'precompute' && e.agentId === undefined && !compacted.skip) await reload($)
141    return compacted
142  }).catch(($, e, next) => next(e))
143
144  // Loads right after /clear, resume and compact where the engine runs classic hooks; not where an organization manages Claude Code.
145  on('classic.SessionStart', async ($, e, next) => {
146    const started = await next(e)
147    resumedTokens = e.source === 'resume' || e.source === 'fork' ? e.context_tokens : undefined
148    await reload($)
149    return started
150  }).catch(($, e, next) => next(e))
151
152  on('session.measure', async ($, e, next) => {
153    await apply($, e.context.percent, e.rateLimits)
154    return next(e)
155  })
156
157  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
158    const below = await next(e)
159    if (e.props.hasSurvey) return below
160    const { Box, Text } = $.ui.resolve(e)
161    const [u, , shown] = await Promise.all([read($, usage), read($, now), read($, shownPct)])
162    const t = Date.now()
163    const pct = u.contextPercent
164
165    const width = Math.max(5, Math.min(10, Math.floor(e.props.bodyColumns / 12)))
166    const filled = pct === undefined ? 0 : Math.min(width, Math.max(0, Math.round((shown / 100) * width)))
167    const metric = (label: string, value?: number, detail?: string, isStale?: boolean) => (
168      <Text>
169        <Text dimColor>{label} </Text>
170        {value === undefined ? <Text dimColor>–</Text> : isStale ? <Text dimColor>~{Math.round(value)}%</Text> : <Text bold color={tone(value, 'success')}>{Math.round(value)}%</Text>}
171        {detail && <Text dimColor> · {detail}</Text>}
172      </Text>
173    )
174
175    return pack(Box, below, (
176      <Box key="usage-limits" flexDirection="row" flexWrap="wrap" columnGap={3}>
177        <Text>
178          <Text color={TINT}>{'ctx'.padEnd(5)} </Text>
179          <Text color={tone(pct ?? 0, TINT)}>{'█'.repeat(filled)}</Text>
180          <Text dimColor>{'░'.repeat(width - filled)} </Text>
181          {pct === undefined ? <Text dimColor>–</Text> : <Text bold color={tone(pct, TINT)}>{Math.round(pct)}%</Text>}
182        </Text>
183        {u.limits.length > 0
184          ? u.limits.map(l => metric(LABELS[l.kind] ?? l.kind, l.percentUsed, l.resetsAt && span(Date.parse(l.resetsAt) - t), l.isStale))
185          : [metric('5h'), metric('7d')]}
186      </Box>
187    ))
188  })
189}
190
types/index.d.ts 10 lines
1export type Limit = { kind: string; percentUsed?: number; resetsAt?: string; isStale?: boolean }
2
3export type Usage = { contextPercent?: number; limits: Limit[] }
4
5declare module 'claude-code' {
6  interface PluginState {
7    'usage-limits': { usage: Usage; now: number; shownPct: number }
8  }
9}
10