Usage statistics tracking and dashboard plugin for OpenCode.
Tracks token usage, costs, model selection, and agent activity across sessions. Provides a browser-based dashboard for reviewing your usage.
- Token tracking — input, output, reasoning, and cache-read tokens per message
- Session tracking — titles, directories, timestamps, parent/child relationships
- Agent tracking — subagent types (explore, product-manager, software-architect, etc.) with per-agent token breakdowns
- Cost tracking — per-message cost as reported by the provider
- Dashboard — dark-themed browser UI at
localhost:3333with auto-refresh - Token summary — today, this week, this month, last month totals
Add the plugin to your opencode.json:
{
"plugin": ["@sleipi/opencode-usage-stats"]
}Restart OpenCode to load the plugin. The plugin starts tracking immediately.
git clone https://github.com/sleipi/opencode-usage-stats-plugin.git
cd opencode-usage-stats-plugin
bun install
ln -s "$(pwd)/src/plugin.ts" ~/.config/opencode/plugins/opencode-usage-stats.tsStart the dashboard:
bunx @sleipi/opencode-usage-statsOr with a custom port (default is 3333):
PORT=3334 bunx @sleipi/opencode-usage-statsOpens at http://localhost:3333.
The dashboard auto-refreshes every 5 seconds and shows:
- Token summary bar (Today / This Week / This Month / Last Month)
- Session cards with token breakdown and agent details
- Cache hit percentages with explanatory tooltips
All data is stored in ~/.config/opencode/usage-stats.db (SQLite). This file is not part of the repository.
For tests, you can override the DB path via OPENCODE_USAGE_STATS_DB.
Tables:
sessions— session metadata (title, directory, parent_id, timestamps)messages— per-message token counts, model, provider, costtool_calls— tool invocations with agent type tracking
The plugin hooks into OpenCode's event system:
session.created/session.updated— tracks session metadata and parent/child relationshipsmessage.updated— captures token counts, model, provider, and cost per assistant message
Subagent tokens are aggregated into their parent session in the dashboard via parent_id linking.
Run unit tests:
bun test tests/unitRun end-to-end tests (Playwright):
bun run test:e2eMIT