Expand description
ccstat - Analyze Claude Code usage data from local JSONL files
This library provides functionality to:
- Parse JSONL usage logs from multiple Claude data directories
- Calculate token costs using LiteLLM pricing data
- Generate reports in table and JSON formats
- Support live monitoring mode for active sessions
§Examples
use ccstat::{
data_loader::DataLoader,
aggregation::Aggregator,
cost_calculator::CostCalculator,
pricing_fetcher::PricingFetcher,
timezone::TimezoneConfig,
types::CostMode,
};
use std::sync::Arc;
#[tokio::main]
async fn main() -> ccstat::Result<()> {
// Initialize components
let data_loader = DataLoader::new().await?;
let pricing_fetcher = Arc::new(PricingFetcher::new(false).await);
let cost_calculator = Arc::new(CostCalculator::new(pricing_fetcher));
let aggregator = Aggregator::new(cost_calculator, TimezoneConfig::default());
// Load and aggregate usage data
let entries = data_loader.load_usage_entries_parallel();
let daily_data = aggregator.aggregate_daily(entries, CostMode::Auto).await?;
Ok(())
}Modules§
- aggregation
- Aggregation module for summarizing usage data
- blocks_
monitor - Enhanced live monitoring display for billing blocks
- cli
- CLI interface for ccstat
- cost_
calculator - Cost calculator module for computing usage costs
- data_
loader - Data loader module for discovering and parsing JSONL files
- error
- Error types for ccstat
- filters
- Filtering module for usage entries
- live_
monitor - Live monitoring functionality for ccstat
- memory_
pool - Memory pool for efficient allocation during parsing
- model_
formatter - Model name formatting module for ccstat
- output
- Output formatting module for ccstat
- pricing_
fetcher - Pricing fetcher module for LiteLLM model pricing data
- statusline
- Statusline module for Claude Code integration
- string_
pool - String interning for memory optimization
- timezone
- Timezone utilities for date handling
- types
- Core domain types for ccstat
Structs§
- Daily
Date - Daily date for aggregation
- ISOTimestamp
- ISO timestamp wrapper for UTC timestamps
- Model
Name - Strongly-typed model name wrapper
- Session
Id - Strongly-typed session ID wrapper
- Token
Counts - Token counts for usage tracking
Enums§
- Ccstat
Error - Main error type for ccstat operations
- Cost
Mode - Cost calculation mode
Constants§
- VERSION
- Library version
Type Aliases§
- Result
- Convenience type alias for Results in ccstat