OpenCode usage tracker - Track and analyze token usage from OpenCode sessions.
- Session list with filtering and sorting
- Usage aggregation by model
- Daily / Weekly / Monthly token usage reports
- Cost calculation (supports free models, subscription usage, GPT, Claude, and more) (not fully covered)
- Export to CSV / JSON formats
Note
This package is currently under development and will be published to npm when it is ready.
git clone https://github.com/HidemaruOwO/ocusage.git
cd ocusage
bun install
bun build src/index.ts --compile --outfile=ocusage --production
mv ocusage /usr/local/bin# Show daily usage
ocusage daily
# Show weekly usage
ocusage weekly
# Show monthly usage
ocusage monthly
# Show usage by model
ocusage models
# List all sessions
ocusage sessions| Option | Description |
|---|---|
--json |
Output as JSON |
--csv |
Output as CSV |
--from, -f |
Start date filter (YYYY-MM-DD) |
--to, -t |
End date filter (YYYY-MM-DD) |
--model, -m |
Filter by model name |
--path, -p |
Custom messages directory |
# Show sessions from the last week
ocusage sessions --from 2025-01-01 --to 2025-01-07
# Export daily usage as CSV
ocusage daily --csv > daily-usage.csv
# Show usage for a specific model
ocusage sessions --model claude-sonnet-4
# Output as JSON for scripting
ocusage models --json | jq '.totals.costUSD'| Variable | Description | Default |
|---|---|---|
OCUSAGE_MESSAGES_DIR |
OpenCode messages directory | ~/.local/share/opencode/storage/message |
OCUSAGE_MODELS_FILE |
Custom model pricing configuration | (uses built-in defaults) |
OCUSAGE_LOG_LEVEL |
Log level (debug/info/warn/error) | warn |
ocusage includes built-in pricing for major AI models:
- Anthropic: Claude Opus 4.5, Sonnet 4.5, Haiku 4.5, and more
- OpenAI: GPT-5.x, GPT-4.x, o1, o3, o4-mini, and more
- Google: Gemini 3, 2.5, 2.0 series
- xAI: Grok 4.x, 3.x series
- OpenRouter: anything
# Run in development
bun run dev
# Run tests
bun test
# Lint
bun run lint
# Format
bun run format
# Build
bun run buildThis project is dual-licensed under Apache License 2.0 and SUSHI-WARE LICENSE.
A reference to the latest license should be used, even if the attached license is outdated of major versions.
This repository was created using the MicroRepository template.
Made with ❤️ by HidemaruOwO
If ocusage helps improve your QOL of vibe coding, please ⭐ this repository!
