SLOPSHOPPER

usage-rings

Rings above the prompt showing the 5-hour, weekly and Fable weekly usage limits.

bandtimer
v0.3.0no licenseupdated 2026-10-18moa-os/claude-mods/usage-rings
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · usage-rings
› 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 ◔ 31% 5-hour ○ – Weekly ○ – Fable ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
◔ 31% 5-hour ○ – Weekly ○ – Fable
README

claude-mods

Mods for Claude Code: small plugins that change its interface.

Mods

usage-rings

Three rings above the prompt showing how much of your plan's usage limits you've used: the 5-hour limit, the weekly limit across all models, and the weekly Fable limit. Each shows the percent used and the time until it resets, and turns amber at 50% and red at 80%.

  • In the desktop app each ring is a small arc with its percent beside it, then the window's name and time left; hover over a ring for its reset time. In a terminal they're a text row with circle symbols.
  • The rings take the left of the band and leave the rest of the row to other mods, such as control-panel's pill.
  • The 5-hour and weekly figures come from Claude Code itself. The Fable figure comes from the desktop app's usage card, so in a terminal-only session it may show "–".
  • Only plans with usage limits have these figures (not API keys, Bedrock, Vertex or gateways).

control-panel

A control panel for your mods. A pill at the right end of the band above the prompt says "✦ Moa's CP" (with your own name), and clicking it, or typing /cp, opens the panel.

  • Your name is your Claude account's display name, which Claude Code keeps in its config file on each machine; without one, it's your login name (USER, or USERNAME on Windows).
  • The panel greets you by the time of day ("Good evening, Moa") on a strip whose colours change from morning to night, as the pill's do.
  • Its Mods tab has a card for every command your installed mods add, plus Claude Code's own /diff. Launch runs that command as if you'd typed it. Skills aren't listed, and nor are mods with nothing to launch. Mods it doesn't know yet get a card too, coloured by their name.
  • Its Stats tab counts your token usage: this conversation, or all conversations today, over the last 7 or 30 days, or all time. It shows conversations, replies, input tokens (split into read from cache, written to cache and new), output tokens, total tokens, your most used model, and output by model for your top five.
  • The counts come from the transcripts Claude Code keeps on each machine. The panel counts each reply once and keeps the totals in ~/.claude/control-panel/stats.json, so transcripts Claude Code later deletes take nothing away. The first count reads every transcript; after that it reads only what's new. Press 1 or 2 in the panel to switch tabs.

Install

In a Claude Code terminal session, run:

/plugin install usage-rings --marketplace moa-os/claude-mods
/plugin install control-panel --marketplace moa-os/claude-mods

Answer y to add the marketplace, then pick the user scope. Once installed from a terminal, the mods also load in the desktop app's sessions on that machine.

Update

After a new version is pushed here:

claude plugin update usage-rings
claude plugin update control-panel

Then restart Claude Code, or run /reload-plugins in a terminal session.

Developing

Each mod is a folder listed in .claude-plugin/marketplace.json. To check one:

claude plugin validate usage-rings
claude plugin test usage-rings

To work on the mods from a clone, add the clone itself as a marketplace and install from it. Claude Code then reads the mods straight from the clone, so /reload-plugins picks up your edits:

claude plugin marketplace add <path to this clone>
claude plugin install usage-rings@claude-mods
Source 3 files
hooks/register.tsx 158 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register, ThemeKey } from 'claude-code'
3
4import type { Entry, Level } from './usage'
5import {
6  EMPTY,
7  RINGS,
8  fromApp,
9  fromEngine,
10  glyphOf,
11  levelOf,
12  mergeAll,
13  ringColor,
14  ringSvg,
15  shownPercent,
16  timeLeft,
17} from './usage'
18
19const limits = atom({ plugin: 'usage-rings', key: 'limits' } as const, EMPTY)
20// Bumped once a minute so the reset countdowns redraw.
21const tick = atom({ plugin: 'usage-rings', key: 'tick' } as const, 0)
22
23// The desktop app's own MCP server; its usage card is the only source of the Fable weekly
24// window when the API's rate-limit headers don't carry it. Absent in a plain terminal.
25const APP_SERVER = 'ccd_session_mgmt'
26const APP_TOOL = 'get_usage'
27
28const MINUTE = 60_000
29const APP_POLL_MS = 2 * MINUTE
30const APP_POLL_AFTER_TURN_MS = 30_000
31
32const THEME: Record<Level, ThemeKey> = {
33  none: 'inactive',
34  low: 'success',
35  mid: 'warning',
36  high: 'error',
37}
38
39// Module variables are fine here: a hot reload starts them over and the first refresh polls anyway.
40let lastAppPoll = -Infinity
41let hadTurnSincePoll = false
42
43async function take($: EngineInterface, entries: Entry[]) {
44  if (entries.length === 0) return
45  const now = await $.clock.now()
46  await update($, limits, prev => mergeAll(prev ?? EMPTY, entries, now))
47}
48
49async function pollEngine($: EngineInterface) {
50  const { rateLimits } = await $.session.usage()
51  await take($, fromEngine(rateLimits))
52}
53
54async function pollApp($: EngineInterface) {
55  lastAppPoll = await $.clock.now()
56  hadTurnSincePoll = false
57  await take($, fromApp(await $.mcp.call(APP_SERVER, APP_TOOL)))
58}
59
60async function refresh($: EngineInterface, isFirst: boolean) {
61  const now = await $.clock.now()
62  const wait = hadTurnSincePoll ? APP_POLL_AFTER_TURN_MS : APP_POLL_MS
63  const polls = [pollEngine($)]
64  if (isFirst || now - lastAppPoll >= wait) polls.push(pollApp($))
65  await Promise.allSettled(polls)
66  await update($, tick, n => (n ?? 0) + 1)
67}
68
69export const register: Register = on => {
70  on('session.start', async ($, e, next) => {
71    const started = await next(e)
72    $.clock.after(1, () => void refresh($, true))
73    $.clock.every(MINUTE, () => void refresh($, false))
74    $.ui.invalidate('ui.render')
75    return started
76  })
77
78  // Pushed by the engine whenever a window moves a whole point.
79  on('session.measure', async ($, e, next) => {
80    await take($, fromEngine(e.rateLimits))
81    return next(e)
82  })
83
84  on('turn.complete', async ($, e, next) => {
85    hadTurnSincePoll = true
86    return next(e)
87  })
88
89  // The band is one site that other mods may draw in too (the control panel's pill, say): the
90  // rings take the left, and whatever the mods beneath drew fills the rest of the row. The
91  // engine's own answer there is its empty band, which draws nothing, so it is left out.
92  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
93    if (e.props.hasSurvey) return next(e)
94
95    const below = await next(e)
96    const others = below.type === 'engine' ? null : below
97
98    const current = await read($, limits)
99    await read($, tick)
100    const now = await $.clock.now()
101    const rings = RINGS.map(({ ring, label, short }) => {
102      const reading = current[ring]
103      const percent = shownPercent(reading, now)
104      return { ring, label, short, percent, left: timeLeft(reading, now) }
105    })
106
107    let drawn
108    if (e.surface === 'terminal') {
109      const { Box, Text } = $.ui.resolve(e)
110      drawn = (
111        <Box key="usage-rings" flexDirection="row" flexWrap="wrap" columnGap={3}>
112          {rings.map(r => (
113            <Box key={r.ring} flexDirection="row" columnGap={1}>
114              <Text color={THEME[levelOf(r.percent)]} bold>
115                {glyphOf(r.percent)} {r.percent === null ? '–' : `${Math.round(r.percent)}%`}
116              </Text>
117              <Text>{r.label}</Text>
118              {r.left !== '' && <Text dimColor>{r.left}</Text>}
119            </Box>
120          ))}
121        </Box>
122      )
123    } else {
124      const { Box, Svg, Text } = $.ui.resolve(e)
125      drawn = (
126        <Box key="usage-rings" flexDirection="row" flexWrap="wrap" alignItems="center" columnGap="sm">
127          {rings.map(r => {
128            const used = r.percent === null ? 'no reading yet' : `${Math.round(r.percent)}% used`
129            const title = `${r.label}: ${used}${r.left === '' ? '' : `, resets in ${r.left}`}`
130            return (
131              <Box key={r.ring} flexDirection="row" alignItems="center" columnGap="xs">
132                <Svg source={ringSvg(r.percent, title)} alt={`${r.label}: ${used}`} width={14} height={14} isInteractive />
133                <Text size="footnote" weight="semibold" color={ringColor(r.percent)}>
134                  {r.percent === null ? '–' : `${Math.round(r.percent)}%`}
135                </Text>
136                <Text size="footnote" weight="semibold">{r.short}</Text>
137                {r.left !== '' && <Text size="footnote" dimColor>{r.left}</Text>}
138              </Box>
139            )
140          })}
141        </Box>
142      )
143    }
144
145    const { Box } = $.ui.resolve(e)
146    return (
147      <Box flexDirection="row" alignItems="center">
148        {drawn}
149        {others !== null && (
150          <Box flexGrow={1} flexDirection="row" marginLeft={e.surface === 'terminal' ? 3 : 'md'}>
151            {others}
152          </Box>
153        )}
154      </Box>
155    )
156  })
157}
158
hooks/usage.ts 157 lines
1import type { McpToolResult, SessionRateLimit } from 'claude-code'
2
3import type { Limits, Reading } from '../types'
4
5export type Ring = keyof Limits
6export type Entry = { ring: Ring; reading: Reading }
7export type Level = 'none' | 'low' | 'mid' | 'high'
8
9export const EMPTY: Limits = { fiveHour: null, weekly: null, fable: null }
10
11// `short` is the name the desktop's small rings carry; `label` names the window everywhere else.
12export const RINGS: readonly { ring: Ring; label: string; short: string }[] = [
13  { ring: 'fiveHour', label: '5-hour', short: '5h' },
14  { ring: 'weekly', label: 'Weekly', short: 'Week' },
15  { ring: 'fable', label: 'Fable', short: 'Fable' },
16]
17
18const MINUTE = 60_000
19const HOUR = 60 * MINUTE
20const DAY = 24 * HOUR
21
22// The engine names windows after the API's rate-limit kinds (`five_hour`, `seven_day`,
23// `seven_day_fable`); the app's usage card labels them ("5-hour limit", "Weekly · Fable").
24// Fable is checked first because its label also says "Weekly".
25export function ringOf(name: string): Ring | null {
26  const n = name.toLowerCase()
27  if (n.includes('fable')) return 'fable'
28  if (n === 'five_hour' || n.includes('5-hour')) return 'fiveHour'
29  if (n === 'seven_day' || n.includes('all models')) return 'weekly'
30  return null
31}
32
33export function readingOf(percent: number, resetsAt: string | undefined): Reading {
34  const at = resetsAt === undefined ? NaN : Date.parse(resetsAt)
35  return { percent, resetsAt: Number.isFinite(at) ? at : null }
36}
37
38export function fromEngine(rateLimits: readonly SessionRateLimit[]): Entry[] {
39  const entries: Entry[] = []
40  for (const limit of rateLimits) {
41    const ring = ringOf(limit.kind)
42    if (ring !== null) entries.push({ ring, reading: readingOf(limit.percentUsed, limit.resetsAt) })
43  }
44  return entries
45}
46
47type AppWindow = { label?: unknown; percentUsed?: unknown; resetsAt?: unknown }
48
49// The desktop app's get_usage tool answers JSON in a text block:
50// { plan: { status: "ok", windows: [{ label, percentUsed, resetsAt }] } }.
51export function fromApp(result: McpToolResult): Entry[] {
52  if (result.isError) return []
53  const data = result.structuredContent ?? parseText(result)
54  const plan = (data as { plan?: { status?: unknown; windows?: unknown } } | undefined)?.plan
55  if (plan?.status !== 'ok' || !Array.isArray(plan.windows)) return []
56
57  const entries: Entry[] = []
58  for (const window of plan.windows as AppWindow[]) {
59    if (typeof window.label !== 'string' || typeof window.percentUsed !== 'number') continue
60    const ring = ringOf(window.label)
61    const resetsAt = typeof window.resetsAt === 'string' ? window.resetsAt : undefined
62    if (ring !== null) entries.push({ ring, reading: readingOf(window.percentUsed, resetsAt) })
63  }
64  return entries
65}
66
67function parseText(result: McpToolResult): unknown {
68  const text = result.content.find(block => block.type === 'text')?.text
69  if (text === undefined) return undefined
70  try {
71    return JSON.parse(text)
72  } catch {
73    return undefined
74  }
75}
76
77// Both sources report the same window at slightly different moments. Within one window usage
78// only grows, so the higher figure is the fresher one; a later reset time is a new window.
79export function merge(prev: Reading | null, next: Reading, now: number): Reading {
80  if (prev === null) return next
81  if (prev.resetsAt !== null && prev.resetsAt <= now) return next
82  if (prev.resetsAt === null || next.resetsAt === null) return next
83  if (next.resetsAt > prev.resetsAt + MINUTE) return next
84  if (next.resetsAt < prev.resetsAt - MINUTE) return prev
85  return next.percent >= prev.percent ? next : prev
86}
87
88export function mergeAll(limits: Limits, entries: readonly Entry[], now: number): Limits {
89  const merged = { ...limits }
90  for (const { ring, reading } of entries) merged[ring] = merge(merged[ring], reading, now)
91  return merged
92}
93
94/** The percent to draw: 0 once the window has reset, null with no reading yet. */
95export function shownPercent(reading: Reading | null, now: number): number | null {
96  if (reading === null) return null
97  if (reading.resetsAt !== null && reading.resetsAt <= now) return 0
98  return Math.max(0, Math.min(100, reading.percent))
99}
100
101export function levelOf(percent: number | null): Level {
102  if (percent === null) return 'none'
103  if (percent >= 80) return 'high'
104  if (percent >= 50) return 'mid'
105  return 'low'
106}
107
108/** Time until the window resets ("4h 59m"); empty with no reading or no reset time. */
109export function timeLeft(reading: Reading | null, now: number): string {
110  if (reading === null || reading.resetsAt === null) return ''
111  const ms = reading.resetsAt - now
112  if (ms <= 0) return 'reset'
113  if (ms >= DAY) return `${Math.floor(ms / DAY)}d ${Math.floor((ms % DAY) / HOUR)}h`
114  if (ms >= HOUR) return `${Math.floor(ms / HOUR)}h ${Math.floor((ms % HOUR) / MINUTE)}m`
115  return `${Math.max(1, Math.ceil(ms / MINUTE))}m`
116}
117
118// A quarter-step circle glyph for the terminal, which has no Svg.
119export function glyphOf(percent: number | null): string {
120  if (percent === null || percent < 12.5) return '○'
121  if (percent < 37.5) return '◔'
122  if (percent < 62.5) return '◑'
123  if (percent < 87.5) return '◕'
124  return '●'
125}
126
127const SVG_COLORS: Record<Level, string> = {
128  none: '#8a8a8a',
129  low: '#2fa36b',
130  mid: '#d99a00',
131  high: '#e5484d',
132}
133
134/** The ring's color, also used for the percent written beside it. */
135export function ringColor(percent: number | null): string {
136  return SVG_COLORS[levelOf(percent)]
137}
138
139// Drawn as an image, so it can't follow the page's theme: the track is a translucent grey and
140// the arc uses mid-tone colors that read on both light and dark backgrounds. Drawn small, so it
141// carries no number: `title` (the percent and reset time) shows when the pointer rests on it.
142export function ringSvg(percent: number | null, title: string): string {
143  const color = ringColor(percent)
144  const value = percent ?? 0
145  const arc =
146    value > 0
147      ? `<circle cx="15" cy="15" r="11" fill="none" stroke="${color}" stroke-width="4.5" stroke-linecap="round" pathLength="100" stroke-dasharray="${value} 100" transform="rotate(-90 15 15)"/>`
148      : ''
149  return (
150    `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" width="30" height="30">` +
151    `<title>${title}</title>` +
152    `<circle cx="15" cy="15" r="11" fill="none" stroke="#8a8a8a" stroke-opacity="0.3" stroke-width="4.5"/>` +
153    arc +
154    `</svg>`
155  )
156}
157
types/index.d.ts 16 lines
1/** One limit window: how much is used (0 to 100) and when it resets (epoch ms). */
2export type Reading = { percent: number; resetsAt: number | null }
3
4/** The three windows the band draws; null until a source has reported one. */
5export type Limits = {
6  fiveHour: Reading | null
7  weekly: Reading | null
8  fable: Reading | null
9}
10
11declare module 'claude-code' {
12  interface PluginState {
13    'usage-rings': { limits: Limits; tick: number }
14  }
15}
16