ccusage-rs-0.1.0 is not a library.
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
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
Output Formats
- Table view - Human-readable daily usage tables
- JSON output - Machine-readable format for integration
- Flexible filtering - Date ranges and project-specific analysis
Installation
From crates.io (Recommended)
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:
# Show daily usage table
# Output as JSON for integration
# Analyze specific project directory
# Debug mode with detailed logging
# Specify custom Claude directory
Options
--table- Display daily usage in table format--json- Output results as JSON--project-dir <PATH>- Analyze specific project directory--claude-dir <PATH>- Custom Claude directory path (default: ~/.claude)--debug- Enable debug output and detailed logging--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
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
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
Star History
License
MIT