Command Code providers, a live gated model list and a usage sidebar for opencode, with all usage rendering delegated to the cmduse CLI.
One package, both opencode plugin APIs: v1 hosts call the default export's server() hook map, v2 hosts decode { id, setup } and call setup(context). The two halves are independent implementations sharing one CLI layer, and neither reimplements usage math — every window figure comes from the cmduse binaries.
It registers two provider lanes against api.commandcode.ai:
command-code-anthropic— Claude models on the Anthropic wire.command-code-openai— everything else on the OpenAI-compatible wire, where the reasoning text is round-tripped throughreasoning_contentso a compaction or model switch doesn't get rejected.
The model list is fetched live from Command Code's listing API, split by wire, and gated to your plan (core/gating.json in the repo is the source of truth). The picker never waits on the network: a static seed from the known-model table, then the last live list cached on disk, paint instantly and the live fetch merges over them — union by model id, so a gated or partial response can never make a model vanish. On v2 hosts the fetch then repeats on an interval, and a tick only touches the provider registry when the model ids actually changed.
Each model is registered with Command Code's published $/1M rates, so opencode's own cost display works for a subscription provider instead of showing $0. Vision support and reasoning-effort variants come from a generated catalog, because the listing API publishes no capabilities.
That catalog is refreshed at runtime: the plugin fetches Command Code's own models.md (bundled in their published CLI, served from the npm CDN), caches it for a day under ~/.cache/command-code/catalog-live.json, and overlays prices, context windows and efforts on the baked snapshot before each model refresh — so a price change reaches a running install without waiting for a plugin release. The baked table stays as the offline and first-run fallback, and vision stays baked because it only exists in the CLI bundle. catalogSource() reports which table a given lookup used.
Credentials resolve in one order everywhere: CMD_API_KEY, then opencode's credential store (the commandcode/command-code rows, active first, newest first), then opencode's legacy auth.json, then ~/.commandcode/auth.json from cmd login. The store ranks first because a re-connect leaves both files on the key it replaced — and if the API still answers 401, the request is retried with the next candidate rather than failing the turn.
Add the plugin to opencode.json (v2 hosts use plugins; v1's singular plugin is auto-normalized):
{
"plugins": ["@jeffreyjyz/opencode-command-code"]
}Usage rendering needs the cmduse CLI on PATH — it owns the plan table, the window math and the formatting:
brew install JeffreyJYZ/tap/cmduseThe sidebar's per-model catalog (tier, rates, allowance, deals) comes from mpc, which is optional: without it the section keeps the model name and the store-backed rows and simply omits the catalog rows.
bun add -g @jeffreyjyz/mpcRun /connect, choose Command Code and paste an API key (create one at commandcode.ai/settings/keys), or use the CMD_API_KEY env method, or log in once with cmd login. With no credential at all the providers register as auto, so a later /connect lights them up without a restart.
One caveat on the v1 half: its /connect entry is bound to the Anthropic lane (opencode's plugin API allows one auth hook per provider id), so the OpenAI lane shares the key through the resolved options.apiKey — a /connect-only v1 setup needs cmd login or CMD_API_KEY for that lane.
While a session uses a Command Code, OpenCode Go/Zen, Volcengine ARK or OpenDesign model, the sidebar grows one section for that family — plain text unless you ask for colour. Write ~/.config/opencode/command-code.json:
{ "colors": true, "ocPlan": "go-plus", "odPlan": "pro" }CMD_COLORS=1 (or 0), CMD_OC_PLAN=go|go-plus, CMD_OD=1|0 and CMD_OD_PLAN=go|plus|pro|max override it for a single run. ocPlan only matters on the Go side and odPlan only on the OpenDesign side: both plans grant different limits at the same token prices, and nothing local records which one you have. The file is re-read every few seconds, so a flip lands on the next poll.
What the section shows:
- plan, price, monthly credits used, and the 5-hour / weekly windows with used / cap, percent used, elapsed share, reset countdown and a
cap in …pace estimate; an over-cap window is flaggedLIMIT EXCEEDED - this period's requests and spend, the active model's tier, allowance and $/M rates, its
Usage (this model)share, any runningDeal, and this session's own totals - on OpenCode Go/Zen and ARK sessions, the same shape from
ocuseandarkuseinstead — account meters where the provider publishes them, per-model spend from opencode's own store - on OpenDesign sessions, a section from
oduse: the plan's published caps per window, this machine's credits against each, per-model credits for the period, and the desktop app's wallet balance. Those figures come from the Open Design app's own store, so they are account-wide rather than this conversation's, and they are labelled as estimates — the store records no cache tokens, the 5-hour and 7-day cuts are local, and the wallet line is a balance, not a meter.
Usage comes from cmduse polled every 5 seconds, read from opencode's message store for the per-model and per-session rows, and cached from mpc for the catalog. Every block remembers its last reading, so a remount, a session switch or a network outage repaints instead of blanking; the model figure is keyed by model and session, so switching models never shows the previous model's numbers. The OpenDesign section is polled on the same tick from oduse, spawns nothing on the other three families, and keeps its last snapshot when the binary or the app's store is missing.
/cmd-settings is a dialog over that same file, so a view option is changed without hand-editing JSON. Seven settings, written as you pick them:
- Colours —
off(default) oron: tint status rows green/amber/red;offkeeps bold and dim only. - OpenCode plan —
go(default) orgo-plus: which per-model monthly limits the Go section renders. - OpenDesign panel —
on(default) oroff: whether an OpenDesign session grows itsodusesection. Credits there are an estimate — the app's store records no cache tokens — the 5-hour and 7-day cuts are local, and the wallet line is a balance rather than a meter. - OpenDesign plan —
go(default),plus,proormax: which published caps that section measures against; hidden while the panel isoff. - Refresh —
2s,5s(default),10s,30sor1m: account poll cadence, one CLI spawn per tick. - Local cost rows —
off(default),sessionorwindow: where the per-model$figure comes from. - Cost refresh —
30s,1m(default) or5m: how often that figure is re-scanned; hidden while cost rows areoff.
The local cost figure lives inside each message's JSON, so summing it scans the whole store — 0.5-1.9s measured on a 1.3 GiB store, on the UI thread. That is why it defaults to off, and why turning it on gives it its own slow interval instead of riding the account poll.
Each command passes its arguments through to the CLI that owns it, and each has an agent-facing tool of the same name, so the model can fetch the same text without you typing a slash command.
| Command | Tool | Spawns |
|---|---|---|
/cmd-usage |
cmd_usage |
cmduse — plan, credits, windows, billing period; plans for the plan table |
/ocuse-usage |
ocuse_usage |
ocuse — OpenCode Go/Zen meters and per-model spend; empty args mean -1 |
/arkuse-usage |
arkuse_usage |
arkuse — Volcengine ARK Agent Plan meters in AFP; empty args mean -1 |
| — | mpc_prices |
mpc — per-model price comparison across Command Code and OpenCode Go plans |
A bare ocuse or arkuse is a live watch loop that would never return to the dialog, so an empty argument means the one-shot dashboard.
- Source (GitHub)
- npm
cmduseCLI — the usage renderer this plugin spawns- MIT license