English · 简体中文
Self-hosted AI token usage tracker for Claude Code, Codex, Cursor and 40+ other coding tools:
one account, many machines, every token and every dollar stored in your own Supabase.
🌐 Website · 🖥️ Live demo · 📖 Docs · 🚀 Deploy guide · 🤖 Agent rules
Live usage of the author's instance — rendered by this project's public badge, click through to the public page
token-usage-promo-16x9.mp4
- One account, many machines — every collector pairs and revokes independently; usage aggregates per account and drills down per device
- Metadata only — the collector parses local AI tool logs into a local queue; prompts, message bodies, absolute paths and session titles are never collected
- Full dashboard — KPIs, trends, activity heatmap, model / source / device breakdowns, daily·hourly·monthly tables, cost analysis, session details, project attribution, collector run history, yearly wrapped, and a 20 × 5 achievement wall
- Vendor credits — tracked as a separate dimension, never mixed into tokens or cost
- Public badge —
/api/badgerenders a deterministic SVG;/u/<token>is a public usage page with no login required, revocable at any time - Data ownership — each instance binds its own Supabase project; nothing is shared across instances, and browsers never read data tables directly (RLS denies everything + service-role)
- Contract first — the collector-facing API is frozen, the dashboard API evolves with the UI (
docs/cli-contract.md) - Multiple surfaces — web dashboard, collector CLI (npm
tokenusage-cli), marketing site, and a Tauri 2 tray companion
Token Usage reads the logs your AI tools already write on disk. No proxy, no SDK, no code changes, and nothing leaves your machine except aggregate counts for the instance you paired.
| Token Usage | Local report CLIs (e.g. ccusage) | Hosted LLM observability (e.g. Helicone, Langfuse) | |
|---|---|---|---|
| How data is collected | Parses local tool logs on a schedule | Parses local logs on demand | Traffic routed through a proxy or instrumented with an SDK |
| Changes to your AI tools | None | None | Proxy URL or SDK integration |
| Persistent storage | Your own Supabase | Local files / terminal output | Vendor cloud, or self-hosted |
| Multi-machine, one account | Yes | No | Usually per deployment, not per machine |
| Dashboard UI | Yes, self-hosted | No | Yes |
| Built for | Personal and small-team usage accounting | Quick ad-hoc reports | Request-level tracing, latency and evals |
These tools solve different problems and can be used together: observability platforms tell you what a request cost and why it was slow; Token Usage tells you what your editors and CLI agents consumed across all your machines over time, and keeps that history in a database you control.
| Surface | Path | Stack |
|---|---|---|
| Web | apps/web |
Next.js 16 App Router + React 19 + HeroUI 3 + Tailwind CSS 4 + recharts |
| Collector CLI | packages/cli |
Node.js ≥ 22.19, npm tokenusage-cli |
| Site | apps/landing |
Next.js 16 static export (single-page site) |
| Desktop | apps/desktop |
Tauri 2 + React 19 + HeroUI 3 (tray companion) |
| Data | supabase/ |
Supabase Auth + Postgres, migrations applied in filename order |
token-usage/
├── apps/
│ ├── web/ # dashboard + collector contract endpoints
│ ├── landing/ # token-usage.cc marketing site (static export)
│ └── desktop/ # Tauri 2 tray companion
├── packages/cli/ # collector CLI (npm: tokenusage-cli)
├── supabase/ # Postgres migrations (timestamp order, idempotent)
├── scripts/ # ops scripts (index in scripts/README.md)
├── docs/ # requirements, contracts, UI spec, deploy and runbooks
├── AGENTS.md # development conventions and agent constraints
└── THIRD_PARTY_NOTICES.md
Prerequisites: Node.js ≥ 22.19, pnpm (version pinned by the root packageManager), and a Supabase project.
pnpm install
cp apps/web/.env.example apps/web/.env.local # Supabase URL / publishable key / secret key
pnpm dev # http://localhost:3000npm install -g tokenusage-cli
tokenusage init # scan local AI tool logs, install the usage hook, register the hourly task
tokenusage device-login # print a pairing code, approve it in the browser at /device
tokenusage sync # report once; --watch keeps it residentLogs are read-only and only usage metadata leaves the machine (never prompts, message
bodies, absolute paths or session titles). Full command surface and source support live in
packages/cli/README.md.
Everything from "empty Supabase project" to "collector reporting" is documented as an agent-executable runbook. Paste this into your coding agent:
Deploy this repository's Token Usage app from scratch, following docs/deploy-guide.md
section by section, and report the result of each section:
1. Create a Supabase project; write Project URL / publishable key / secret key into
apps/web/.env.local (never commit them).
2. Apply every migration in supabase/migrations/ in filename order (idempotent); confirm
the token_* tables exist and no RLS policies were added.
3. Configure Supabase Auth: Site URL plus wildcard Redirect URLs (https://<domain>/**),
and disable public sign-ups.
4. Deploy apps/web to Vercel with the four required environment variables.
5. Create the admin account with scripts/admin/create-user.cjs.
6. Pair a collector: tokenusage device-login → approve on /device → tokenusage sync --drain.
7. Run the smoke checklist in docs/launch-runbook.md and print the actual output of each step.
Stop and ask me before any irreversible action (deleting a project, switching domains);
keep secrets local and never echo them.
The agent's two sources of truth: docs/deploy-guide.md (from
zero, including env vars and FAQ) and docs/launch-runbook.md
(upgrades, smoke checks, rollback). Or hit the button below and fill in the env vars after
the deploy:
No. The collector only sends aggregate token counts, model names, project basenames and
session metadata (start/end time, token split, per-model usage). Prompts, assistant
messages, tool arguments, command output, diffs, session titles and absolute paths are
never uploaded. The boundary is locked by a field whitelist in packages/cli/test/.
46 local sources plus 5 account-level sources, including Claude Code, Codex, Cursor,
GitHub Copilot, Gemini, Qoder, Kiro, Zed, TRAE and more. The authoritative list is
tokenusage sync --help; only tools you actually use are scanned.
No. Token Usage reads the logs those tools already write to disk. Nothing changes in your editor, CLI or API calls.
You need a Supabase project and the web app running somewhere — Vercel or your own host. It can also run locally if you only want the dashboard on your own machine.
A CLI report reads the logs, prints numbers and exits. Token Usage keeps the data in your Supabase, aggregates multiple machines under one account, shows trends and project attribution over time, and can publish a badge or a login-free public page.
Only to the instance you paired. The CLI sends no anonymous telemetry and no third-party error reports; apart from your own instance, nothing receives data.
Product documentation lives at www.token-usage.cc/docs.
Repository documentation is written in Chinese: start with AGENTS.md for
conventions, docs/requirements.md for scope,
docs/rewrite-plan.md for architecture, and
docs/cli-contract.md for the API contract.
| Document | Content |
|---|---|
docs/deploy-guide.md |
Deploy from zero (Supabase + Vercel) |
docs/launch-runbook.md |
Upgrades, smoke checklist, rollback |
docs/cli-contract.md |
Collector API contract |
docs/badge.md |
Public badge and public page |
docs/sources-capture-audit.md |
How each source is captured |
packages/cli/README.md |
Collector install, commands, troubleshooting |
docs/archive/ |
Historical records |
MIT. Code provenance and third-party licenses live in
THIRD_PARTY_NOTICES.md and
packages/cli/THIRD_PARTY_NOTICES.md.