Skip to content
 
 

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 Clawd Watch

A local proxy + web UI for tracking real per-turn token usage from Claude Code.

Why

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.

How it works

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.

Setup

npm install
npm run dev        # starts proxy (8080) and UI (5173) concurrently

Point Claude Code at the proxy:

export ANTHROPIC_BASE_URL=http://localhost:8080
claude

Or, 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.

What gets captured

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

UI

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.

Scripts

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/

Data

SQLite database lives at ~/.clawd-watch/turns.db.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages