modscode / Gallery / usage-hud
usage-hud
输入框下方的用量面板:会按工具做动作的像素小螃蟹 + 三列对齐的模型/用量/状态网格(Windows / macOS / Linux)
What it does
- Draws a band above the prompt, toasts
- Adds /hud
- Watches tool calls
- Hooks classic.SessionStart, session.measure, session.start, turn.complete and 2 more
- Keeps its own state between turns
Good points
- No network calls
- Written in TypeScript
- Has a desktop-specific branch
- Handles errors
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-hud by Ronan (band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/ronanworks-usage-hud/
// 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 band above the prompt; what else goes there is drawn under it
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const { Box, Svg } = $.ui.resolve(e)
const crab = '…'
const dash = '…'
const pct = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" alignItems="center" columnGap={2}>
<Box flexShrink={0}>
<Svg source={`${crab}`} alt="用量面板的小螃蟹" />
</Box>
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Svg source={`${dash}`} alt={`上下文 ${pct}%,5小时 ${pct}%,本周 ${pct}%`} />
</Box>
</Box>
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const err = '…'
await $.ui.toast(`已打开项目文件夹`)
await $.ui.toast(`打开失败: ${err}`)
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.
usage-hud/hooks/register.tsx lines 1413–1429 · Band
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (layout === 'off' || e.props.hasSurvey) return next(e)
if (e.surface === 'desktop') {
const els: any = $.ui.resolve(e)
return buildDesktop($, els, e.props.bodyColumns ?? 100, !!e.props.isWorking)
}
if (e.surface !== 'terminal' || position !== 'above') return next(e)
const els: any = $.ui.resolve(e)
const { Box, Text } = els
const view = await buildView($, els, e.surface, e.props.bodyColumns ?? 100, !!e.props.isWorking)
return (
<Box flexDirection="column">
<Text key="gap"> </Text>
{view}
</Box>
)
})usage-hud/hooks/register.tsx lines 912–979 · Band
async function buildDesktop($: any, els: any, cols: number, working: boolean) {
const { Box, Svg } = els
const s = await snapshot($, working)
const reset = (l?: Limit) => (l?.resetsAt ? durShort(Date.parse(l.resetsAt) - Date.now()) + ' 后重置' : '')
const ag = agentsNow ? ` +${agentsNow} 个子代理` : ''
// 客户端只显示到分钟: 每秒变一次会让图片每秒重换一次
const ran = s.now - turnStartedAt
const status: DashData['status'] = working
? { text: toolLabel(currentTool) + (ran >= 60_000 ? ' ' + durShort(ran) : '') + ag, tone: 'work' }
: agentsNow
? { text: agentsNow + ' 个子代理在跑', tone: 'agents' }
: lastTurnMs
? { text: '✓ 上一轮 ' + dur(lastTurnMs) + ',' + lastTurnTools + ' 次工具', tone: 'idle' }
: { text: '✓ 待命', tone: 'idle' }
const top = Object.entries(toolCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 3)
.map(([t, n]) => shortTool(t) + ' ' + n)
.join(' ')
const counted = tokState === 'ready' || tokState === 'failed'
const data: DashData = {
model: prettyModel(modelId),
effort,
project: project || '--',
branch: branch ? branch + (dirty ? ' *' + dirty : '') : '',
session: dur(s.now - (s.u.startedAt ?? s.now)),
cost: s.u.cost ? '$' + s.u.cost.usd.toFixed(2) : '',
ctx: { pct: s.pct, extra: tok(s.ctxTokens) + ' / ' + tok(s.ctxWindow) },
five: { pct: s.five?.percentUsed, extra: reset(s.five) },
week: { pct: s.week?.percentUsed, extra: reset(s.week) },
status,
tools: top,
tokenTotal: counted ? big(tokTotal(s.tk)) : '统计中..',
tokenOutput: counted ? big(s.tk.output) : '',
}
const sc = s.scene
// 可用宽度: 横栏格数 x 每格像素, 减去螃蟹和间距; 太窄就只放一行用量条
lastDesktopCols = cols
const crabScale = 5
const crabW = 16 * crabScale
// 估计的可用宽度; 故意多画 5% + 20 像素, 让客户端总是把它等比缩到正好贴满卡片, 右边缘和卡片对齐
const est = Math.round((cols || 100) * DESKTOP_PX_PER_COL) - crabW - 15
const dashW = Math.max(340, Math.min(1040, Math.round(est * 1.05) + 20))
const compact = layout === 'compact' || est < 380
// 螃蟹直接画在卡片上 (没有底板/边框); 当普通图片显示, SMIL 动画照样会动, 必须给明确宽高
const crab = crabSvg(
{
mode: sc.celebrating ? 'celebrate' : working ? 'work' : sc.sleeping ? 'sleep' : 'idle',
kind: sc.kind,
heat: lastPct >= 95 ? 'crit' : lastPct >= 80 ? 'hot' : 'ok',
agents: Math.min(3, agentsNow),
},
compact ? 3 : crabScale,
)
const crabSize = compact ? { w: 48, h: 21 } : { w: crabW, h: 7 * crabScale }
const dash = dashSvg(data, { compact, width: dashW })
return (
<Box key="hud-d-row" flexDirection="row" alignItems="center" columnGap={2}>
<Box key="hud-d-crab" flexShrink={0}>
<Svg key="crab-svg" source={crab} alt="用量面板的小螃蟹" width={crabSize.w} height={crabSize.h} />
</Box>
{/* 估计的宽度偏大时, 这个容器允许仪表盘等比缩小, 不会被截断 */}
<Box key="hud-d-dash" flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Svg key="dash-svg" source={dash} alt={`上下文 ${data.ctx.pct ?? '--'}%,5小时 ${data.five.pct ?? '--'}%,本周 ${data.week.pct ?? '--'}%`} />
</Box>
</Box>
)
}Licence text (MIT)
MIT License Copyright (c) 2026 Ronan 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
runs programsreads filesenv varsdrives Claudetool callsremembers
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 e3330546eb4a 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.usage-hud/hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.2 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, with its own branch for the desktop |
| 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.usage-hud/hooks/register.tsx:651 a program named at run time; usage-hud/hooks/register.tsx:693 cmd.exe (a shell or interpreter); usage-hud/hooks/register.tsx:696 powershell.exe (a shell or interpreter); usage-hud/hooks/register.tsx:715 cmd.exe (a shell or interpreter); usage-hud/hooks/register.tsx:809 node (a shell or interpreter) |
| Reads and sends | Whether it both reads files or environment variables and reaches the network.reads environment variables and files and reaches the 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 ronanworks/claude-code-mods/plugin install usage-hud@claude-code-modsThis installs the marketplace's latest commit, which may not be the one read here (e3330546eb4a). 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 "ronanworks-usage-hud" with its code and make me a pane like itSearch them from Claude: the MCP connector
Similar designs
-
▴Token OptimizerCheckpointCheckpointCheckpointbuildStart freshbuildStart freshbuildStart freshbuildCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointbuildbuildbuildTokens savedSaved Clean up tokens in 30 days (chat 2 this session)Ask Claude…
-
plan-progress is on. A bar appears when Claude starts a task with several steps.Ask Claude…
-
Ask Claude…Fix loginRemoveCopy markdownacme/app · mainCopy linkCopy markdownbuild2h 10mbuild2h 10mbuild2h 10mHosted on uploads.sh, not committed to the repo.They will appear in a comment on the pull request once opened.
-
What it does
- Draws a band above the prompt, a pane
- Adds /progress
- Watches tool calls and can refuse them
- Hooks classic.SessionStart, prompt.compose, prompt.submit, session.start and 2 more
-
pixel-pet: your theme no longer reads (3). Showing the slime.Ask Claude…pixel-pet:
-
Contextchat 2Context42%Agentbuild42%Agentbuild42%Agentbuild42%Agent· Weekly· Weekly· Weekly⏳ AgentContext⏳ AgentContext⏳ Agent+3 more agents runningContextAsk Claude…