modscode / Gallery / tokenscope
tokenscope
Live token & USD observatory for Claude Code: per agent, subagent, workflow, task, skill and model, with prompt-cache countdowns, a model lock while the cache is warm, and subscription leverage
What it does
- Draws a pane, a band above the prompt, the status line, toasts
- Adds /effort, /model, /tokenscope
- Watches tool calls and can refuse them
- Hooks agent.spawn, session.end, session.measure, session.start and 4 more
- Keeps its own state between turns
Good points
- No network calls
- Starts no processes
- Written in TypeScript
- 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 tokenscope by Moaaz Homaid (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/moaazhomaid-tokenscope/
// 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: "TokenScope" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Button } = $.ui.resolve(e)
const fmtDuration = '…'
const requests = '…'
const agentCount = '…'
const fmtUsd = '…'
const fmtUsd2 = '…'
const fmtUsd3 = '…'
const modelName = '…'
const effort = '…'
const fmtTok = '…'
const fmtTok2 = '…'
const bar = '…'
const pctFull = '…'
const fmtUsd4 = '…'
const fmtUsd5 = '…'
const mmss = '…'
const bar2 = '…'
const modelName2 = '…'
const efforts = '…'
const warmCount = '…'
const fmtTok3 = '…'
const fmtUsd6 = '…'
const lock = '…'
const bar3 = '…'
const modelName3 = '…'
const efforts2 = '…'
const warmCount2 = '…'
const fmtTok4 = '…'
const fmtUsd7 = '…'
const lock2 = '…'
const bar4 = '…'
const modelName4 = '…'
const efforts3 = '…'
const warmCount3 = '…'
const fmtTok5 = '…'
const fmtUsd8 = '…'
const lock3 = '…'
const label = '…'
const i = '…'
return (
<Box flexDirection="column" gap={1}>
<Box flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text bold color="#a78bfa">
◆ T O K E N S C O P E
</Text>
<Text color="#64748b">
{fmtDuration}
{" · "}
{requests}
{" req · "}
{agentCount}
{" subagents"}
</Text>
</Box>
<Box flexDirection="row" gap={2} flexWrap="wrap">
<Text bold color="#facc15">
{fmtUsd}
</Text>
<Text color="#64748b">
API-equivalent
</Text>
<Text>
{"↯ "}
{fmtUsd2}
/h burn
</Text>
<Text color="#64748b">
{"/cost ledger "}
{fmtUsd3}
</Text>
</Box>
<Box flexDirection="row" columnGap={1} flexWrap="wrap">
<Text color="#64748b">
▶ NOW
</Text>
<Text bold>
{modelName}
</Text>
<Text color="#64748b">
{`effort ${effort}`}
</Text>
<Box flexDirection="row" columnGap={1}>
<Text color="#64748b">
│ ctx
</Text>
<Text>
{fmtTok}
/
{fmtTok2}
</Text>
<Text>
{bar}
</Text>
<Text bold>
{pctFull}
%
</Text>
</Box>
<Box flexDirection="row" columnGap={1}>
<Text color="#64748b">
│ next request
</Text>
<Box flexDirection="row" columnGap={1}>
<Text color="#34d399" bold>
≈
{fmtUsd4}
</Text>
<Text color="#64748b">
{"warm · "}
{fmtUsd5}
{" if cold"}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="column">
<Box flexDirection="row" columnGap={1}>
<Text bold>
{`⏱${mmss}`}
</Text>
<Text>
{bar2}
</Text>
<Text bold>
{modelName2}
</Text>
<Text color="#64748b">
{efforts}
</Text>
<Text color="#e2e8f0">
{warmCount}
</Text>
<Text color="#64748b">
{"· "}
{fmtTok3}
{" tok · keeping it warm saves "}
{fmtUsd6}
{lock}
</Text>
</Box>
<Box flexDirection="row" columnGap={1}>
<Text bold>
{`⏱${mmss}`}
</Text>
<Text>
{bar3}
</Text>
<Text bold>
{modelName3}
</Text>
<Text color="#64748b">
{efforts2}
</Text>
<Text color="#e2e8f0">
{warmCount2}
</Text>
<Text color="#64748b">
{"· "}
{fmtTok4}
{" tok · keeping it warm saves "}
{fmtUsd7}
{lock2}
</Text>
</Box>
<Box flexDirection="row" columnGap={1}>
<Text bold>
{`⏱${mmss}`}
</Text>
<Text>
{bar4}
</Text>
<Text bold>
{modelName4}
</Text>
<Text color="#64748b">
{efforts3}
</Text>
<Text color="#e2e8f0">
{warmCount3}
</Text>
<Text color="#64748b">
{"· "}
{fmtTok5}
{" tok · keeping it warm saves "}
{fmtUsd8}
{lock3}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="row" gap={1} flexWrap="wrap">
<Button label={`${label}`} hotkey={`${i}`} variant="primary" />
<Button label={`${label}`} hotkey={`${i}`} variant="primary" />
<Button label={`${label}`} hotkey={`${i}`} variant="primary" />
</Box>
</Box>
)
})
// the band above the prompt; what else goes there is drawn under it
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const { Box, Text } = $.ui.resolve(e)
const text = '…'
const text2 = '…'
const text3 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row">
<Text>
{text}
</Text>
<Text>
{text2}
</Text>
<Text>
{text3}
</Text>
</Box>
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const head = '…'
const cacheBadge = '…'
const fmtUsd = '…'
const ctx = '…'
const pct = '…'
const target = '…'
await $.ui.status(`${head}${cacheBadge} · ${fmtUsd}${ctx} · hit ${pct}`)
await $.ui.toast(`⏱ `)
await $.ui.toast(`🔁 Cache cooled: switching to ${target} as you asked`)
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/tokenscope/hooks/register.tsx lines 1251–1310 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const ui = $.ui.resolve(e)
const { Box, Text, Button } = ui
const l = await read($, ledger)
const v = await read($, view)
const c = await read($, cache)
const now = await $.clock.now()
const W = Math.max(36, e.props.bodyColumns - 1)
const elapsedH = Math.max(1 / 60, (now - l.startedAt) / 3_600_000)
const perHour = l.totals.usd / elapsedH
const agentCount = Object.values(l.agents).filter(a => a.kind === 'subagent').length
const room = Math.max(4, (e.viewport?.rows ?? 30) - 12)
const groups = buildGroups(l, c, now)
let body
if (v.tab === 'agents') body = Agents(ui, l, W, now)
else if (v.tab === 'tasks') body = Tasks(ui, l, W, now, room)
else if (v.tab === 'skills') body = Skills(ui, l, W)
else if (v.tab === 'models') body = ModelCards(ui, groups, l, c, now, W)
else if (v.tab === 'plan') body = Plan($, ui, l, v, W, now)
else if (v.tab === 'cache') body = CacheTab($, ui, c, W, now, groups)
else body = Overview(ui, l, W, ByModel(ui, groups, l, c, now, W))
return (
<Box flexDirection="column" gap={1}>
<Box flexDirection="column">
<Box flexDirection="row" justifyContent="space-between">
<Text bold color={C.brand}>
◆ T O K E N S C O P E
</Text>
<Text color={C.dim}>
{fmtDuration(now - l.startedAt)} · {l.totals.requests} req · {agentCount} subagents
</Text>
</Box>
<Box flexDirection="row" gap={2} flexWrap="wrap">
<Text bold color={C.usd}>
{fmtUsd(l.totals.usd)}
</Text>
<Text color={C.dim}>API-equivalent</Text>
<Text color={heat(perHour / 4)}>↯ {fmtUsd(perHour)}/h burn</Text>
{v.engineUsd !== null && <Text color={C.dim}>/cost ledger {fmtUsd(v.engineUsd)}</Text>}
</Box>
{NowLine(ui, l, v, c, now, W)}
{ModelStrip(ui, groups, l, c, now, W)}
</Box>
<Box flexDirection="row" gap={1} flexWrap="wrap">
{TABS.map(([tab, label], i) => (
<Button
key={`tab-${tab}`}
label={label}
hotkey={String(i + 1)}
variant={v.tab === tab ? 'primary' : 'secondary'}
onPress={() => update($, view, x => ({ ...x, tab }))}
/>
))}
</Box>
{body}
</Box>
)
})plugins/tokenscope/hooks/models.tsx lines 98–151 · Pane
export function NowLine(ui: Kit, l: Ledger, v: View, c: CacheState, now: number, W: number) {
const { Box, Text } = ui
const n = l.now
if (!n?.model) return <Text color={C.dim}>▶ NOW waiting for the first request…</Text>
const r = rateFor(n.model)
const ctx = v.context
const pctFull = ctx?.percent ?? 0
const prefix = ctx?.tokens ?? c.main?.tokens ?? 0
const warm = c.main !== null && isWarm(c.main, now) && modelKey(c.main.model) === modelKey(n.model)
const warmCost = (prefix * r.cacheRead) / 1e6
const coldCost = (prefix * r.input * 1.25) / 1e6
const bw = W >= 100 ? 12 : 6
return (
<Box flexDirection="row" columnGap={1} flexWrap="wrap">
<Text color={C.dim}>▶ NOW</Text>
<Text bold color={familyColor(n.model)}>
{modelName(n.model)}
</Text>
<Text color={n.effort ? effortColor(n.effort) : C.dim}>{n.effort ? `effort ${n.effort}` : 'effort —'}</Text>
{ctx && ctx.tokens !== undefined && (
<Box flexDirection="row" columnGap={1}>
<Text color={C.dim}>│ ctx</Text>
<Text color={ctxColor(pctFull)}>
{fmtTok(ctx.tokens)}/{fmtTok(ctx.window)}
</Text>
<Text color={ctxColor(pctFull)}>{bar(pctFull / 100, bw).padEnd(bw, '·')}</Text>
<Text color={ctxColor(pctFull)} bold>
{pctFull}%
</Text>
</Box>
)}
{prefix > 0 && (
<Box flexDirection="row" columnGap={1}>
<Text color={C.dim}>│ next request</Text>
{warm ? (
<Box flexDirection="row" columnGap={1}>
<Text color={C.cr} bold>
≈{fmtUsd(warmCost)}
</Text>
<Text color={C.dim}>warm · {fmtUsd(coldCost)} if cold</Text>
</Box>
) : (
<Box flexDirection="row" columnGap={1}>
<Text color={C.cold} bold>
≈{fmtUsd(coldCost)}
</Text>
<Text color={C.dim}>re-writes the cache</Text>
</Box>
)}
</Box>
)}
</Box>
)
}plugins/tokenscope/hooks/models.tsx lines 155–206 · Pane
export function ModelStrip(ui: Kit, groups: Group[], l: Ledger, c: CacheState, now: number, W: number) {
const { Box, Text } = ui
const ttl = ttlMs(c.ttl)
const bw = W >= 100 ? 14 : 8
const shown = groups.filter(g => g.loops.length > 0 || g.isNow).slice(0, 4)
if (shown.length === 0) return <Text color={C.dim}>⏱ no prompt cache yet</Text>
return (
<Box flexDirection="column">
{shown.map(g => {
const w = g.warmest
const efforts = effortList(g, l)
const lock = g.hasMain && c.lock === 'on' && w ? ' 🔒' : ''
if (!w) {
const last = g.loops[0]?.w
return (
<Box flexDirection="row" columnGap={1}>
<Text color={C.cold} bold>
{lpad('❄', 6)}
</Text>
<Text color={C.cold}>{''.padEnd(bw, '·')}</Text>
<Text color={familyColor(g.model)} bold>
{pad(modelName(g.model), 11)}
</Text>
<Text color={C.dim}>{pad(efforts, 13)}</Text>
<Text color={C.dim}>
{last ? `cold for ${fmtDuration(now - last.expiresAt)} · next request re-writes ~${fmtTok(last.tokens)}` : 'no cache yet'}
</Text>
</Box>
)
}
const color = warmColor(w, now, ttl)
return (
<Box flexDirection="row" columnGap={1}>
<Text color={color} bold>
{lpad(`⏱${mmss(w.expiresAt - now)}`, 6)}
</Text>
<Text color={color}>{bar((w.expiresAt - now) / ttl, bw).padEnd(bw, '·')}</Text>
<Text color={familyColor(g.model)} bold>
{pad(modelName(g.model), 11)}
</Text>
<Text color={C.dim}>{pad(efforts, 13)}</Text>
<Text color={C.text}>{warmCount(g, now)}</Text>
<Text color={C.dim}>
· {fmtTok(w.tokens)} tok · keeping it warm saves {fmtUsd(keepWarmUsd(w))}
{lock}
</Text>
</Box>
)
})}
</Box>
)
}plugins/tokenscope/hooks/register.tsx lines 1312–1388 · Band
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const v = await read($, view)
const l = await read($, ledger)
if (e.props.hasSurvey || !v.band || (l.totals.requests === 0 && !l.now)) return next(e)
const { Box, Text } = $.ui.resolve(e)
const c = await read($, cache)
const now = await $.clock.now()
const ttl = ttlMs(c.ttl)
const t = l.totals
type Seg = [string, string, boolean?]
const segs: Seg[][] = []
// what runs now, and its cache
const n = l.now
const head: Seg[] = [['◆ ', C.brand]]
if (n?.model) {
head.push([modelName(n.model), familyColor(n.model), true])
head.push([n.effort ? `·${n.effort}` : '', n.effort ? effortColor(n.effort) : C.dim])
}
const m = c.main
if (m && isWarm(m, now)) {
head.push([` ⏱${mmss(m.expiresAt - now)}`, warmColor(m, now, ttl), true])
if (c.lock === 'on') head.push([' 🔒', C.dim])
} else if (m) {
head.push([' ❄ cold', C.cold, true])
}
if (c.queued) head.push([` 🔁 ${c.queued}`, C.usd])
segs.push(head)
// every other model with a warm cache, grouped
for (const g of buildGroups(l, c, now)) {
if (!g.warmest || (n?.model && modelKey(n.model) === g.key)) continue
segs.push([
[' │ ', C.dim],
[modelName(g.model), familyColor(g.model)],
[` ⏱${mmss(g.warmest.expiresAt - now)}`, warmColor(g.warmest, now, ttl)],
[g.loops.filter(x => isWarm(x.w, now)).length > 1 ? ` ×${g.loops.filter(x => isWarm(x.w, now)).length}` : '', C.dim],
])
}
segs.push([[' │ ', C.dim], [fmtUsd(t.usd), C.usd, true]])
const ctx = v.context
if (ctx?.percent !== undefined) segs.push([[' │ ctx ', C.dim], [`${ctx.percent}%`, ctxColor(ctx.percent), true]])
segs.push([[' │ in ', C.dim], [fmtTok(t.input), C.in]])
segs.push([[' c.wrt ', C.dim], [fmtTok(t.cacheWrite), C.cw]])
segs.push([[' c.read ', C.dim], [fmtTok(t.cacheRead), C.cr]])
segs.push([[' out ', C.dim], [fmtTok(t.output), C.out]])
segs.push([[' │ hit ', C.dim], [pct(hitRate(t)), C.save]])
const five = v.gauges.find(g => g.kind === 'five_hour')
if (five) {
const cells = Math.round(five.percentUsed / 20)
segs.push([
[' │ 5h ', C.dim],
['▰'.repeat(cells) + '▱'.repeat(5 - cells), gaugeColor(five.percentUsed)],
[` ${five.percentUsed}%`, gaugeColor(five.percentUsed)],
])
}
segs.push([[' │ /tokenscope', C.dim]])
let room = e.props.bodyColumns - 1
const shown: Seg[] = []
for (const g of segs) {
const w = g.reduce((sum, [text]) => sum + text.length, 0)
if (w > room) break
room -= w
shown.push(...g.filter(([text]) => text !== ''))
}
return (
<Box flexDirection="row">
{shown.map(([text, color, bold]) => (
<Text color={color} bold={bold === true}>
{text}
</Text>
))}
</Box>
)
})Licence text (MIT)
MIT License Copyright (c) 2026 Moaaz Homaid 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
tool 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 5826db47c443 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/tokenscope/hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.5 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 moaazhomaid/claude-plugins/plugin install tokenscope@moaazhomaidThis installs the marketplace's latest commit, which may not be the one read here (5826db47c443). 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 "moaazhomaid-tokenscope" with its code and make me a pane like itSearch them from Claude: the MCP connector
Similar designs
-
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
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Ask Claude…
-
Ask Claude…TodayOct 63 left · Mar overdueRemCTL: Sep✓ All done for today.● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓Updated 14:32UndoRefresh
-
Ask Claude…TO graph› Fix login › Fix login › Fix loginScopeThis featureWhole projectHide done stepsReconnect
-
Ask Claude…InboxUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtral
-
Ask Claude…InboxUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtralUntitled captureFinishing Open in localvoxtral