ModsCode / Claude Code Mods / Ranking / token-ledger
token-ledger
Your 5-hour, weekly, context and cache-hit figures as one line above the prompt, a ? button that asks Haiku 5.5 for questions to ask next, and a /ledger pane with subagent shares. Percentages only, no money.
What it does
- Draws a band above the prompt, a pane, toasts
- Adds /ledger, /ask
- Watches tool calls and can refuse them
- Hooks session.end, session.start, turn.complete, turn.step
- Keeps its own state between turns
Good points
- No network calls
- Written in TypeScript
- Handles errors
- Writes no files
Code to start from
A starter ModsCode writes from the drawing it read, and the mod's own lines that draw, where there are any.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like token-ledger by claude-code-mods contributors (pane, band, status, toast), as ModsCode read it from the mod's code:
// https://modscode.com/claude-mods/mods/bully911210-token-ledger/
// 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, Text, Button } = $.ui.resolve(e)
const GLYPHS = '…'
const value = '…'
const label = '…'
const GLYPHS2 = '…'
const value2 = '…'
const label2 = '…'
const GLYPHS3 = '…'
const value3 = '…'
const label3 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" alignItems="center" justifyContent="space-between">
<Box flexDirection="row" alignItems="center" flexWrap="nowrap" overflow="hidden">
<Box flexDirection="row" alignItems="center" flexShrink={0}>
<Text>
{GLYPHS}
</Text>
<Text>
{" "}
{value}
</Text>
<Text color="inactive">
{" "}
{label}
</Text>
</Box>
<Box flexDirection="row" alignItems="center" flexShrink={0}>
<Text>
{GLYPHS2}
</Text>
<Text>
{" "}
{value2}
</Text>
<Text color="inactive">
{" "}
{label2}
</Text>
</Box>
<Box flexDirection="row" alignItems="center" flexShrink={0}>
<Text>
{GLYPHS3}
</Text>
<Text>
{" "}
{value3}
</Text>
<Text color="inactive">
{" "}
{label3}
</Text>
</Box>
</Box>
<Box flexDirection="row" alignItems="center" position="relative" marginLeft={2}>
<Button plain label="…" />
<Box position="absolute" bottom={1} right={0} display="none" paddingX={1} borderStyle="round" borderDimColor>
<Text dimColor wrap="truncate">
Haiku is thinking…
</Text>
</Box>
</Box>
</Box>
{await next(e)}
</Box>
)
})
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Questions worth asking" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text } = $.ui.resolve(e)
const resetsLabel = '…'
const ctx = '…'
const turns = '…'
const compact = '…'
const compact2 = '…'
const compact3 = '…'
const compact4 = '…'
const compact5 = '…'
const length = '…'
const agentTotal = '…'
const type = '…'
const id = '…'
const calls = '…'
const compact6 = '…'
const shareOf = '…'
const ago = '…'
const type2 = '…'
const id2 = '…'
const calls2 = '…'
const compact7 = '…'
const shareOf2 = '…'
const type3 = '…'
const id3 = '…'
const calls3 = '…'
const compact8 = '…'
const shareOf3 = '…'
const turns2 = '…'
const compact9 = '…'
const length2 = '…'
const misses = '…'
const toLocaleTimeString = '…'
const gapMinutes = '…'
const ttl = '…'
const compact10 = '…'
const toLocaleTimeString2 = '…'
const gapMinutes2 = '…'
const ttl2 = '…'
const compact11 = '…'
const toLocaleTimeString3 = '…'
const gapMinutes3 = '…'
const ttl3 = '…'
const compact12 = '…'
const toLocaleTimeString4 = '…'
const input = '…'
const cacheRead = '…'
const cacheWrite = '…'
const compact13 = '…'
const durationMs = '…'
const toLocaleTimeString5 = '…'
const compact14 = '…'
const durationMs2 = '…'
const toLocaleTimeString6 = '…'
const compact15 = '…'
const durationMs3 = '…'
return (
<Box flexDirection="column">
<Text bold>
Limits
</Text>
<Text>
{"5-hour "}
no reading
{` · resets ${resetsLabel}`}
{" · week "}
no reading
{" · context "}
{ctx}
%
</Text>
<Text>
{" "}
</Text>
<Text bold>
This session
</Text>
<Text>
{turns}
{" turns · "}
{compact}
{" tokens · cache hit "}
n/a
</Text>
<Text dimColor>
{"in "}
{compact2}
{" · out "}
{compact3}
{" · cache read "}
{compact4}
{" · cache write"}
{" "}
{compact5}
</Text>
<Text>
{" "}
</Text>
<Text bold>
Subagents
</Text>
<Text>
{length}
{" this session · about "}
{agentTotal}
% of the session's usage
</Text>
<Text>
✓
{" "}
{type}
{" · "}
{id}
{" · "}
?
{" · "}
{calls}
{" calls ·"}
{" "}
{compact6}
{" tokens · "}
{shareOf}
{" · "}
{`done ${ago}`}
</Text>
<Text>
✓
{" "}
{type2}
{" · "}
{id2}
{" · "}
?
{" · "}
{calls2}
{" calls ·"}
{" "}
{compact7}
{" tokens · "}
{shareOf2}
{" · "}
{`done ${ago}`}
</Text>
<Text>
✓
{" "}
{type3}
{" · "}
{id3}
{" · "}
?
{" · "}
{calls3}
{" calls ·"}
{" "}
{compact8}
{" tokens · "}
{shareOf3}
{" · "}
{`done ${ago}`}
</Text>
<Text>
{" "}
</Text>
<Text bold>
Last 7 days
</Text>
<Text>
{turns2}
{" turns · "}
{compact9}
{" tokens"}
</Text>
<Text>
{" "}
</Text>
<Text bold>
Cache rewrites after idle
</Text>
<Text>
{length2}
{" this session · "}
{misses}
{" in 7 days"}
</Text>
<Text dimColor>
{toLocaleTimeString}
{" · idle "}
{gapMinutes}
{" min ("}
{ttl}
{") · "}
{compact10}
{" tokens rewritten"}
</Text>
<Text dimColor>
{toLocaleTimeString2}
{" · idle "}
{gapMinutes2}
{" min ("}
{ttl2}
{") · "}
{compact11}
{" tokens rewritten"}
</Text>
<Text dimColor>
{toLocaleTimeString3}
{" · idle "}
{gapMinutes3}
{" min ("}
{ttl3}
{") · "}
{compact12}
{" tokens rewritten"}
</Text>
<Text>
{" "}
</Text>
<Text bold>
Recent turns
</Text>
<Text dimColor>
No turns yet.
</Text>
<Text dimColor>
{toLocaleTimeString4}
{" · in "}
{`${input}${cacheRead}${cacheWrite}`}
{" · out"}
{" "}
{compact13}
{" · "}
{durationMs}
s
</Text>
<Text dimColor>
{toLocaleTimeString5}
{" · in "}
{`${input}${cacheRead}${cacheWrite}`}
{" · out"}
{" "}
{compact14}
{" · "}
{durationMs2}
s
</Text>
<Text dimColor>
{toLocaleTimeString6}
{" · in "}
{`${input}${cacheRead}${cacheWrite}`}
{" · out"}
{" "}
{compact15}
{" · "}
{durationMs3}
s
</Text>
</Box>
)
})
on('session.start', async ($, e, next) => {
const description = '…'
const points = '…'
const gapMinutes = '…'
const compact = '…'
await $.ui.toast(`Subagent "${description}" has used about ${points}% of your 5-hour limit.`)
await $.ui.toast(`Cache expired after ${gapMinutes} min idle: ${compact} tokens rewritten.`)
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.
token-ledger/hooks/register.tsx lines 494–538 · Band
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const now = await $.clock.now()
if (e.props.hasSurvey) return next(e)
const f = await furnaceNow($, cfg, now)
const session = await read($, sessionAtom)
const hasContext = session.turns > 0 || f.five >= 0
const els = $.ui.resolve(e)
const insights = await read($, insightsAtom)
const row = telemetryTree(
els,
{
fivePercent: f.five,
ratePerMin: f.rate,
resetsAt: f.resetsAt,
now,
weekPercent: f.week,
contextPercent: hasContext ? await read($, contextAtom) : null,
cacheHit: cacheHitPercent(session.usage),
model: await $.session.model(),
effort: await read($, effortAtom),
},
Math.max(20, (e.props.bodyColumns ?? 80) - 6),
)
const ask = askButton(els, insights.status, () => {
void runInsights($)
})
const { Box } = els
const bar = (
<Box key="bar" flexDirection="row" alignItems="center" justifyContent="space-between">
{row}
{ask}
</Box>
)
const questions =
insights.inBand && insights.status !== 'idle'
? insightsPane(els, insights, e.props.bodyColumns ?? 80, insightHandlers($))
: undefined
if (questions === undefined) return bar
return (
<Box flexDirection="column">
{questions}
{bar}
</Box>
)
})token-ledger/hooks/telemetry.tsx lines 128–165 · Band
export const telemetryTree = (els: Table, d: TelemetryData, columns: number) => {
const { Box, Text } = els
const { groups, sep } = fitGroups(buildGroups(d), columns)
const pad = sep === SEP_WIDE ? 2 : 1
return (
<Box flexDirection="row" alignItems="center" flexWrap="nowrap" overflow="hidden">
{groups.flatMap((g, i) => {
const parts = [
<Box key={`g-${g.key}`} flexDirection="row" alignItems="center" flexShrink={0}>
{hasIcon(g) ? (
<Text key={`i-${g.key}`} color={g.iconTheme}>
{GLYPHS[g.icon]}
</Text>
) : null}
<Text key={`v-${g.key}`} {...(g.valueColor ? { color: g.valueColor } : { color: 'text' })} bold={g.isBold === true}>
{hasIcon(g) ? ' ' : ''}
{g.value}
</Text>
{g.label ? (
<Text key={`l-${g.key}`} color="inactive">
{' '}
{g.label}
</Text>
) : null}
</Box>,
]
if (i < groups.length - 1) {
parts.push(
<Text key={`s-${g.key}`} color="subtle" dimColor>
{' '.repeat(pad)}│{' '.repeat(pad)}
</Text>,
)
}
return parts
})}
</Box>
)
}token-ledger/hooks/insightsView.tsx lines 36–45 · Band
export const askButton = (els: Table, status: InsightStatus, onPress: () => void) => {
const { Box, Button } = els
const isBusy = status === 'loading'
return (
<Box key="ask-scope" flexDirection="row" alignItems="center" position="relative" marginLeft={2}>
<Button key="ask" plain dimColor={isBusy} label={isBusy ? '…' : '?'} onPress={onPress} />
{tooltip(els, isBusy)}
</Box>
)
}token-ledger/hooks/insightsView.tsx lines 24–33 · Band
const tooltip = (els: Table, isBusy: boolean) => {
const { Box, Text } = els
return (
<Box position="absolute" bottom={1} right={0} display="none" hover={{ display: 'flex' }} paddingX={1} borderStyle="round" borderDimColor>
<Text dimColor wrap="truncate">
{isBusy ? 'Haiku is thinking…' : TOOLTIP}
</Text>
</Box>
)
}token-ledger/hooks/register.tsx lines 552–567 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const resetsAt = await read($, resetsAtAtom)
return paneTree($.ui.resolve(e), {
session: await read($, sessionAtom),
week: await read($, weekAtom),
misses: await read($, missesAtom),
recent: await read($, recentAtom),
agents: await read($, agentsAtom),
ctx: await read($, contextAtom),
five: await read($, fiveHourAtom),
weekPercent: await read($, weekPercentAtom),
resetsLabel: resetsAt ? new Date(resetsAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : '',
rows: e.viewport?.rows ?? 30,
now: await $.clock.now(),
})
})token-ledger/hooks/views.tsx lines 37–101 · Pane
export const paneTree = (els: Pick<Table, 'Box' | 'Text'>, d: PaneData) => {
const { Box, Text } = els
const s = d.session
const hit = cacheHitPercent(s.usage)
const agentTotal = d.agents.reduce((sum, a) => sum + liveCost(a), 0)
const sessionTotal = Math.max(0.000001, s.costUsd + d.agents.reduce((sum, a) => sum + a.pendingUsd, 0))
const shareOf = (a: LedgerAgent): string => `${Math.round((liveCost(a) / sessionTotal) * 100)}%`
const room = Math.max(3, d.rows - 24)
return (
<Box flexDirection="column">
<Text bold>Limits</Text>
<Text>
5-hour {d.five < 0 ? 'no reading' : `${pct(d.five)}%`}
{d.resetsLabel ? ` · resets ${d.resetsLabel}` : ''} · week {d.weekPercent < 0 ? 'no reading' : `${pct(d.weekPercent)}%`} · context {d.ctx}%
</Text>
<Text> </Text>
<Text bold>This session</Text>
<Text>
{s.turns} turns · {compact(tokensOf(s.usage))} tokens · cache hit {hit === null ? 'n/a' : `${hit}%`}
</Text>
<Text dimColor>
in {compact(s.usage.input)} · out {compact(s.usage.output)} · cache read {compact(s.usage.cacheRead)} · cache write{' '}
{compact(s.usage.cacheWrite)}
</Text>
<Text> </Text>
<Text bold>Subagents</Text>
<Text>
{d.agents.length} this session · about {Math.round((agentTotal / sessionTotal) * 100)}% of the session's usage
</Text>
{[...d.agents]
.sort((x, y) => liveCost(y) - liveCost(x))
.slice(0, 5)
.map(a => (
<Text key={`agent-${a.id}`} {...(isDone(a.status) ? { dimColor: true } : { color: '#378ADD' })}>
{isDone(a.status) ? '✓' : '▶'} {a.type} · {a.description || a.id.slice(0, 8)} · {shortModel(a.model)} · {a.calls} calls ·{' '}
{compact(tokensOf(a.usage))} tokens · {shareOf(a)} · {isDone(a.status) ? `done ${ago(d.now, a.endedAt ?? d.now)}` : a.tool || 'thinking'}
</Text>
))}
<Text> </Text>
<Text bold>Last 7 days</Text>
<Text>
{d.week.turns} turns · {compact(tokensOf(d.week.usage))} tokens
</Text>
<Text> </Text>
<Text bold>Cache rewrites after idle</Text>
<Text>
{d.misses.length} this session · {d.week.misses} in 7 days
</Text>
{d.misses.slice(-3).map(x => (
<Text key={`miss-${x.at}`} dimColor>
{new Date(x.at).toLocaleTimeString()} · idle {x.gapMinutes} min ({x.ttl}) · {compact(x.tokensRewritten)} tokens rewritten
</Text>
))}
<Text> </Text>
<Text bold>Recent turns</Text>
{d.recent.length === 0 && <Text dimColor>No turns yet.</Text>}
{d.recent.slice(-room).map(t => (
<Text key={`turn-${t.at}`} dimColor>
{new Date(t.at).toLocaleTimeString()} · in {compact(t.usage.input + t.usage.cacheRead + t.usage.cacheWrite)} · out{' '}
{compact(t.usage.output)} · {Math.round(t.durationMs / 1000)}s
</Text>
))}
</Box>
)
}Licence text (MIT)
MIT License Copyright (c) 2026 bully911210 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.
How to build this: Pane (panel), Deny a tool call
What its code calls
runs programsreads filesdrives Claudetool callsremembers
What its code shows
Read from the source at commit bf4e5297845d. 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.token-ledger/hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.9 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.git (reaches the network) |
| Reads and sends | Whether it both reads something of yours (files, environment variables, the transcript, settings) and reaches outside (the network, an MCP server, another session, telemetry).reads files, the transcript, the prompt box 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 |
| Settings hooks | Hooks declared in hooks/hooks.json or plugin.json beside the module: a command (a shell when it has no args), an HTTP request, an MCP tool or a model prompt at an event. They run outside $.no settings hooks: its function hooks alone |
| Servers it ships | MCP servers (a program, or a URL; a headersHelper is a shell command; a .mcpb bundle is unpacked at run time), LSP servers, monitors (a shell command for the whole session) and bin/ (on the PATH of the Bash tool).ships no MCP or LSP server, no monitor, no bin/ |
| Skills, commands, agents | What its Markdown declares beyond text: allowed-tools granted for the turn, hooks added when a skill is invoked, a command run before Claude reads the skill.no skills, commands, agents or workflows |
| Tools and MCP | Whether every tool it calls through $.tool.call and $.mcp.call is named in the code, and none is a shell (Bash through the tool runs a shell without $.process).calls no tool, MCP server or command |
| Asks of the model | Completions it runs ($.model.complete, fork, classify), subagents it spawns, prompts it submits as you, and the tools, commands and agents it adds.model.complete, adds command ledger, adds command ask |
| Events it hooks | By what a hook there can do: gates (refuse a tool call, a prompt, a setting, another plugin), shapes (what the model reads: the system prompt, tool descriptions, each request), reads (your input, the events of the settings hooks, every event with *), and the rest.gates: tool.call, command.run (ledger, ask) · shapes: turn.step · also: session.start, session.end, turn.complete, ui.render (AbovePrompt, Pane) · timers: clock.every |
| Reads, by name | The environment variables and files it names, and whether it reads the transcript, settings.json, the prompt box or the mouse selection.files: CLAUDE.md-like files above the project; the transcript; the prompt box |
| Writes, by name | The files and environment variables it names, and whether it changes settings, the prompt box, the clipboard, the conversation (a row the model reads) or another session.the prompt box |
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 its code (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
From its marketplace
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 bully911210/claude-code-mods/plugin install token-ledger@claude-code-mods/reload-pluginsThis installs the marketplace's latest commit, which may not be the one read here (bf4e5297845d). Compare them before you install. /reload-plugins loads it into a session that is already open.
Try the commit ModsCode read
No marketplace needed. In a terminal, clone the repository, check out the commit read, validate the mod, and load it for one session:
git clone https://github.com/bully911210/claude-code-modsgit -C claude-code-mods checkout bf4e5297845df85e7c678260c8a2b8e3734120a6claude plugin validate claude-code-mods/token-ledgerclaude --plugin-dir claude-code-mods/token-ledgerThe validate line lists the events the mod hooks and what it asks Claude Code to do, without running it. The last line loads the mod for this session only and writes nothing to your settings. If the author has rewritten history, the commit may no longer exist.
Ask Claude or ChatGPT about it
With ModsCode added as a connector, Claude or ChatGPT can read this mod's code, what it reaches and how its controls are wired, and build on them. Ask it like this:
Read the ModsCode mod "bully911210-token-ledger" with its code and make me one like itAdd the ModsCode MCP to Claude or ChatGPT
Similar mods
- code-modernizationAnthropic★ 37,809
- crit-tuiTomasz Tomczyk★ 1,205
- remctlFederico Viticci★ 595
- task-orchestrator-modJeff Picklyk★ 208
- localvoxtral-modlocalvoxtral★ 59
- localvoxtral-remotelocalvoxtral★ 59
More from this repository
Badge for your README
If this is your mod, paste this into your README. It links to this page.
[](https://modscode.com/claude-mods/mods/bully911210-token-ledger/)