A local proxy + web UI for tracking real per-turn token usage from Claude Code.
Claude Code's JSONL logs at ~/.claude/projects/ are unreliable for token counts — input_tokens is a streaming placeholder (75% of entries are 0 or 1), and output_tokens excludes thinking tokens. If you're on an enterprise SSO account with no API key, the OTel pipeline isn't available either.
This proxy intercepts each API response synchronously and captures the finalized usage object before forwarding it — the only way to get accurate per-turn token counts without an API key.
Claude Code CLI
│ (ANTHROPIC_BASE_URL=http://localhost:8080)
▼
Local Proxy (Express, port 8080)
- Forwards requests to https://api.anthropic.com unchanged
- Intercepts responses, extracts usage + content blocks
- Writes turn record to SQLite
- Returns response to Claude Code unmodified
│
▼
Anthropic API
The UI reads from the same SQLite database and runs on a separate port.
npm install
npm run dev # starts proxy (8080) and UI (5173) concurrentlyPoint Claude Code at the proxy:
export ANTHROPIC_BASE_URL=http://localhost:8080
claudeOr, when starting a claude session:
ANTHROPIC_BASE_URL=http://localhost:8080 claude --worktree <worktree-name-goes-here>Then open http://localhost:5173 to explore token usage.
Per turn, from the finalized API response:
| Field | Notes |
|---|---|
input_tokens |
Accurate — finalized in response body |
output_tokens |
Accurate — finalized in response body |
cache_read_tokens |
Accurate |
cache_creation_tokens |
Accurate |
stop_reason |
tool_use or end_turn |
tool_name |
Name of tool called, if any |
model |
Model used for the turn |
message_count |
Number of messages in request context (context growth proxy) |
cost_usd |
Computed at insert time using current Anthropic pricing |
Session browser — table of all sessions with total cost, turns, cache efficiency ratio, and duration.
Session view — stacked bar chart (one bar per turn) broken down by token category, with cost tooltips, a context growth curve overlay, and compaction event markers. Click any bar for a turn detail pane showing the full token breakdown, tool input, and delta from the previous turn. Sessions with multiple agent tiers show an AgentBreakdown panel comparing token utilization across tiers.
| Command | Description |
|---|---|
npm run proxy |
Start proxy only (port 8080) |
npm run ui |
Start Vite dev server only (port 5173) |
npm run dev |
Start both concurrently |
npm run build |
Build UI to dist/ |
SQLite database lives at ~/.clawd-watch/turns.db.