Package Exports
- opencode-token-tracker
- opencode-token-tracker/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (opencode-token-tracker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
opencode-token-tracker
Real-time token usage and cost tracking plugin for OpenCode.

Features
- Real-time Toast notifications - See token usage and cost after each AI response
- Session statistics - Track cumulative usage across your entire session
- CLI statistics tool - Query usage by day/week/month with breakdowns by model/agent
- Cost calculation - Automatic cost estimation based on model pricing
- JSONL logging - All usage data saved locally for analysis
- Multi-model support - Claude, GPT, DeepSeek, Gemini, and more
Installation
Add to your OpenCode config file (~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-token-tracker"]
}Restart OpenCode and the plugin will be automatically installed.
Usage
Toast Notifications
Once installed, you'll see Toast notifications after each AI response:
12.5K tokens
$0.023 | Session: $0.156When a session becomes idle, you'll see a summary:
Session: 45.2K tokens
$0.156 | 8 msgs | 5minCLI Statistics
Query your token usage from the command line:
# All-time summary
opencode-tokens
# Today's usage
opencode-tokens today
# This week's usage with model breakdown
opencode-tokens week --by model
# This month with all breakdowns
opencode-tokens month --by all
# Day-by-day breakdown
opencode-tokens --by dailyExample output:
Today's Usage
──────────────────────────────────────────────────
Total Tokens: 2.81M
Input: 2.74M
Output: 72.9K
Reasoning: 7.1K
Cache Read: 12.62M
Total Cost: $32.93
Messages: 230
By Model
─────────────────────────────────────────────────────
Model Tokens Cost Msgs
--------------- ---------- ---------- ------
claude-opus-4.5 2.70M $32.93 206
deepseek-chat 23.4K $0.0025 6
gpt-5.2 86.9K $0.0000 18Breakdown options (--by):
model- Group by model (e.g., claude-opus-4.5)agent- Group by agent (e.g., sisyphus, coder)provider- Group by provider (e.g., anthropic, openai)daily- Show day-by-day breakdownall- Show all breakdowns
Log Files
Token usage is logged to:
~/.config/opencode/logs/token-tracker/tokens.jsonlEach line is a JSON object:
{
"type": "tokens",
"sessionId": "ses_xxx",
"messageId": "msg_xxx",
"agent": "build",
"model": "claude-opus-4.5",
"provider": "github-copilot",
"input": 1500,
"output": 350,
"reasoning": 0,
"cacheRead": 5000,
"cacheWrite": 0,
"cost": 0.0234,
"_ts": 1234567890123
}Supported Models
| Provider | Models |
|---|---|
| Anthropic | Claude Opus 4.5, Sonnet 4/4.5, Haiku 4/4.5 |
| OpenAI | GPT-5.x, GPT-4.x, o1, o3 |
| DeepSeek | deepseek-chat, deepseek-reasoner |
| Gemini 2.x, 3.x |
Unknown models use a default pricing estimate.
Configuration
Create a config file at ~/.config/opencode/token-tracker.json:
{
"providers": {
"github-copilot": { "input": 0, "output": 0 }
},
"models": {
"my-custom-model": { "input": 1, "output": 2 }
},
"toast": {
"enabled": true,
"duration": 3000,
"showOnIdle": true
}
}Pricing Override
Pricing is resolved in this order (first match wins):
- Provider-level - Override all models for a provider
- User model config - Custom model pricing in config file
- Built-in pricing - Default pricing table
- Fallback - $1/M input, $4/M output
Example: Free providers
If you're using GitHub Copilot or other subscription-based services, set their cost to $0:
{
"providers": {
"github-copilot": { "input": 0, "output": 0 },
"cursor": { "input": 0, "output": 0 }
}
}Example: Custom model pricing
Override or add pricing for specific models:
{
"models": {
"claude-opus-4.5": { "input": 12, "output": 60, "cacheRead": 1.2 },
"my-local-model": { "input": 0, "output": 0 }
}
}Toast Settings
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Show toast notifications |
duration |
number | 3000 |
Toast display duration (ms) |
showOnIdle |
boolean | true |
Show session summary on idle |
Development
# Clone the repo
git clone https://github.com/tongsh6/opencode-token-tracker.git
cd opencode-token-tracker
# Install dependencies
npm install
# Build
npm run build
# Link for local testing
npm link
cd ~/.config/opencode
npm link opencode-token-trackerLicense
MIT © tongsh6
Related
- OpenCode - The AI coding assistant
- OpenCode Plugins - Plugin documentation
- oh-my-opencode - OpenCode enhancement plugin