Skip to content

pitimon/TokenTracker

 
 

Repository files navigation

Token Tracker

Know exactly what you're spending on AI — across every CLI

Auto-collect token usage from 22 AI coding tools, aggregate it locally, and read real cost trends in one dashboard. No account or API key required to start — just one command.

npm version npm downloads License: MIT CLI GitHub stars


Token Tracker dashboard



If TokenTracker saves you time, please star it on GitHub.


⚡ Quick Start

Requires Node.js 20+.

npx --yes @ipv9/tokentracker-cli

That's it. The first run installs hooks, syncs your data, and prints the dashboard URL, usually http://127.0.0.1:7680. Pass --open if you want TokenTracker to ask the OS to open your browser.

Prefer a global install for shorter commands:

npm install -g @ipv9/tokentracker-cli

tokentracker            # start the dashboard and print the URL
tokentracker serve --open
tokentracker sync       # sync now
tokentracker status     # check which tools are connected
tokentracker doctor     # health check

✨ What you get

  • 🏠 100% local. Token counts and timestamps only — never prompts, responses, or file contents. No account, no required API keys, no phone-home.
  • 🚀 Zero config. Hooks auto-install on the first run. Zero to dashboard in about 30 seconds.
  • 🔌 22 tools out of the box. Claude Code, Codex, Cursor, Gemini, Copilot, Antigravity, OpenCode, Kiro, Zed, Goose, and more — auto-detected.
  • 💰 Accurate cost. 2,200+ models priced from LiteLLM (refreshed daily) with a bundled offline snapshot, so USD totals are right even without a network. Cross-provider records are de-duplicated so your numbers match each provider's own billing.
  • 📈 Rate-limit tracking. Live quota windows with reset countdowns for Claude, Codex, Cursor, Gemini, Kimi, Z.AI, Kiro, Copilot, and Antigravity.
  • 🧩 Optional extras. A worldwide leaderboard (opt-in) and a Skills tab that syncs 250+ public skills across your tools.

📊 The dashboard

A calm, single-screen readout — a hero total paired with a usage-trend chart, a provider breakdown stacked above a per-provider context breakdown, and a GitHub-style activity heatmap.

Dark Light
Dashboard — dark Dashboard — light

On one screen:

  • Total tokens + cost for the selected window (24h / day / 7d / 30d / total / custom), with a browser-timezone "Updated" stamp.
  • Usage Trend — token volume over time, right beside the total.
  • Provider breakdown — every tool's share and top models, with a click-to-expand per-model drill-down.
  • Context breakdown — where Claude's and Codex's tokens actually go (input / output / cache / reasoning), shown side by side.
  • Activity heatmap — daily usage at a glance.
  • Project & daily tables — per-project totals and a day-by-day breakdown with cost and $/MTok.

Auto-refresh runs only while the tab is visible (Off / 30s / 60s / 120s, default 30s).


🔌 Supported tools

Auto-detected on first run — no manual plugin or hook wiring:

Claude Code · Codex CLI · Cursor · Gemini CLI · GitHub Copilot · Antigravity · Kiro · OpenCode · OpenClaw · Every Code · Hermes · Kimi Code · CodeBuddy · Grok Build · oh-my-pi · pi · Craft Agents · Kilo CLI · Kilo Code · Roo Code · Zed Agent · Goose

Each tool is connected one of three ways, all automatic: a SessionEnd/notify hook (Claude Code, Codex, Gemini, Every Code, CodeBuddy, Grok Build), a bundled plugin linked via the tool's own CLI (OpenCode, OpenClaw), or a passive reader that only reads files the tool already writes — SQLite, JSONL, OTEL exports (Cursor, Kiro, Copilot, Zed, Goose, and the rest).

Run tokentracker status to see each integration's state. Missing your tool? Open an issue — a new provider is usually one parser file away.

Rate-limit providers are auto-detected where possible. For Z.AI / GLM Coding Plan quota windows, export ZAI_API_KEY or ZHIPU_API_KEY before starting the local server. If Claude-compatible tooling is pointed at Z.AI with ANTHROPIC_BASE_URL=https://api.z.ai/... and ANTHROPIC_AUTH_TOKEN, TokenTracker can reuse that auth token for the local limits endpoint.


🏗️ How it works

AI CLI tools  →  hooks / passive readers  →  local SQLite  →  dashboard
   (logs)         (token counts only)       (30-min buckets)   (your browser)
  1. Your AI tools write logs during normal use.
  2. Lightweight hooks (or passive file readers) pick up token counts locally — never prompt or response content.
  3. Counts are aggregated into 30-minute UTC buckets in a local SQLite snapshot.
  4. The dashboard reads that snapshot and renders it in your browser's timezone.

The leaderboard is the only feature that ever leaves your machine, and only when you opt in.


🛡️ Privacy

Protection What it means
No content Only token counts and timestamps. Never prompts, responses, or files.
Local by default All data stays on your machine. The leaderboard is fully opt-in.
Auditable Open source — read src/lib/rollout.js; it's just numbers and timestamps.
No telemetry No analytics, no crash reporting, no phone-home.

📦 Configuration

Most users never touch this — defaults are sensible.

Variable Description Default
TOKENTRACKER_DEBUG Debug output (1 to enable)
TOKENTRACKER_HTTP_TIMEOUT_MS HTTP timeout (ms) 20000
CODEX_HOME Override Codex CLI directory ~/.codex
GEMINI_HOME Override Gemini CLI directory ~/.gemini
TOKENTRACKER_GROK_HOME Override Grok Build directory ~/.grok

To force a dashboard port, use your shell's environment-variable syntax (otherwise TokenTracker auto-picks the next free port from 7680):

PORT=7700 npx --yes @ipv9/tokentracker-cli serve
$env:PORT = 7700
npx --yes @ipv9/tokentracker-cli serve

Browser auto-open is opt-in: tokentracker serve --open. Background services and headless shells should use the default no-open behavior and open the printed URL manually.


🛠️ Development

git clone https://github.com/pitimon/TokenTracker.git
cd TokenTracker
npm install

# build the dashboard, then run the CLI
npm run dashboard:build
node bin/tracker.js

npm test          # root tests
npm run ci:local  # full local gate (build + tests + validators)

📚 Code Documentation

Source-backed engineering documentation starts at openwiki/README.md. Regenerate the local fact ledger with npm run docs:openwiki:extract, validate it with npm run docs:openwiki:check, and use npm run docs:openwiki:verify for the independent read-only review. The model-backed update command expects credentials from the caller's environment and never reads them from this repository.


🔧 Troubleshooting

A tool isn't being detected
tokentracker status      # see each integration's state
tokentracker doctor      # deeper health check

If a tool you use shows as not configured, run tokentracker activate-if-needed to re-run detection. Still missing? Open an issue with the doctor output.

Port 7680 is already in use

The server auto-picks the next free port (7681, 7682, …) and logs it on startup. To force one, use the Bash or PowerShell command in Configuration. To see what's holding port 7680:

lsof -i :7680
Get-NetTCPConnection -LocalPort 7680 -ErrorAction SilentlyContinue
Linux: spawn xdg-open ENOENT

TokenTracker does not require xdg-open to run. The dashboard URL is printed on startup, so you can open it manually from another browser.

If you explicitly pass --open on a desktop Linux machine and see spawn xdg-open ENOENT, install the desktop opener package:

sudo apt update
sudo apt install -y xdg-utils

On servers, SSH sessions, CI, systemd units, and other headless environments, leave browser opening disabled and run:

tokentracker serve --sync --no-open
tokentracker doctor
Windows / PowerShell: start TokenTracker with npx

For an interactive PowerShell session:

npx --yes @ipv9/tokentracker-cli serve --open

For headless PowerShell, CI, or a background process, keep browser opening disabled:

npx --yes @ipv9/tokentracker-cli serve --no-sync --no-open

TokenTracker never stops another process to free a port. When no port is specified it tries the next one up (7681, 7682, …); an explicit --port or $env:PORT that is already in use fails startup and prints an alternative command to run.

Remove everything
tokentracker uninstall

Removes every hook TokenTracker installed across all detected tools, plus local config and data. Safe to re-run.


🤝 Contributing & Support

🙏 Credits

The Clawd character design belongs to Anthropic. This is a community project with no official affiliation with Anthropic.

License

MIT


Token Tracker — quantify your AI output.

npm · GitHub

About

Track token usage across 22 AI coding tools (Claude Code, Codex, Cursor, Gemini, Roo Code, Zed Agent, Goose, and more) — local-first, zero-config, with a beautiful dashboard, native macOS menu bar app, and 4 desktop widgets.

Resources

License

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 72.4%
  • TypeScript 11.2%
  • Swift 9.6%
  • C# 3.4%
  • Inno Setup 1.0%
  • Shell 0.8%
  • Other 1.6%