A beautiful TUI for tracking your Claude Code token usage. Automatically logs token consumption after each response and provides an interactive dashboard to analyze your usage patterns.
- Automatic Logging - Hooks into Claude Code to log tokens after each response
- Per-Model Breakdown - Track usage separately for Opus, Sonnet, and Haiku
- Detailed Token Types - Input, Output, Cache Read, and Cache Write tracked separately
- Interactive Date Picker - View stats for any date range
- Auto-Refresh - Live updates every 2 seconds
- Daily Trends - Sparkline graphs and mini bar charts
- Zero Dependencies - Pure Python, no external packages required
git clone https://github.com/yourusername/claude-token-stats.git
cd claude-token-stats
./install.sh- Copy
hooks/log-token-stats.pyto~/.claude/hooks/ - Copy
bin/claude-statsto~/.claude/hooks/ - Add to
~/.claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/log-token-stats.py"
}
]
}
]
}
}- Add alias to your shell rc file:
alias claude-stats="~/.claude/hooks/claude-stats"claude-stats # Open interactive TUI
claude-stats -h # Show help| Key | Action |
|---|---|
← / → |
Switch between From/To date |
↑ / ↓ |
Adjust selected date |
T |
Jump to Today |
W |
Last 7 days (Week) |
M |
Last 30 days (Month) |
Q |
Quit |
| Metric | Description |
|---|---|
| Input | Direct input tokens sent to the model |
| Output | Tokens generated by the model |
| Cache Read | Tokens read from prompt cache |
| Cache Write | Tokens written to prompt cache |
Stats are stored as JSON in ~/.claude/stats/YYYY-MM-DD.json:
{
"date": "2024-01-15",
"sessions": [...],
"daily_totals": {
"input_tokens": 1234,
"output_tokens": 5678,
"cache_read_tokens": 90123,
"cache_creation_tokens": 4567,
"total_tokens": 101602,
"request_count": 42,
"session_count": 3
},
"by_model": {
"claude-opus-4-5-20251101": {...},
"claude-sonnet-4-20250514": {...}
}
}./uninstall.shThis will:
- Remove hook scripts
- Remove the PostToolUse hook from settings
- Remove shell alias
- Optionally delete your stats data
- PostToolUse Hook - Claude Code triggers the hook after each tool use
- Transcript Parsing - The hook reads the session transcript JSONL file
- Token Extraction - Extracts
usagedata from each API response - Aggregation - Aggregates by model and saves to daily JSON file
- TUI Display - The viewer reads JSON files and renders the dashboard
- Python 3.8+
- Claude Code CLI
- macOS or Linux (uses
termiosfor keyboard input)
MIT
PRs welcome! Please open an issue first to discuss major changes.
