OpenCode Go usage in the opencode TUI sidebar, plus a
go_usagetool so agents can check availability before they delegate.
OpenCode Go has three limits: a rolling 5-hour window, a weekly limit and a monthly allowance. Once one is used up, every opencode-go/* model returns errors until it resets. This plugin reads the official usage endpoint and shows all three, so you see the limit coming and an orchestrating agent can route around it.
Restart opencode.
GO
5h [███ 30.0% ░░░] 2h 10m
wk [█ 12.0% ░░░░░] 1d 11h
mo [████ 40.0% ░░] 18d 11h
One bar per limit, using the shared ProgressBar from @four-bytes/opencode-plugin-lib (centred percent label, black or white by contrast). Colours come from the active opencode theme: title in accent (as in deepseek-meter), labels in text, reset times in textMuted, the track in backgroundElement (mapping via statusThemeFromOpencode from the lib, ≥ v0.13.0), the fill per meter in
success— below 80 %warning— 80 % or moreerror— limit used up (rate-limited)
Refreshes on start and after assistant messages (at most every 30 s).
Error states: NO KEY, KEY ERROR <code> (key file exists but is unreadable), INVALID KEY (401, e.g. expired key), NO GO SUBSCRIPTION (403), API <status>, BAD RESPONSE, unreachable.
No arguments. The first line can be checked without parsing the rest:
available: yes
5-hour: 30% used, ok, resets in 2h 10m
weekly: 12% used, ok, resets in 1d 11h
monthly: 40% used, ok, resets in 18d 11h
available: no when any meter reports rate-limited or 100 %. available: unknown with an error: line when the usage could not be read. The tool never throws.
Example rule for an orchestrator agent: before delegating to an opencode-go/* agent, call go_usage; on available: no, use the non-Go fallback agent.
| Option | Default | Effect |
|---|---|---|
extraUsage |
false |
Set to true when extra usage is enabled on the Go account. An exhausted limit then keeps available: yes (with an extra usage: active line) and its bar turns warning instead of error. The usage endpoint does not report this setting, so it has to be configured. |
// opencode.json and tui.json
{ "plugin": [["/home/user/four-opencode-go-meter/", { "extraUsage": true }]] }The Go API key is taken from the first source that has one:
auth.jsonin the opencode data dir, entryopencode-go, thenopencode(a new console key may land there) —$XDG_DATA_HOME/opencode/auth.json, default~/.local/share/opencode/auth.json(written byopencode auth login→ OpenCode Go)auth.jsonin the opencode state dir (fallback)~/.secrets/opencode-go-key(plain text file)- Environment variable
OPENCODE_GO_API_KEY, thenOPENCODE_API_KEY
All found keys are tried in this order until one is not rejected with 401, so an expired key in one entry does not hide a valid one in another. A malformed auth.json is skipped. The state-dir fallback (2) is only available to the sidebar; the go_usage tool runs in the server process, which has no state path, and uses 1, 3 and 4. Expired keys are not renewed by signing in again — create a new key in the OpenCode console.
bun install
bun run build
bunx tsc --noEmit
bun test