token-telemetry
Claude Code plugin that records per-turn and per-subagent token usage into a
central SQLite database — with zero model-token overhead (capture runs in
Stop/SubagentStop hooks, outside the model loop).
Since v0.14.0 it can also record to an optional remote backend (Supabase)
for a central, multi-machine view, isolated per user by Postgres Row-Level
Security and reached over stdlib HTTPS with no new dependencies. It is off by
default — local SQLite stays the default and the durable store — and is
enabled with /token-telemetry:enable-remote. See the user handbook for the
enable/migrate flow and the operator/security guide.
v0.16.1 hardens sub-agent capture under parallel load. The sweep committed up to 40 sub-agent transcripts in ONE transaction, so when a hook was killed at its timeout — a large session running 3-6 agents in parallel on a slow or contended working directory (e.g. a cloud-drive mount) — the whole batch rolled back and the cursors froze: capture silently stopped for that session (no error.log, since a kill logs nothing) while small, quiet projects kept recording. Each sub-agent file now commits in its own transaction and the sweep stops on a wall-clock budget, so progress is always durable and the remainder resumes on the next firing; the Stop/SubagentStop hook timeout is raised 10s -> 30s for headroom on cold cloud-drive cwds.
v0.10.0 (schema v6) records per-event agent metrics — api_calls (how many
API calls a turn or sub-agent slice contained) and ctx_tokens (context size
when it ended: the last call's input side, i.e. the number Claude Code's own
token gauge shows) — and the dashboard grows Calls and Context columns in the
Events table, total (input/output) splits on the COST columns too, and a
Detailed/Summary toggle on each of the Projects and Events tables.
v0.9.0 marks backlog roll-ups and gives the dashboard its face: the first
capture of an already-running session distills days of history into one event
dated "today" — capture now stamps such events (note = 'backlog-capture'
when the cursor started at 0 and the span exceeds 24h; a real sidecar note
always wins), windowed reports and the dashboard exclude them from day/week
figures (with an explicit exclusion notice; project-stats and other all-time
views still include them), and the dashboard serves the Marvin icon as its
favicon.
v0.8.1 fixes sub-agent capture for the current harness, which writes each
sub-agent's transcript to <session>/subagents/agent-*.jsonl while the
SubagentStop hook still passes the MAIN transcript path: capture now sweeps
that directory on every firing (per-file cursors, agentType label from the
sibling meta.json — e.g. marvin:developer — bounded to 40 files per firing so
a backlog can't blow the hook timeout; the rest lands on subsequent firings,
which also backfills historical uncaptured sub-agent usage at its original
timestamps). Main-transcript rows are now always kind 0 with no agent label —
previously SubagentStop firings mislabeled a slice of main-loop usage as the
agent. Project totals were always right; per-agent attribution before v0.8.1
was not.
v0.8.0 adds the interactive dashboard (/token-telemetry:dashboard): a
zero-dependency stdlib web app (scripts/dashboard.py) that opens a glass UI in
the browser and computes every KPI, breakdown and cost total server-side from
usage.db — the page only ever receives aggregates and one page of events, so
it scales past what an embedded snapshot could hold. Filter by period (day /
week / month / year, default week), by model and agent, and click a project row
to filter the whole page; the events table is sortable and paginated; four
token/cost measures; a live auto-refresh every 5 minutes. The server is
read-only (mode=ro, every filter a bound SQL parameter), localhost-only,
backgrounded by open, reattaches instead of duplicating, and self-terminates
after ~11 minutes idle so nothing lingers once the last tab closes. If the
server does stop, the page shows a connection-lost overlay that reconnects on
its own; /token-telemetry:dashboard-restart brings the server back in place
(same port, no second tab) and /token-telemetry:dashboard-stop ends it
deliberately. Every event prices at the rate in force at its own timestamp —
the same resolution report.py uses, so the dashboard matches /token-stats.
v0.7.2 completes the permission-hardening pass (AOS-10): no command grants
Bash(sqlite3:*) or bare Bash(python3:*) any more. Write-side bookkeeping
(export, delete, audit, mirror-meta, name registration) moved into
scripts/manage.py (argv-passed values, never interpolated into SQL; table
copies introspect common columns so exports survive schema growth), and
storage-status joined the read-only script reports. Every command's grant now
pins to its exact script invocation.