claude-code-stats
claude-code-stats is a Rust library and CLI for collecting Claude Code usage
stats and rendering them as JSON payloads.
The crate supports both:
- a reusable library API (
claude_code_stats), and - a
claude-code-statsbinary that prints a widget-friendly JSON payload.
Features
- Fetches usage from Claude OAuth usage API
- Falls back to claude.ai web session usage API
- Falls back to probing
/usagefrom the Claude CLI - Caches responses for 4 minutes
- Computes usage windows and pace signals
- Scans recent Claude project logs for estimated 30-day cost
Install
CLI Usage
The command prints a JSON payload to stdout.
Library Usage
Or use the typed API:
Authentication Sources
The crate tries the following usage sources in order:
- OAuth API via keychain/credentials token
- claude.ai web API via browser session cookie
- CLI
/usageprobe via pseudo-terminal session
License
MIT