Skip to content

Repository files navigation

opencode-token-tracker

CI

Real-time token usage, cost, and request tracking for every AI request in OpenCode.


🆕 TUI Version (RECOMMENDED) - token-tracker.tsx

Displays tokens directly in the OpenCode sidebar footer, in real-time during agent execution — no popups or toasts.

⏳ last: in: 70.0k · out: 1.2k · 1 req · $0.04
📊 total: in: 1.2m · out: 0.3m · 42 reqs · $1.23

When the agent finishes:

✓ last: in: 70.0k · out: 1.2k · 1 req · $0.04
📊 total: in: 1.2m · out: 0.3m · 42 reqs · $1.23

Lines:

  • /last — tokens and cost of the last request (useful to see the cost of each individual interaction)
  • 📊total — cumulative for the entire session (tokens in, out, request count, and total cost)

Updates: every 2 seconds during execution.

Installation

1. Copy the plugin:

curl -sL https://github.com/eserete/opencode-token-tracker/raw/main/token-tracker.tsx \
-o ~/.config/opencode/plugins/token-tracker.tsx

2. Register it in tui.json (~/.config/opencode/tui.json):

{
"$schema": "https://opencode.ai/config/tui.json",
"plugin": ["./plugins/token-tracker.tsx"]
}

3. Restart OpenCode and open the sidebar with Ctrl+X B.

Requirements

  • OpenCode v1.4.3+
  • Sidebar must be open (Ctrl+X B) for the footer to be visible

Real-time Toast Version - token-tracker-realtime.js

Shows tokens in real-time via a toast notification during agent execution:

⏳ 1.2k tokens · 12 reqs · $0.05

Installation:

curl -sL https://github.com/eserete/opencode-token-tracker/raw/main/token-tracker-realtime.js \
-o ~/.config/opencode/plugins/token-tracker-realtime.js

Classic Version (Toast) - token-tracker.js

Shows a toast after each request completes:

[tokens] in: 45,231 | out: 1,204 | cache↓: 120,000 | t: 4.2s | $0.0032 | reqs: 3

Installation:

curl -sL https://github.com/eserete/opencode-token-tracker/raw/main/token-tracker.js \
-o ~/.config/opencode/plugins/token-tracker.js

Which version should I use?

FeatureTUI Slot (tsx)Real-time ToastClassic
InterfaceSidebar footerToast/popupToast/popup
When it showsAlways visibleDuring executionAfter completion
Last vs Total✅ Both❌ Total only✅ Per request
CompatibilityOpenCode v1.4.3+All versionsAll versions
Update frequencyEvery 2sEvery 2sOnce

Recommendation: Use token-tracker.tsx (TUI) — it's the most complete and doesn't interrupt your workflow.


Configuration

No additional configuration required beyond the installation steps above.

Important: After installing or updating, restart OpenCode for the plugin to be reloaded.


Field Reference (Classic Version)

FieldDescription
inInput tokens
outOutput tokens
thinkReasoning tokens
cache↓Cache read tokens
cache↑Cache write tokens
tLatency in seconds
$Message cost
sessionCumulative session cost
modelProvider/model
reqsNumber of requests
finishFinish reason
[+N subagents]Aggregated subagents

Features

  • Zero configuration - copy and it works
  • No popups - integrated display in the OpenCode UI
  • Last vs Total - see the cost of each interaction separately from the session total
  • Subagent-aware - aggregates tokens automatically
  • Non-intrusive - errors are silent
  • Real-time - track usage while the agent works

Limitations

  • Cost accuracy depends on the provider reporting correctly
  • No persistence across sessions
  • TUI version requires the sidebar to be open for the footer to appear
  • Updates every 2 seconds (not instantaneous)

License

MIT

About

OpenCode plugin that tracks token usage, cost, and latency per request

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages