CLI tool to track and display OpenCode token usage statistics
Project description
opencode-usage
CLI tool to track and display OpenCode token usage statistics. Reads directly from OpenCode's local SQLite database — no API keys or external services needed.
Features
- Daily breakdown — token usage and cost per day
- Group by dimension — model, agent, provider, or session
- Agent × Model view — see which model each agent uses
- Time filtering — last N days, relative durations (
7d,2w), or ISO dates - JSON output — pipe to
jqor other tools - Cross-platform — macOS, Linux, Windows
Installation
# From PyPI
pip install opencode-usage
# Or with uv
uv tool install opencode-usage
From source
git clone https://github.com/rchardx/opencode-usage.git
cd opencode-usage
uv sync
uv tool install -e .
After installation, opencode-usage is available globally.
Usage
# Default: last 7 days, daily breakdown
opencode-usage
# Quick shortcuts
opencode-usage today
opencode-usage yesterday
# Time filtering
opencode-usage --days 30
opencode-usage --since 7d
opencode-usage --since 2025-01-01
# Group by dimension
opencode-usage --by model
opencode-usage --by agent # shows model per agent
opencode-usage --by provider
opencode-usage --by session --limit 10
# JSON output
opencode-usage --json
opencode-usage --by model --json | jq '.rows[].label'
Example output
╭──────────────── OpenCode Usage — Last 7 days ────────────────╮
│ Calls: 1,280 │ Tokens: 52.3M │ Cost: $0.00 │
╰──────────────────────────────────────────────────────────────╯
Usage by Agent (Last 7 days)
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ Agent ┃ Model ┃ Calls ┃ Total ┃ Cost ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ build │ deepseek-r1 │ 420 │ 18.2M │ - │
│ │ qwen-3-coder │ 105 │ 4.7M │ - │
├────────────────────────┼──────────────┼───────┼─────────┼─────────┤
│ explore │ gemma-3 │ 310 │ 12.5M │ - │
│ │ minimax-m2.5 │ 198 │ 8.1M │ - │
├────────────────────────┼──────────────┼───────┼─────────┼─────────┤
│ librarian │ llama-4 │ 156 │ 5.8M │ - │
├────────────────────────┼──────────────┼───────┼─────────┼─────────┤
│ oracle │ qwen-3-coder │ 91 │ 3.0M │ - │
└────────────────────────┴──────────────┴───────┴─────────┴─────────┘
Configuration
| Environment Variable | Description |
|---|---|
OPENCODE_DB |
Override database path (default: auto-detected per platform) |
Default database locations:
- All platforms (macOS, Linux, Windows):
~/.local/share/opencode/opencode.db
Development
git clone https://github.com/rchardx/opencode-usage.git
cd opencode-usage
uv sync
# Lint & format
uvx ruff check .
uvx ruff format .
# Install pre-commit hooks
uvx pre-commit install
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opencode_usage-0.1.1.tar.gz.
File metadata
- Download URL: opencode_usage-0.1.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
add5d9cf5716ecca36e5fa4a454577fb4c68ae830f97c376412170f3393af7e0
|
|
| MD5 |
367256a0b3ab3ffa9222f284ecc7e146
|
|
| BLAKE2b-256 |
8bc0d9210e1e35f0bbebf271ab94f39c3c01e8930e4437810b4cd51579d23a95
|
File details
Details for the file opencode_usage-0.1.1-py3-none-any.whl.
File metadata
- Download URL: opencode_usage-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2c26f69db463d50bada1aa56bd47c2c649c1bd8898e0a78c541a583a00c6eac
|
|
| MD5 |
08fe9d9bee25642e56b0cdb5efe8e469
|
|
| BLAKE2b-256 |
c6ee70620f5f66c4a779d7900adbb09ec05e49e917abc0acd6e983ee98a01500
|