CC Usage Monitor
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.
Features
Session Log Analysis
- Native JSONL parsing - Direct analysis of Claude Code session logs
- Global deduplication - Prevents counting duplicate entries across files
- Schema validation - Ensures data integrity matching ccusage standards
- Multi-project support - Analyzes usage across all your Claude projects
Financial Tracking
- Accurate cost calculations - Per-token pricing for all Claude models
- Daily cost summaries - Track spending patterns over time
- Model-specific pricing - Supports all Claude 3, 3.5, and 4 models
- Cache token costs - Includes cache creation and read token pricing
- Per-model cost breakdown - Detailed analysis by model type (Phase 2)
Token Analytics
- Detailed token breakdown:
- Input tokens
- Output tokens
- Cache creation tokens
- Cache read tokens
- Model usage tracking - Shows which Claude models you're using
- Daily aggregations - Comprehensive daily usage statistics
- Session-level analysis - Individual session cost and token tracking
Advanced Filtering (Phase 3)
- Recent filtering - Show only last N days/sessions
- Active monitoring - Filter to show only active blocks
- Date range filtering - Precise date-based analysis
- Custom refresh intervals - Configurable monitoring updates
Output Formats
- Table view - Human-readable daily usage tables
- JSON output - Machine-readable format for integration
- Cost breakdown tables - Per-model detailed analysis
- Real-time monitoring - Live usage dashboard
Installation
Pre-built binaries (Fastest ⚡)
Using cargo-binstall (recommended):
# Install cargo-binstall if you don't have it
# Install ccusage-rs from pre-built binaries
Direct download: Download the latest release for your platform from GitHub Releases.
Available platforms:
- Linux (x86_64, ARM64, musl)
- macOS (Intel, Apple Silicon)
- Windows (x86_64)
From crates.io
From source
# Clone the repository
# Install locally
# Or build manually
# Binary will be at ./target/release/ccusage-rs
Usage
After installation, the ccusage-rs command will be available in your PATH:
Daily Reports (Default)
# Show daily usage table (default command)
# or explicitly
# Filter by date range (YYYYMMDD format)
# Show only recent entries (last 7 days)
# Sort ascending (oldest first)
# Output as JSON for integration
# Show per-model cost breakdown (Phase 2)
Monthly Reports
# Show monthly aggregated usage
# Filter monthly data by date range
# Monthly data as JSON
# Monthly breakdown by model (Phase 2)
Session Reports
# Show individual session details
# Filter sessions by date range
# Show only recent sessions (last 10)
# Session data as JSON (sorted by cost, highest first)
# Session breakdown by model (Phase 2)
Real-time Monitoring (Phase 3 Enhanced)
# Real-time monitoring dashboard (original behavior)
# Monitor with custom plan and timezone
# Monitor with custom reset hour
# Show only active blocks (Phase 3)
# Show only recent blocks (Phase 3)
# Custom refresh interval (Phase 3)
Global Options
# Enable debug logging for any command
# Use custom Claude directory (Phase 2)
# Offline mode - skip remote pricing lookups (Phase 2)
# Test JSONL parser compatibility
Enhanced Features
Phase 2: Cost Analysis & Configuration ✅
Cost Breakdown Analysis
# Show per-model cost breakdown for daily reports
# Model breakdown for monthly reports
# Model breakdown for session analysis
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 │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
Environment Configuration
# Use environment variable for custom directory
# Or specify directly
Offline Mode
# Use cached pricing data, skip remote lookups
Phase 3: Advanced Filtering & Monitoring ✅
Recent Filtering
# Show only last 7 days of data
# Show only last 10 sessions
# Show only last 3 blocks in monitor
Active Block Filtering
# Show only currently active blocks in monitor
# Combine with other filters
Custom Monitoring
# Fast refresh for development work
# Slow refresh for background monitoring
# Focus on recent active work
Commands
daily- Show daily usage reports (default)monthly- Show monthly usage aggregatessession- Show individual session reportsmonitor- Real-time monitoring dashboard
Options
Date Filtering (daily, monthly, session)
--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)
Monitoring Options (monitor)
--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)
Global Options
--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
Sample Output
Table Format
┌────────────┬─────────────┬──────────────┬───────────────┬──────────────┬─────────────┬──────────────┬─────────────┐
│ 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
JSON Format
Key Metrics:
- Daily breakdown - Usage statistics for each day
- Model tracking - Which Claude models were used
- Token categories - Input, output, cache creation, and cache read tokens
- Cost calculations - Accurate pricing based on current Anthropic rates
- Total summaries - Aggregate statistics across all analyzed sessions
Requirements
- Rust 1.70+
- Claude Code installation with session logs
- Active Claude Code usage (generates JSONL session files)
How It Works
The tool analyzes Claude Code session logs stored in ~/.claude/ directory:
- Session Discovery: Finds all JSONL session files across projects
- Schema Validation: Validates entries against ccusage standards
- Global Deduplication: Prevents duplicate counting across files
- Token Analysis: Extracts and categorizes token usage by type
- Cost Calculation: Applies current Anthropic pricing models
- Aggregation: Groups usage statistics by date
- Filtering: Applies advanced filtering (recent, active, date ranges)
Session Log Processing:
- Native JSONL parsing - No external dependencies
- Entry-level deduplication - Matching ccusage behavior exactly
- Robust error handling - Skips invalid entries gracefully
- Multi-project support - Analyzes all your Claude projects
- Schema validation - Ensures data integrity
Data Sources
The tool reads session data from:
~/.claude/sessions/- Global session files<project-dir>/.claude/- Project-specific session files- Automatic discovery of all Claude project directories
- Custom directories via
--claude-dirorCLAUDE_CONFIG_DIR
Troubleshooting
If you see "No valid usage data found":
- Ensure you've used Claude Code recently (generates session logs)
- Check that
~/.claude/directory exists - Verify session files contain usage data:
ls ~/.claude/sessions/ - Use
--debugflag for detailed parsing information - Try
--offlinemode if having network issues
Star History
Comparison with ccusage npm
ccusage-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 |
Migration from ccusage npm
# All these commands work identically:
# Plus new enhanced features:
Advantages of ccusage-rs:
- ⚡ ~10x faster execution (Rust vs Node.js)
- 🔋 Lower memory footprint
- 📊 Real-time monitoring capabilities
- 📦 Single binary deployment (no Node.js required)
- 🛡️ Better error handling and validation
- 💰 Per-model cost breakdown analysis (Phase 2)
- 🎯 Advanced filtering options (Phase 3)
- ⚙️ Environment configuration support (Phase 2)
- 🔌 Offline mode for reliable operation (Phase 2)
Development Phases
✅ Phase 1: Core Functionality (Completed)
- Daily, monthly, and session reports
- Date filtering and sorting
- JSON output and table formatting
- 100% npm compatibility achieved
✅ Phase 2: Enhanced UX (Completed)
- Cost breakdown analysis (
--breakdown) - Environment variable support (
CLAUDE_CONFIG_DIR) - Offline mode (
--offline) - Modular code architecture
✅ Phase 3: Advanced Features (Completed)
- Recent filtering (
--recent) - Active block filtering (
--active) - Custom refresh intervals (
--refresh-interval) - Enhanced monitoring capabilities
🚧 Phase 4: Future Enhancements
- MCP server implementation
- HTTP API endpoints
- Advanced analytics and trends
- Team collaboration features
License
MIT