ccusage(claude-code-usage)
A CLI tool for analyzing Claude Code usage from local JSONL files.
Inspired by this article about tracking Claude Code usage costs.
Podcact Claude.Code.CLI.ccusage.mov what-is-ccusage-jp.movClaude Code's Max plan offers unlimited usage - but wouldn't it be interesting to know how much you'd be paying if you were on a pay-per-use plan?
This tool helps you understand the value you're getting from your subscription by calculating the equivalent costs of your actual usage. See how much you're saving and enjoy that satisfying feeling of getting great value! 😊
- 📊 Daily Report: View token usage and costs aggregated by date
- 📅 Monthly Report: View token usage and costs aggregated by month
- 💬 Session Report: View usage grouped by conversation sessions
- 📅 Date Filtering: Filter reports by date range using --since and --until
- 📁 Custom Path: Support for custom Claude data directory locations
- 🎨 Beautiful Output: Colorful table-formatted display
- 📄 JSON Output: Export data in structured JSON format with --json
- 💰 Cost Tracking: Shows costs in USD for each day/month/session
- 🔄 Cache Token Support: Tracks and displays cache creation and cache read tokens separately
⚠️ This is NOT an official Claude tool - it's an independent community project that analyzes locally stored usage data.
Cost calculations are estimates only and may not reflect actual billing:
- Costs shown are virtual/estimated based on token counts and model pricing data
- Actual costs may vary due to pricing changes, special rates, or billing adjustments
- We do not guarantee the accuracy of calculated costs
- For official billing information, always refer to your Claude account dashboard
- This tool only reads local JSONL files generated by Claude Code. If you use Claude Code with multiple devices, you need to ensure the JSONL files are synchronized across devices.
- API usage for tools like Web Search, Code Execution, and Image Analysis are not included in the token usage reports. The tool only tracks language model token usage.
Run directly without installation:
Shows token usage and costs aggregated by date:
ccusage is an alias for ccusage daily, so you can run it without specifying the subcommand.
Shows token usage and costs aggregated by month:
Shows usage grouped by conversation sessions, sorted by cost:
All commands support the following options:
- -s, --since <date>: Filter from date (YYYYMMDD format)
- -u, --until <date>: Filter until date (YYYYMMDD format)
- -p, --path <path>: Custom path to Claude data directory (default: ~/.claude)
- -j, --json: Output results in JSON format instead of table
- -m, --mode <mode>: Cost calculation mode: auto (default), calculate, or display
- -d, --debug: Show pricing mismatch information for debugging
- --debug-samples <number>: Number of sample discrepancies to show in debug output (default: 5)
- -h, --help: Display help message
- -v, --version: Display version
- auto (default): Uses pre-calculated costUSD values when available, falls back to calculating costs from token counts using model pricing
- calculate: Always calculates costs from token counts using model pricing, ignores any pre-calculated costUSD values
- display: Always uses pre-calculated costUSD values only, shows $0.00 for entries without pre-calculated costs
Exposes usage data through Model Context Protocol for integration with other tools:
The MCP server supports both stdio and HTTP stream transports:
- stdio (default): Best for local integration where the client directly spawns the process
- HTTP stream: Best for remote access when you need to call the server from another machine or network location
Available MCP tools:
- daily: Returns daily usage reports (accepts since, until, mode parameters)
- session: Returns session usage reports (accepts since, until, mode parameters)
To use ccusage MCP with Claude Desktop, add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Or if you have ccusage installed globally:
After adding this configuration, restart Claude Desktop. You'll then be able to use the ccusage tools within Claude to analyze your usage data.
- Claude Code usage history files (~/.claude/projects/**/*.jsonl)
MIT
This tool was inspired by this excellent article by @milliondev about tracking Claude Code usage costs. The article demonstrates how to analyze Claude Code's local JSONL files using DuckDB to understand token usage patterns and costs.
While the original approach uses DuckDB for analysis, this tool provides a more accessible CLI interface with the same core functionality - analyzing the same JSONL files that Claude Code stores locally to give you insights into your usage patterns and costs.
Thanks to @milliondev for the original concept and approach to Claude Code usage analysis.