1 unstable release
| 0.1.0 | Mar 5, 2026 |
|---|
#13 in #cost
58KB
1K
SLoC
token-map
Visual token cost tracker for Claude Code. See exactly what each prompt, tool, and session costs — in real time.
┌─ Session ──────────────────────────────────────────────┐
│ Model claude-sonnet-4-6 Requests 42 │
│ Cost $0.084312 Duration 14m 22s │
├─ Token Breakdown ──────────────────────────────────────┤
│ Input ████████████████████░░░░░░ 128,430 │
│ Output ████░░░░░░░░░░░░░░░░░░░░░░ 18,291 │
│ Cache read ██████████████░░░░░░░░░░░░ 92,100 saved $0.22 │
│ Cache write ██░░░░░░░░░░░░░░░░░░░░░░░░ 8,400 │
├─ Tool Breakdown ───────────────────────────────────────┤
│ Agent ████████████████ $0.051 │
│ Bash ████████ $0.024 │
│ Edit ████ $0.009 │
└────────────────────────────────────────────────────────┘
Install
Requires Rust (install via rustup):
cargo install token-map
Claude Code Plugin (recommended)
Install as a Claude Code plugin for automatic session reports and slash commands:
/plugin install https://github.com/jayeshvpatil/token-map
This gives you:
- Auto report on every session end (Stop hook)
/token-map:report— cost breakdown for the last session/token-map:sessions— history table across all sessions/token-map:dev— guided setup for the live dashboard
Manual Setup
Live dashboard
Open two terminals:
Terminal 1 — start the collector + dashboard:
token-map dev --project my-feature
Terminal 2 — start Claude Code with telemetry enabled:
eval $(token-map env) && claude
The dashboard refreshes every 2 seconds. Press q or Ctrl+C to exit and print a final report.
Auto-report on session end
token-map hook-install
This adds a Stop hook to ~/.claude/settings.json so token-map report runs automatically when each Claude Code session ends.
Commands
| Command | Description |
|---|---|
token-map dev [-p project] |
Start collector + live dashboard |
token-map report [session_id] |
Post-session cost report |
token-map sessions [-n 10] |
Recent sessions table |
token-map env |
Print shell env vars for telemetry |
token-map hook-install |
Install Stop hook into ~/.claude/settings.json |
How it works
Claude Code emits per-request telemetry via OpenTelemetry gRPC. token-map runs a local OTEL collector on localhost:4317, receives the claude_code.api_request metric, and persists each request to a local SQLite database (~/.token-map/sessions.db).
Claude Code → OTEL gRPC (localhost:4317) → token-map → SQLite → Ratatui dashboard
No data leaves your machine. No account required.
Data collected per request
- Model, session ID, timestamp
- Input / output / cache read / cache write tokens
- Cost in USD, duration in ms
- Tool name (Bash, Edit, Read, Agent, ...)
- Prompt snippet (first 200 chars, for expensive-turns view)
License
MIT
Dependencies
~38–56MB
~838K SLoC