opencode-token-bar
v0.1.2
Published
OpenCode TUI plugin that shows daily token usage (in/out) and current context-window percentage in the bottom bar
Maintainers
Readme
opencode-token-bar
An opencode TUI plugin that renders a compact, color-coded token-usage line in the bottom bar:
day ↑31.5K ↓12.3K │ ctx 16%↑/↓— total tokens used today, summed across every session and project.↑(input) = input + cache read + cache write;↓(output) = output- reasoning. Arrows and labels are dimmed; the numbers use the theme's text color.
ctx 16%— the current session's context-window usage, using the same formula opencode shows internally:(input + output + reasoning + cache.read + cache.write) / model context limit. Colored by how full the window is — green <60%, yellow <85%, red otherwise.
The bar is shown only while a session is open — it is hidden on the home screen. Colors come from the active opencode theme, so it blends in with the rest of the TUI.
How it works
This is a TUI plugin. It:
- Reads today's usage straight from opencode's own database
(
~/.local/share/opencode/opencode.db, or under$XDG_DATA_HOME). A single aggregate query sums thetokensof every assistant message created today across all sessions and projects — so the bar shows the real daily total immediately, even right after launch. - Subscribes to
message.updatedto re-query the total as work happens and to compute the current session's context percentage. - Registers an
app_bottomslot, rendered only while a session is open.
The daily total rolls over automatically at local midnight. The database is opened read-only; if it can't be read the bar simply shows nothing.
Install
Install it as an opencode TUI plugin:
opencode plugin opencode-token-barThis adds opencode-token-bar to the plugin array in
~/.config/opencode/tui.json. Restart opencode and the bar appears at the
bottom. You can also add it by hand:
{
"plugin": ["opencode-token-bar"]
}Develop locally
bun install
bun run build # -> dist/tui.js
bun testTo run your local build instead of the published package, point the TUI config
at the project directory (opencode loads dist/tui.js from the package main):
{
"plugin": ["/home/you/path/to/opencode-token-bar"]
}License
MIT © Lilithya <me@lilithya>
