@ccusage/opencode
Analyze OpenCode usage logs with the same reporting experience as ccusage. Track token usage, costs, and sessions for Claude models used in OpenCode.Quick Start
Installation
Shell Alias (Recommended)
Sincenpx @ccusage/opencode@latest is quite long to type repeatedly, set up a shell alias:
Data Source
The CLI looks for OpenCode usage data under:- Default:
~/.local/share/opencode/storage/ - Custom: Set
OPENCODE_DATA_DIRenvironment variable
Storage Structure
OpenCode stores usage data in:- Messages:
~/.local/share/opencode/storage/message/{sessionID}/msg_{messageID}.json - Sessions:
~/.local/share/opencode/storage/session/{projectHash}/{sessionID}.json
Common Commands
Daily Usage Report
View token usage and costs grouped by date:Weekly Usage Report
View usage grouped by ISO week (YYYY-Www):Monthly Report
View usage aggregated by month (YYYY-MM):Session Report
Detailed breakdown by conversation sessions:JSON Output
Export structured data for scripting:Compact Mode
Optimized for screenshots and narrow terminals:Token Fields
OpenCode message files track these token types:| Field | Description | Usage |
|---|---|---|
tokens.input | Total input tokens sent to model | Standard input billing |
tokens.output | Completion tokens | Output billing |
tokens.cache.read | Cached prompt tokens | Cheaper cached billing |
tokens.cache.write | Cache creation tokens | Cache creation cost |
Cost Calculation
OpenCode storescost: 0 in message files by default. This CLI calculates accurate costs from token usage data using the LiteLLM pricing database.
- All models supported by LiteLLM have accurate pricing
- Supports cache token pricing (cheaper for cached reads)
- Automatic model price lookups
Features
Daily Reports
View token usage and costs aggregated by date
Weekly Reports
View usage grouped by ISO week (YYYY-Www)
Monthly Reports
View usage aggregated by month (YYYY-MM)
Session Reports
View usage grouped by conversation sessions
Responsive Tables
Automatic layout adjustment for terminal width
Model Tracking
See which Claude models you’re using (Opus, Sonnet, Haiku, etc.)
Accurate Costs
Uses LiteLLM pricing database for accurate cost calculation
Cache Support
Tracks cache creation and cache read tokens separately
JSON Output
Export data in structured JSON format with —json
Compact Mode
Use —compact flag for narrow terminals, perfect for screenshots
Environment Variables
| Variable | Description | Default |
|---|---|---|
OPENCODE_DATA_DIR | Override OpenCode data directory | ~/.local/share/opencode |
LOG_LEVEL | Control log verbosity (0 silent … 5 trace) | - |
Example Output
The CLI provides beautiful terminal tables showing:- Date or session information
- Models used (with bullet points for multiple models)
- Total tokens (input + output)
- Cache tokens (read and write)
- Estimated cost in USD
Links
npm Package
View on npm registry
OpenCode
Official OpenCode repository
ccusage Family
Explore all related tools
Main Documentation
Full ccusage documentation