Skip to content

About

opencode plugin: OpenCode Go usage (5h / weekly / monthly) in the TUI sidebar + go_usage tool for agents

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

@four-bytes/four-opencode-go-meter

OpenCode Go usage in the opencode TUI sidebar, plus a go_usage tool so agents can check availability before they delegate.

license bun

Why?

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.

Quickstart

// ~/.config/opencode/opencode.json — server part (go_usage tool)
{ "plugin": ["/home/user/four-opencode-go-meter/"] }

// ~/.config/opencode/tui.json — TUI part (sidebar)
{ "plugin": ["/home/user/four-opencode-go-meter"] }

Restart opencode.

TUI Sidebar

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 more
  • error — 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.

Tool go_usage

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.

Options

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 }]] }

Configuration

The Go API key is taken from the first source that has one:

  1. auth.json in the opencode data dir, entry opencode-go, then opencode (a new console key may land there) — $XDG_DATA_HOME/opencode/auth.json, default ~/.local/share/opencode/auth.json (written by opencode auth login → OpenCode Go)
  2. auth.json in the opencode state dir (fallback)
  3. ~/.secrets/opencode-go-key (plain text file)
  4. Environment variable OPENCODE_GO_API_KEY, then OPENCODE_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.

Development

bun install
bun run build
bunx tsc --noEmit
bun test

License

Apache-2.0 — see LICENSE and NOTICE.

About

opencode plugin: OpenCode Go usage (5h / weekly / monthly) in the TUI sidebar + go_usage tool for agents

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages