SLOPSHOPPER

token-bar

Bar above the prompt showing account usage (5h and 7-day limits), context, cost, model, effort and login expiry

band
v0.4.0no licenseupdated 2026-10-26Lerma4/claude-code-mods/token-bar
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · token-bar
› 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 ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ⚡ 5h ████ ░░░░░░░░░░ 31% ↻ NaNm ctx 49% 97k/200k opus-5-5 $0.42 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │ ⚡ 5h ████ ░░░░░░░░░░ 31% ↻ NaNm ctx 49% 97k/200k opus-5-5 $0.42 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
README

claude-code-mods

A growing collection of mods for Claude Code.

ModWhat it does
agent-squadSide pane listing the agents at work: nickname, icon, role, status and current activity. /squadra flusso (or a click on an agent) opens a live map in the browser: call graph, timeline, files touched and crucial files. /squadra storico lists past sessions and the files each one changed. A 💬 button on sessions, files and calls puts a question about them in the prompt of the session that did the work (/squadra collega registers the squadra:// link once). Windows only for now
token-barBar above the prompt showing account usage (5h and 7-day limits), context, cost, model, effort and login expiry (🔑, read from .credentials.json; absent on macOS, where credentials live in the Keychain). Bars shrink with the terminal width and drop to bare percentages below 90 columns

The in-app labels are in Italian.

Install

Inside Claude Code:

/plugin marketplace add Lerma4/claude-code-mods
/plugin install agent-squad@claude-code-mods
/plugin install token-bar@claude-code-mods

Then restart Claude Code.

Update

/plugin marketplace update claude-code-mods

Or enable auto-update for this marketplace from the /plugin menu.

agent-squad: setup and use

The pane works as soon as the plugin is installed. The browser pages and the 💬 buttons need Windows (for now).

  1. Install and restart Claude Code (see above). The squad pane opens by itself; /squadra opens it again.
  2. Open the flow map: /squadra flusso, the 🗺 Flusso button in the pane, or a click on an agent's name. It opens in your default browser and updates live.
  3. Open the history: /squadra storico, or the 📚 Storico link in the flow page.
  4. Optional, once: link the 💬 buttons to the terminal with /squadra collega.
  5. Without it, 💬 copies a ready-made question to the clipboard and you paste it in the terminal.
  6. With it, 💬 writes the question straight into the prompt of the session that did the work. If that session is closed, a menu lets you resume it in a new terminal (claude --resume) or pick another open session.
  7. The first click, the browser asks whether to open the squadra link: allow it (tick "always allow" to skip the question next time).
  8. The question is never sent on its own: you finish it and press Enter.
CommandWhat it does
/squadraOpens the pane
/squadra flusso [name]Flow map of the session, or of one agent and its subagents
/squadra storicoPast sessions, the files each one changed, search by file, project or request
/squadra collegaRegisters the squadra:// link for your Windows user (no admin rights)
/squadra scollegaRemoves it
/squadra pulisciClears finished agents from the pane
/squadra tombola [name]New random nicknames

Settings (/plugin → agent-squad → configure): keepSessions, how many recent sessions keep their full flow map (default 20). Older ones keep only the list of files they changed.

What it writes on your machine

  • %USERPROFILE%\.claude\agent-flow\: the pages, one folder per recent session, the history data. Delete it any time; it is rebuilt.
  • With /squadra collega only: the key HKCU\Software\Classes\squadra, which runs agent-flow\chiedi.ps1 on a squadra:// link. That script takes only a known session id from the link and puts text in that session's prompt box; /squadra scollega removes the key.

Troubleshooting

  • 💬 only copies to the clipboard: run /squadra collega, then reload the page.
  • Nothing happens on 💬 after linking: the browser may have blocked the link; click again and allow it.
  • The page says "ultimo aggiornamento …" instead of "live": that session is closed or idle; the page shows what it recorded.
Source 2 files
hooks/register.tsx 136 lines
1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Snapshot } from '../types'
5
6const snap = atom({ plugin: 'token-bar', key: 'snap' } as const, null)
7
8const LABEL: Record<string, string> = { five_hour: '5h', seven_day: '7gg', spend_limit: 'spesa' }
9// celle della barra in base alla larghezza del terminale; sotto 90 colonne restano solo le percentuali
10const barWidth = (cols: number) => (cols >= 150 ? 14 : cols >= 120 ? 10 : cols >= 90 ? 6 : 0)
11
12// verde < 60, giallo < 85, rosso oltre
13const tone = (p: number) => (p >= 85 ? '#f7768e' : p >= 60 ? '#e0af68' : '#9ece6a')
14
15const bar = (p: number, width: number) => {
16  const n = Math.round((Math.min(100, Math.max(0, p)) / 100) * width)
17  return { on: '█'.repeat(n), off: '░'.repeat(width - n) }
18}
19
20const fmtTokens = (n: number) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${Math.round(n / 1e3)}k` : `${n}`)
21
22const until = (iso: string | undefined, now: number) => {
23  if (!iso) return ''
24  const m = Math.max(0, Math.round((Date.parse(iso) - now) / 60000))
25  const d = Math.floor(m / 1440)
26  const h = Math.floor((m % 1440) / 60)
27  return d > 0 ? `${d}g ${h}h` : h > 0 ? `${h}h ${m % 60}m` : `${m}m`
28}
29
30const toSnap = (u: {
31  rateLimits: Snapshot['limits']
32  context: { percent?: number; tokens?: number; window: number }
33  cost?: { usd: number }
34}): Snapshot => ({
35  limits: u.rateLimits,
36  contextPercent: u.context.percent,
37  contextTokens: u.context.tokens,
38  contextWindow: u.context.window,
39  usd: u.cost?.usd,
40})
41
42// solo la scadenza del login (refresh token): i token non escono mai da qui. Su macOS le credenziali
43// stanno nel Keychain, il file manca e la chiave non si vede
44const readExpiry = async ($: EngineInterface) => {
45  const dir = (await $.env.get('CLAUDE_CONFIG_DIR')) ?? `${(await $.env.get('HOME')) ?? (await $.env.get('USERPROFILE'))}/.claude`
46  try {
47    const o = JSON.parse(await $.fs.read(`${dir}/.credentials.json`)).claudeAiOauth ?? {}
48    return { refreshExpiresAt: typeof o.refreshTokenExpiresAt === 'number' ? new Date(o.refreshTokenExpiresAt).toISOString() : undefined }
49  } catch {
50    return {}
51  }
52}
53
54export const register: Register = on => {
55  on('session.start', async ($, e, next) => {
56    const u = await $.session.usage()
57    const model = await $.session.model()
58    const expiry = await readExpiry($)
59    await update($, snap, s => ({ ...s, ...toSnap(u), model, ...expiry }))
60
61    return next(e)
62  })
63
64  on('session.measure', async ($, e, next) => {
65    // un nuovo login durante la sessione sposta la scadenza: la rileggo a ogni misura
66    const expiry = await readExpiry($)
67    await update($, snap, s => ({ ...s, ...toSnap(e), ...expiry }))
68
69    return next(e)
70  })
71
72  // modello ed effort reali della richiesta, solo loop principale (non subagenti)
73  on('turn.step', async function* ($, e, next) {
74    if (e.agentId === undefined) {
75      await update($, snap, s => (s ? { ...s, model: e.model, effort: e.effort } : s))
76    }
77
78    return yield* next(e)
79  })
80
81  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
82    const s = await read($, snap)
83
84    if (e.props.hasSurvey || s === null) return next(e)
85
86    const { Box, Text } = $.ui.resolve(e)
87    const now = await $.clock.now()
88    const width = barWidth(e.viewport?.columns ?? 150)
89    const ctxPct = s.contextPercent ?? (s.contextTokens !== undefined ? (s.contextTokens / s.contextWindow) * 100 : undefined)
90
91    const meters = s.limits.map(l => {
92      const b = bar(l.percentUsed, width)
93      const c = tone(l.percentUsed)
94      const reset = until(l.resetsAt, now)
95
96      return (
97        <Box key={l.kind} gap={1}>
98          <Text bold>{LABEL[l.kind] ?? l.kind}</Text>
99          {width > 0 ? <Text color={c}>{b.on}</Text> : null}
100          {width > 0 ? <Text dimColor>{b.off}</Text> : null}
101          <Text color={c} bold>{`${Math.round(l.percentUsed)}%`}</Text>
102          {reset ? <Text dimColor>{`↻ ${reset}`}</Text> : null}
103        </Box>
104      )
105    })
106
107    return (
108      <Box borderStyle="round" borderColor="#565f89" paddingX={1} flexWrap="wrap" columnGap={3}>
109        <Text bold color="#7aa2f7">⚡</Text>
110        {meters.length > 0 ? meters : <Text dimColor>limiti account non disponibili</Text>}
111        {s.contextTokens !== undefined ? (
112          <Box gap={1}>
113            <Text dimColor>ctx</Text>
114            {ctxPct !== undefined ? <Text color={tone(ctxPct)} bold>{`${Math.round(ctxPct)}%`}</Text> : null}
115            <Text dimColor>{`${fmtTokens(s.contextTokens)}/${fmtTokens(s.contextWindow)}`}</Text>
116          </Box>
117        ) : null}
118        {s.model ? (
119          <Text color="#bb9af7">{`${s.model.replace(/^claude-/, '')}${s.effort !== undefined ? ` · ${s.effort}` : ''}`}</Text>
120        ) : null}
121        {s.usd !== undefined ? <Text dimColor>{`$${s.usd.toFixed(2)}`}</Text> : null}
122        {s.refreshExpiresAt ? (
123          <Box gap={1}>
124            <Text dimColor>🔑</Text>
125            {Date.parse(s.refreshExpiresAt) <= now ? (
126              <Text color="#f7768e" bold>scaduto</Text>
127            ) : (
128              <Text dimColor>{until(s.refreshExpiresAt, now)}</Text>
129            )}
130          </Box>
131        ) : null}
132      </Box>
133    )
134  })
135}
136
types/index.d.ts 18 lines
1export type Limit = { kind: string; percentUsed: number; resetsAt?: string }
2export type Snapshot = {
3  limits: Limit[]
4  contextPercent?: number
5  contextTokens?: number
6  contextWindow: number
7  usd?: number
8  model?: string
9  effort?: string | number
10  refreshExpiresAt?: string
11}
12
13declare module 'claude-code' {
14  interface PluginState {
15    'token-bar': { snap: Snapshot | null }
16  }
17}
18