ccstat
Analyze Claude Code usage data from local JSONL files.
Overview
ccstat is a high-performance Rust CLI tool that processes Claude Code usage logs, calculates costs using LiteLLM pricing data, and provides various reporting views including daily, monthly, session-based, and 5-hour billing block reports.
This project is inspired by ccusage and is a Rust reimplementation (RIIR - Rewrite It In Rust) of the original TypeScript tool, offering:
- 50-70% reduction in memory usage
- 2-3x faster processing speed
- Zero memory leaks through RAII
- Better error handling and recovery
Features
- 📊 Multiple Report Types: Daily, monthly, session, and billing block views
- 💰 Accurate Cost Calculation: Uses latest LiteLLM pricing data with offline fallback
- 🔍 Automatic Discovery: Finds Claude data directories across platforms
- 📈 Flexible Output: Table format for humans, JSON for machines
- 🚀 High Performance: Stream processing with minimal memory footprint
- 👀 Universal Live Monitoring: Real-time tracking with auto-refresh for ALL commands
- 📊 Live Billing Block Monitor: Visual ASCII art display with progress bars, burn rate, and projections
- 🎨 Watch Command Alias: Quick
ccstat watch
shortcut for live billing block monitoring - 💸 Custom Cost Limits: Set your own maximum cost threshold for progress calculations
- ⚡ Performance Options: Parallel processing, string interning, arena allocation
- 🔧 Advanced Filtering: By date, project, instance, and more
- 🌍 Timezone Support: Accurate daily aggregation across different timezones
- 📊 Statusline Integration: Real-time usage monitoring for Claude Code status bar
- 🎯 Model Name Simplification: Shortened model names with
--full-model-names
option
Installation
From crates.io
The easiest way to install ccstat is using cargo:
From Source
# Clone the repository
# Build and install
Pre-built Binaries
Download the latest release for your platform from the releases page.
Docker
You can run ccstat using Docker without installing Rust or building from source:
# Pull the latest image
# Run ccstat with your Claude data directory mounted
# Use a specific version
# Run with custom options
For Linux users, the path is the same:
For Windows users (PowerShell):
docker run -v "$env:APPDATA\Claude:/data:ro" hydai/ccstat daily
The Docker image is multi-platform and supports both linux/amd64
and linux/arm64
architectures.
Quick Start
# View today's usage (defaults to daily command)
# View with informational messages
# View this month's usage
# View all sessions with costs
# Show statusline for Claude Code integration
# Export data as JSON for further processing (global option)
# Live monitoring (works with all commands)
# Quick alias for live billing block monitor
Usage
Daily Usage Report
Show daily token usage and costs. The daily command is the default when no command is specified.
# Default table output (these are equivalent)
# Common options can be used globally or with commands
# Filter by date range (accepts YYYY-MM-DD or YYYY-MM format)
# Daily-specific options
# Live monitoring (global option, works with all commands)
# Global options work with all commands
# Performance options (global)
Monthly Summary
Aggregate usage by month:
# Monthly totals
# Filter specific months (accepts YYYY-MM-DD or YYYY-MM format)
# Live monitoring
# JSON output
# Filter by project
# Timezone configuration
# Model display options
Session Analysis
Analyze individual sessions:
# List all sessions
# Live monitoring
# JSON output with full details
# Filter by date range
# Filter by project
# Timezone configuration
# Model display options
# Different cost calculation modes
Billing Blocks
Track 5-hour billing blocks:
# Show all blocks
# Live monitoring
# Only active blocks
# Recent blocks (last 24h)
# JSON output
# Filter by project
# Filter by date range
# Set token limit for warnings
# Timezone configuration
# Model display options
Live Billing Block Monitor
The --watch --active
combination provides a rich visual monitoring interface for active billing blocks:
This displays a real-time ASCII art dashboard with:
-
TIME Progress Bar: Shows how much of the current 5-hour billing block has elapsed
- Visual progress bar with percentage completion
- Start time, elapsed time, and time remaining until block ends
-
USAGE Progress Bar: Tracks current cost and token consumption
- Real-time cost tracking against monthly limit
- Burn rate indicator (NORMAL/ELEVATED) based on usage patterns
- Total tokens consumed in the current block
-
PROJECTION Progress Bar: Estimates final cost for the billing block
- Status indicator (WITHIN LIMITS/APPROACHING LIMIT/OVER LIMIT)
- Projected final cost based on current burn rate
-
Summary Line: Shows active models, number of sessions, and projects
The monitor refreshes every 5 seconds by default (customizable with --interval
) and provides an at-a-glance view of your Claude Code usage patterns and spending.
Watch Command (Quick Access)
The watch
command provides a convenient alias for the most common live monitoring use case:
# Quick access to live billing block monitor
# Set custom cost limit
# Combine with global options
The --max-cost
option allows you to customize the cost limit used for:
- Progress bar calculations in the USAGE section
- Projection warnings in the PROJECTION section
- Status indicators (WITHIN LIMITS/APPROACHING LIMIT/OVER LIMIT)
If not specified, the tool automatically uses the highest historical cost from your billing blocks.
Cost Calculation Modes
Control how costs are calculated:
# Auto mode (default) - use pre-calculated when available
# Always calculate from tokens
# Only use pre-calculated costs
Detailed Output Mode
Get detailed token information for each API call:
# Show individual entries for daily usage
# Detailed mode with JSON output
# Detailed mode for specific date
Statusline Command
Real-time usage monitoring for Claude Code integration:
# Basic statusline output (requires JSON input from stdin)
|
# Customize monthly fee (default: $200)
# Disable colored output
# Show date and time
# Show git branch
Important: The statusline command is designed to be called by Claude Code and expects JSON input from stdin. It will:
- Return an error immediately if run interactively in a terminal (TTY detection)
- Timeout after 5 seconds if stdin doesn't provide input
- Example usage:
echo '{"session_id": "test", "model": {"id": "claude-3-opus", "display_name": "Claude 3 Opus"}}' | ccstat statusline
The statusline command is optimized for minimal memory footprint and fast response times, making it ideal for integration with Claude Code's status bar.
Performance Options
Optimize for large datasets:
# Parallel processing is always enabled
# Use string interning to reduce memory
# Use arena allocation for better performance
# Combine all optimizations
Output Examples
Live Billing Block Monitor
When using ccstat blocks --watch --active
, you get a visual dashboard:
+--------------------------------------------------------------------------------------------------+
| CCSTAT - LIVE BILLING BLOCK MONITOR |
+--------------------------------------------------------------------------------------------------+
| TIME [##################......................] 46.0% |
| Started: 19:00:00 Elapsed: 2h 18m Remaining: 2h 41m (00:00:00) |
| USAGE [#############...........................] 32.9% ($ 68.49/$ 208.37) |
| Cost: $ 68.49 (Burn: $0.496/min ELEVATED) Tokens: 31,321,720 |
| PROJECTION [############################............] 71.2% ($ 148.39/$ 208.37) |
| Status: WITHIN LIMITS Projected Cost: $ 148.39 |
| Models: Opus 4.1, Sonnet 4 Sessions: 10 Projects: 2 |
+--------------------------------------------------------------------------------------------------+
| Refreshing every 5s - Press Ctrl+C to stop |
+--------------------------------------------------------------------------------------------------+
This provides:
- Real-time progress tracking for the current 5-hour billing block
- Visual indicators for usage against monthly limits
- Burn rate monitoring to detect unusual usage patterns
- Projected costs to help stay within budget
Table Format (Default)
┌────────────┬───────────┬──────────┬──────────────┬────────────┬───────────┬──────────┬─────────────────┐
│ Date │ Input │ Output │ Cache Create │ Cache Read │ Total │ Cost │ Models │
├────────────┼───────────┼──────────┼──────────────┼────────────┼───────────┼──────────┼─────────────────┤
│ 2024-01-15 │ 1,234,567 │ 123,456 │ 12,345 │ 1,234 │ 1,371,602 │ $12.35 │ claude-3-opus │
│ 2024-01-16 │ 2,345,678 │ 234,567 │ 23,456 │ 2,345 │ 2,606,046 │ $23.46 │ claude-3-sonnet │
├────────────┼───────────┼──────────┼──────────────┼────────────┼───────────┼──────────┼─────────────────┤
│ TOTAL │ 3,580,245 │ 358,023 │ 35,801 │ 3,579 │ 3,977,648 │ $35.81 │ │
└────────────┴───────────┴──────────┴──────────────┴────────────┴───────────┴──────────┴─────────────────┘
JSON Format
Configuration
Environment Variables
CLAUDE_DATA_PATH
: Override default Claude data directory locationRUST_LOG
: Control logging level (e.g.,RUST_LOG=ccstat=debug
)
Logging Behavior
ccstat runs in quiet mode by default (only warnings and errors are shown):
- Use
--verbose
or-v
flag to show informational messages RUST_LOG
environment variable can override these defaults
Data Locations
ccstat automatically discovers Claude data in standard locations:
- macOS:
~/.claude/
- Linux:
~/.claude/
- Windows:
%APPDATA%\Claude\
Using as a Library
ccstat can also be used as a Rust library. Add to your Cargo.toml
:
[]
= "0.3.3"
Example usage:
use ;
use Arc;
async
See the examples/
directory for more usage examples.
Development
Building from Source
# Debug build
# Release build with optimizations
# Run tests
# Run benchmarks
Architecture
The project follows a modular architecture:
types.rs
- Domain types with newtype patterndata_loader.rs
- Async streaming JSONL parserpricing_fetcher.rs
- LiteLLM API client with cachingcost_calculator.rs
- Token-based cost calculationsaggregation.rs
- Time-based data aggregationcli.rs
- Command-line interfaceoutput.rs
- Table and JSON formattersstatusline.rs
- Statusline command for Claude Code integrationtimezone.rs
- Timezone support and configurationmodel_formatter.rs
- Model name formatting utilitiesfilters.rs
- Data filtering logiclive_monitor.rs
- Live monitoring with auto-refreshmemory_pool.rs
- Memory pool optimizationstring_pool.rs
- String interning for memory efficiency
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run
cargo fmt
andcargo clippy
- Submit a pull request
Troubleshooting
Common Issues
No data found:
- Ensure Claude Code is installed and has been used
- Check if data exists in the expected location
- Try setting
CLAUDE_DATA_PATH
environment variable
Permission errors:
- ccstat needs read access to Claude data directory
- On Unix systems, check directory permissions
Pricing data unavailable:
- ccstat will use embedded pricing data if LiteLLM API is unavailable
- Check internet connection for latest pricing
Memory issues with large datasets:
- Parallel processing is always enabled for better performance
- Use
--intern
flag to reduce memory usage for repeated strings - Use
--arena
flag for more efficient memory allocation
Debug Mode
Enable debug logging to troubleshoot issues:
RUST_LOG=ccstat=debug
License
MIT License - see LICENSE file for details.
Acknowledgments
- ccusage - The original TypeScript implementation that inspired this project
- LiteLLM for model pricing data
- Claude by Anthropic for the usage data format