Skip to content

OpenCode Usage

Shows your OpenCode Go subscription usage in the bar. Data comes from OpenCode’s usage API (GET https://opencode.ai/zen/go/v1/usage), which tracks the 5-hour rolling, weekly, and monthly windows.

Setup

If you use OpenCode Go in OpenCode, there’s nothing to configure: the module picks up the key OpenCode already has in auth.json. Just add it to your bar config:

{
    "modules-right": ["opencode-usage"],
    "modules": {
        "opencode-usage": {
            "type": "opencode_usage"
        }
    }
}

API key

The module looks for a key in this order, using the first one it finds:

  1. api_key in the module config
  2. The OPENCODE_API_KEY environment variable
  3. opencode / opencode_go in pybar’s credentials.json ({ "api_key": "..." })
  4. The key OpenCode keeps in ~/.local/share/opencode/auth.json (opencode-go, falling back to opencode; honors XDG_DATA_HOME)

Configuration

KeyTypeDefaultDescription
intervalinteger300Seconds between usage checks
api_keystring''OpenCode Go API key (leave empty to auto-detect)
displaychoicemonthlyWindow shown in the bar: monthly, weekly, rolling, or worst
show_remainingbooleanfalseShow remaining percent instead of used percent
formatstring'{}%'Bar label format, with {} as the percent
iconstring'\uf121'Icon shown before the text (empty string to hide)
warninteger80Percent at which the widget turns orange
criticalinteger95Percent at which the widget turns red
per_modelbooleantrueShow per-model cost from OpenCode’s local database
models_showninteger5How many models to list in the popover
db_pathstring''Override the OpenCode database path

Notes

  • Clicking the module opens a popover with a bar for each window and its reset time underneath.
  • The widget turns orange at the warn threshold and red at critical.
  • The “By model” section lists the top models by cost for the selected window, read from OpenCode’s local database (session_v2). It only covers sessions from this machine and is approximate, so it won’t exactly match the dashboard; free and non-Go providers aren’t counted.
  • Go-only: a key without a Go subscription gets a 403 and the module stays hidden. Zen balance isn’t covered since there’s no official API for it.
  • If the key is missing or the request fails, the module hides instead of showing stale data.