modscode / Gallery / usage-meter
usage-meter
Plan-limit bars with burn rate and time-to-empty, session cost, cache hit ratio and tokens-per-turn sparkline.
What it does
- Draws a pane, toasts
- Adds /meter
- Hooks session.start, turn.complete
Good points
- No network calls
- Starts no processes
- Small: 338 lines
- Written in TypeScript
Code to start from
Two kinds: a starter modscode writes from the design above, and the lines of the mod's own code that draw it.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like usage-meter by Michael Goldenberg (pane, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/mishgoldenberg-usage-meter/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Usage" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Svg, Input, Button } = $.ui.resolve(e)
const status = '…'
const kind = '…'
const LABELS = '…'
const pct = '…'
const svgBar = '…'
const until = '…'
const perHour = '…'
const hoursLeft = '…'
const kind2 = '…'
const until2 = '…'
const kind3 = '…'
const until3 = '…'
const value = '…'
const value2 = '…'
const value3 = '…'
const value4 = '…'
const value5 = '…'
const value6 = '…'
const value7 = '…'
const spark = '…'
const value8 = '…'
const value9 = '…'
const value10 = '…'
return (
<Box flexDirection="column" gap={1}>
<Box gap={1}>
<Text>
▲
</Text>
<Text bold>
usage-meter
</Text>
<Text dimColor wrap="truncate-end">
{status}
</Text>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
Plan limits
</Text>
</Box>
<Box flexDirection="column">
<Text dimColor>
No rate-limit windows reported (API key, or a plan without limits).
</Text>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind2}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until2}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">
{kind3}
</Text>
</Box>
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS} ${pct}% used`} source={`${svgBar}`} />
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{`▲ ${pct}%`}
</Text>
</Box>
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until3}
{` · +${perHour}%/h this session · full in ~${hoursLeft}m`}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
This session
</Text>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cost
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Time
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value2}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Turns
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value3}
</Text>
</Box>
</Box>
<Input />
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Output
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value4}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache read
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value5}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache write
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value6}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Cache hit
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text color="success">
{value7}
</Text>
</Box>
</Box>
<Text dimColor>
Low cache hit: long pauses or edits to early context break the cache.
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>
Tokens per turn (new, uncached)
</Text>
</Box>
<Box flexDirection="column">
<Text color="claude">
{spark}
</Text>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Last
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value8}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Average
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value9}
</Text>
</Box>
</Box>
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
Max
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
{value10}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box gap={1}>
<Button hotkey="r" variant="primary" label="Refresh" />
<Button label="Reset burn baseline" />
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const LABELS = '…'
const percentUsed = '…'
const until = '…'
await $.ui.toast(`${LABELS} limit at ${percentUsed}% (${until})`)
return next(e)
})
}
The mod's own code
Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.
plugins/usage-meter/hooks/register.tsx lines 182–307 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const els = $.ui.resolve(e)
const { Box, Text, Button } = els
const Svg = 'Svg' in els ? els.Svg : undefined
const kit = { Box, Text }
const snap = await read($, snapshot)
const list = await read($, turns)
const base = await read($, baseline)
const cols = e.props.bodyColumns ?? 40
const width = Math.max(10, Math.min(30, cols - 20))
if (snap === null) {
return (
<Box flexDirection="column" gap={1}>
{header(kit, GLYPH.off, TONE.dim, 'usage-meter', 'no reading yet')}
{empty(kit, 'Plan limits and cost update after every turn and once a minute. Read them now to see where you stand.')}
<Box>
<Button key="refresh" hotkey="r" variant="primary" label="Read usage" onPress={() => void refresh($)} />
</Box>
</Box>
)
}
const now = snap.updatedAt
const totals = list.reduce((s, t) => ({ input: s.input + t.input, output: s.output + t.output, cacheRead: s.cacheRead + t.cacheRead, cacheWrite: s.cacheWrite + t.cacheWrite }), { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 })
const prompted = totals.input + totals.cacheRead + totals.cacheWrite
const cacheHit = prompted > 0 ? Math.round((totals.cacheRead / prompted) * 100) : null
const minutes = Math.round((now - snap.startedAt) / 60000)
const perTurn = list.map(t => t.input + t.output + t.cacheWrite)
const toneOf = (pct: number) => (pct >= 95 ? TONE.bad : pct >= warnAt ? TONE.warn : undefined)
const worst = Math.max(0, ...snap.windows.map(w => w.percentUsed))
const five = snap.windows.find(w => w.kind === 'five_hour')
const status = [five ? `5h ${Math.round(five.percentUsed)}%` : '', snap.costUsd !== null ? `$${snap.costUsd.toFixed(2)}` : '', `${list.length} turns`].filter(Boolean).join(' · ')
const stat = (label: string, value: string, color?: string) => (
<Box gap={1}>
<Box flexGrow={1} flexShrink={1}>
<Text dimColor wrap="truncate-end">
{label}
</Text>
</Box>
{num(kit, value, 9, color)}
</Box>
)
return (
<Box flexDirection="column" gap={1}>
{header(kit, worst >= warnAt ? GLYPH.warn : GLYPH.on, toneOf(worst) ?? TONE.accent, 'usage-meter', status)}
{section(
kit,
'Plan limits',
<Box flexDirection="column">
{snap.windows.length === 0 && empty(kit, 'No rate-limit windows reported (API key, or a plan without limits).')}
{snap.windows.map(w => {
const b = burn(w, base, now)
const pct = Math.round(w.percentUsed)
return (
<Box flexDirection="column">
<Box gap={1}>
<Box width={11} flexShrink={0}>
<Text wrap="truncate-end">{LABELS[w.kind] ?? w.kind}</Text>
</Box>
{Svg !== undefined ? (
<Box flexGrow={1} flexShrink={1}>
<Svg alt={`${LABELS[w.kind] ?? w.kind} ${pct}% used`} source={svgBar(w.percentUsed)} />
</Box>
) : (
<Text color={TONE.accent}>{bar(w.percentUsed, width)}</Text>
)}
{num(kit, `${w.percentUsed >= warnAt ? `${GLYPH.warn} ` : ''}${pct}%`, 6, toneOf(w.percentUsed))}
</Box>
<Box paddingLeft={12}>
<Text dimColor wrap="truncate-end">
{until(w.resetsAt, now)}
{b !== null && ` · +${b.perHour.toFixed(1)}%/h this session · full in ~${b.hoursLeft < 1 ? `${Math.round(b.hoursLeft * 60)}m` : `${b.hoursLeft.toFixed(1)}h`}`}
</Text>
</Box>
</Box>
)
})}
</Box>,
)}
{section(
kit,
'This session',
<Box flexDirection="column">
{stat('Cost', snap.costUsd !== null ? `$${snap.costUsd.toFixed(2)}` : 'n/a')}
{stat('Time', `${minutes}m`)}
{stat('Turns', String(list.length))}
{stat('Input', k(totals.input))}
{stat('Output', k(totals.output))}
{stat('Cache read', k(totals.cacheRead))}
{stat('Cache write', k(totals.cacheWrite))}
{cacheHit !== null && stat('Cache hit', `${cacheHit < 40 ? `${GLYPH.warn} ` : ''}${cacheHit}%`, cacheHit >= 70 ? TONE.ok : cacheHit >= 40 ? undefined : TONE.warn)}
{cacheHit !== null && cacheHit < 40 && <Text dimColor>Low cache hit: long pauses or edits to early context break the cache.</Text>}
</Box>,
)}
{section(
kit,
'Tokens per turn (new, uncached)',
perTurn.length < 2 ? (
empty(kit, 'The chart starts after two turns.')
) : (
<Box flexDirection="column">
{Svg !== undefined ? (
<Svg alt={`Tokens per turn over the last ${Math.min(perTurn.length, 60)} turns`} source={svgSpark(perTurn.slice(-60))} />
) : (
<Text color={TONE.accent}>{spark(perTurn.slice(-Math.max(8, cols - 4)))}</Text>
)}
{stat('Last', k(perTurn.at(-1) ?? 0))}
{stat('Average', k(perTurn.reduce((a, b) => a + b, 0) / perTurn.length))}
{stat('Max', k(Math.max(...perTurn)))}
</Box>
),
)}
<Box gap={1}>
<Button key="refresh" hotkey="r" variant="primary" label="Refresh" onPress={() => void refresh($)} />
<Button key="reset" label="Reset burn baseline" onPress={() => void update($, baseline, () => null).then(() => refresh($))} />
</Box>
</Box>
)
})plugins/usage-meter/hooks/register.tsx lines 12–20 · Pane
function header({ Box, Text }: Kit, glyph: string, tone: string, name: string, status: string) {
return (
<Box gap={1}>
<Text color={tone}>{glyph}</Text>
<Text bold>{name}</Text>
<Text dimColor wrap="truncate-end">{status}</Text>
</Box>
)
}plugins/usage-meter/hooks/register.tsx lines 45–47 · Pane
function empty({ Text }: Kit, text: string) {
return <Text dimColor>{text}</Text>
}plugins/usage-meter/hooks/register.tsx lines 23–33 · Pane
function section({ Box, Text }: Kit, label: string, rows: RenderChildren, aside?: RenderChildren) {
return (
<Box flexDirection="column">
<Box gap={1}>
<Text dimColor>{label}</Text>
{aside}
</Box>
{rows}
</Box>
)
}plugins/usage-meter/hooks/register.tsx lines 36–42 · Pane
function num({ Box, Text }: Kit, value: string, width: number, color?: string) {
return (
<Box width={width} flexShrink={0} justifyContent="flex-end">
<Text color={color}>{value}</Text>
</Box>
)
}Licence text (MIT)
MIT License Copyright (c) 2026 Michael Goldenberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
What its code calls
nothing found
The design, read from code
Drawn from the mod's source at the commit read, not from a run: a list is drawn three times, a condition takes its first branch that draws in the desktop app, and a value only the run time knows is shown as a made-up sample (dotted underline) or left out. Colours and type are this site's.
What its code shows
Read from the source at commit 6949e8dde6af on 2026-10-06. The first group decides whether a mod is listed; the rest is for you to weigh. A later commit is not read until the next crawl.
| Decides the listing: code you can check | |
|---|---|
| Entry read | Every module hooks/hooks.json names was read.plugins/usage-meter/hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.1 files parsed |
| All its code is in the mod | Every import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod |
| Readable | No minified lines, no eval or new Function, no import of a computed path, no encoded blobs.no minified code, no eval, no encoded blobs |
| Calls in the open | Network and programs are reached as $.http.fetch and $.process.run in place, never passed around.every call outside goes through $ in the open |
| For you to weigh before installing | |
| Where it draws | The terminal, the desktop app, both, or nothing (hooks only: a guard or a prompt rewriter), as its code says. Shown, never a reason to leave a mod out.draws in the terminal and the desktop app, the same in both |
| Install line | Whether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.listed in its repository's .claude-plugin/marketplace.json: installs from there |
| Programs on Windows | Whether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks |
| Network | Whether every fetch names its https host in the code.no network |
| Programs | Whether every program it starts is named in the code and is not a shell, an interpreter or a network tool.starts no programs |
| Reads and sends | Whether it both reads files or environment variables and reaches the network.reaches no network |
| Keys in the source | Whether the source holds what looks like an API key or a private key.no keys in the source |
| Licence | An open licence (MIT, Apache-2.0, BSD, ISC, Unlicense, 0BSD, CC0) with its text lets modscode show its code; otherwise the code is linked.MIT |
This is a reading of the code text, not a security review: it does not run the mod, and it cannot see what a program the mod starts does. The check before installing is yours. How mods are chosen
Install it
Check it yourself before you install it. Mods run unsandboxed, with your permissions, and modscode does not vouch for what this code does. Read the code below (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
Its repository is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:
/plugin marketplace add mishgoldenberg/claude-mods/plugin install usage-meter@claude-modsThis installs the marketplace's latest commit, which may not be the one read here (6949e8dde6af). Compare them before you install.
Ask Claude about it
With the modscode connector added, Claude can read this design, what its code reaches and its code, and build on them. Ask it like this:
Read the modscode design "mishgoldenberg-usage-meter" with its code and make me a pane like itSearch them from Claude: the MCP connector
Similar designs
-
Ask Claude…Files⋯│●./file-name.tsx│●./file-name.tsx│●./file-name.tsxNew file Move to Recycle Bin?────────./menu-item.tsx./menu-item.tsx./menu-item.tsx────────./menu-item.tsx./menu-item.tsx./menu-item.tsx────────./menu-item.tsx./menu-item.tsx./menu-item.tsx
-
Ask Claude…IssuesChoose a repositoryBackRefresh open⠋Refreshing…This session● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appalex● buildacme/app● buildacme/app● buildacme/appPress Enter to open Refresh.
-
Ask Claude…secret-broker: waiting for Use savedSecret neededUse savedUse savedUse saved▌ THE LOG REQUIRES A SECRETUse savedClaude never sees the value. It goes to this one command, then it is gone.the command, exactly as it will runnpm test◯ build ▶ paste it here, press Enter. the log is watching. feed◯ build ▶ paste it here, press Enter. the log is watching. feed! Secret needed◉ the log remembers these for this session◯ build ▶ paste it here, press Enter. the log is watching. feedthe log waits for: Use saved n
-
Ask Claude…2h 10m · █████░░░✓ build ✓ build ✓ buildJavaKotlin3 Python■ ok 3 ■ ok 3 ■ ok 3 Razor proven 3 Razor proven 3 Razor proven 3Phases ──────── 3/3build Pythonbuild Pythonbuild Python… 3 more phasesLua ──────── 3/Kotlin■ the whole upgrade Ruby■ build build Ruby■ build build Ruby■ build build Ruby … 3 moreNext ──────── PythonRuby (by hand)Podsclick a button, or ctrl+x tab then Tab, EnterAttention ──────── 3! Scala ! Scala ! Scala … 3 moreSession ──────── okJava
-
Ask Claude…great_cto: 3 gate waiting — /gatesGatesmy-app · 3 waiting · checked Gates UTCGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approve
-
Ask Claude…agent-discoverbuildbuildbuildRefreshMCP Browse/3Tab / shift+Tab move · Enter presses · ↑↓ scroll · Esc back to the promptBrowse...Audit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancel