| Crates.io | ccusage-rs |
| lib.rs | ccusage-rs |
| version | 0.2.1 |
| created_at | 2025-06-26 12:34:42.045491+00 |
| updated_at | 2025-06-27 03:23:19.340495+00 |
| description | Real-time token usage monitor for Claude Code (cc) with cost tracking |
| homepage | https://github.com/snowmead/ccusage-rs |
| repository | https://github.com/snowmead/ccusage-rs |
| max_upload_size | |
| id | 1727227 |
| size | 169,987 |
A comprehensive token usage analyzer for Claude Code written in Rust. This tool analyzes your Claude API token usage from session logs, providing detailed cost tracking, daily statistics, and usage patterns.
Using cargo-binstall (recommended):
# Install cargo-binstall if you don't have it
cargo install cargo-binstall
# Install ccusage-rs from pre-built binaries
cargo binstall ccusage-rs
Direct download: Download the latest release for your platform from GitHub Releases.
Available platforms:
cargo install ccusage-rs
# Clone the repository
git clone https://github.com/snowmead/ccusage-rs
cd ccusage-rs
# Install locally
cargo install --path .
# Or build manually
cargo build --release
# Binary will be at ./target/release/ccusage-rs
After installation, the ccusage-rs command will be available in your PATH:
# Show daily usage table (default command)
ccusage-rs
# or explicitly
ccusage-rs daily
# Filter by date range (YYYYMMDD format)
ccusage-rs daily --since 20241201 --until 20241231
# Show only recent entries (last 7 days)
ccusage-rs daily --recent 7
# Sort ascending (oldest first)
ccusage-rs daily --order asc
# Output as JSON for integration
ccusage-rs daily --json
# Show per-model cost breakdown (Phase 2)
ccusage-rs daily --breakdown
# Show monthly aggregated usage
ccusage-rs monthly
# Filter monthly data by date range
ccusage-rs monthly --since 20241101 --until 20241231
# Monthly data as JSON
ccusage-rs monthly --json
# Monthly breakdown by model (Phase 2)
ccusage-rs monthly --breakdown
# Show individual session details
ccusage-rs session
# Filter sessions by date range
ccusage-rs session --since 20241220
# Show only recent sessions (last 10)
ccusage-rs session --recent 10
# Session data as JSON (sorted by cost, highest first)
ccusage-rs session --json
# Session breakdown by model (Phase 2)
ccusage-rs session --breakdown
# Real-time monitoring dashboard (original behavior)
ccusage-rs monitor
# Monitor with custom plan and timezone
ccusage-rs monitor --plan max5 --timezone America/New_York
# Monitor with custom reset hour
ccusage-rs monitor --reset-hour 6
# Show only active blocks (Phase 3)
ccusage-rs monitor --active
# Show only recent blocks (Phase 3)
ccusage-rs monitor --recent 5
# Custom refresh interval (Phase 3)
ccusage-rs monitor --refresh-interval 5
# Enable debug logging for any command
ccusage-rs daily --debug
# Use custom Claude directory (Phase 2)
ccusage-rs daily --claude-dir ~/.claude-custom
export CLAUDE_CONFIG_DIR=~/.claude-custom
# Offline mode - skip remote pricing lookups (Phase 2)
ccusage-rs daily --offline
# Test JSONL parser compatibility
ccusage-rs --test-parser
# Show per-model cost breakdown for daily reports
ccusage-rs daily --breakdown
# Model breakdown for monthly reports
ccusage-rs monthly --breakdown
# Model breakdown for session analysis
ccusage-rs session --breakdown
The breakdown view shows detailed per-model token usage and costs:
📅 2025-06-26
┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│ Model │ Input │ Output │ Cache │ Read │ Total │ Cost │
│ │ │ │ Create │ │ Tokens │ (USD) │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ sonnet-4 │ 8K │ 20K │ 1.5M │ 16.6M │ 18.1M │ $10.93 │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ opus-4 │ 798 │ 26K │ 382K │ 5.5M │ 5.9M │ $17.39 │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ Total │ 9K │ 46K │ 1.9M │ 22.0M │ 24.0M │ $28.32 │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
# Use environment variable for custom directory
export CLAUDE_CONFIG_DIR=~/.custom-claude
ccusage-rs daily
# Or specify directly
ccusage-rs daily --claude-dir ~/.custom-claude
# Use cached pricing data, skip remote lookups
ccusage-rs daily --offline
ccusage-rs monitor --offline
# Show only last 7 days of data
ccusage-rs daily --recent 7
# Show only last 10 sessions
ccusage-rs session --recent 10
# Show only last 3 blocks in monitor
ccusage-rs monitor --recent 3
# Show only currently active blocks in monitor
ccusage-rs monitor --active
# Combine with other filters
ccusage-rs monitor --active --recent 5 --refresh-interval 1
# Fast refresh for development work
ccusage-rs monitor --refresh-interval 1
# Slow refresh for background monitoring
ccusage-rs monitor --refresh-interval 30
# Focus on recent active work
ccusage-rs monitor --active --recent 3 --refresh-interval 2
daily - Show daily usage reports (default)monthly - Show monthly usage aggregatessession - Show individual session reportsmonitor - Real-time monitoring dashboard--since YYYYMMDD - Filter usage data from specific date--until YYYYMMDD - Filter usage data until specific date--order asc|desc - Sort order (default: desc, newest first)--json - Output results as JSON--breakdown - Show per-model cost breakdown (Phase 2)--recent N - Show only recent entries (Phase 3)--plan pro|max5|max20|custom-max - Claude plan type (default: pro)--reset-hour 0-23 - Custom reset hour for daily limits--timezone - Timezone for reset times (default: Europe/Warsaw)--active - Show only active blocks (Phase 3)--recent N - Show only recent blocks (Phase 3)--refresh-interval N - Update frequency in seconds (Phase 3)--claude-dir <PATH> - Custom Claude directory path (default: ~/.claude, or CLAUDE_CONFIG_DIR env var) (Phase 2)--debug - Enable debug output and detailed logging--offline / -O - Offline mode, skip remote pricing lookups (Phase 2)--test-parser - Test JSONL parser compatibility┌────────────┬─────────────┬──────────────┬───────────────┬──────────────┬─────────────┬──────────────┬─────────────┐
│ Date │ Models │ Input Tokens │ Output Tokens │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
├────────────┼─────────────┼──────────────┼───────────────┼──────────────┼─────────────┼──────────────┼─────────────┤
│ 2024-06-20 │ sonnet-4 │ 12,543 │ 8,921 │ 2,847 │ 1,234 │ 25,545 │ $0.89 │
│ 2024-06-21 │ opus-4 │ 8,234 │ 15,678 │ 0 │ 892 │ 24,804 │ $2.34 │
│ 2024-06-22 │ sonnet-4 │ 15,892 │ 12,456 │ 3,421 │ 2,108 │ 33,877 │ $1.23 │
└────────────┴─────────────┴──────────────┴───────────────┴──────────────┴─────────────┴──────────────┴─────────────┘
Total Usage: 84,226 tokens | Total Cost: $4.46
{
"summary": {
"total_tokens": 84226,
"total_cost_usd": 4.46,
"date_range": {
"start": "2024-06-20",
"end": "2024-06-22"
}
},
"daily_stats": [
{
"date": "2024-06-20",
"models": ["sonnet-4"],
"input_tokens": 12543,
"output_tokens": 8921,
"cache_creation_tokens": 2847,
"cache_read_tokens": 1234,
"total_tokens": 25545,
"cost_usd": 0.89
}
]
}
The tool analyzes Claude Code session logs stored in ~/.claude/ directory:
The tool reads session data from:
~/.claude/sessions/ - Global session files<project-dir>/.claude/ - Project-specific session files--claude-dir or CLAUDE_CONFIG_DIRIf you see "No valid usage data found":
~/.claude/ directory existsls ~/.claude/sessions/--debug flag for detailed parsing information--offline mode if having network issuesccusage-rs provides 100% compatibility with the original ccusage npm package plus additional features:
| Metric | Accuracy | Notes |
|---|---|---|
| Token counts | 100% | Perfect match on all token types |
| Cost calculations | 100% | Exact billing precision |
| Date filtering | 100% | Perfect compatibility |
| Command syntax | 100% | Full feature parity + enhancements |
# All these commands work identically:
ccusage daily --since 20241201 --until 20241231
ccusage-rs daily --since 20241201 --until 20241231
ccusage monthly --json
ccusage-rs monthly --json
ccusage session --since 20241220
ccusage-rs session --since 20241220
# Plus new enhanced features:
ccusage-rs daily --breakdown --recent 7
ccusage-rs monitor --active --refresh-interval 1
ccusage-rs --offline daily --breakdown
Advantages of ccusage-rs:
--breakdown)CLAUDE_CONFIG_DIR)--offline)--recent)--active)--refresh-interval)MIT