Usage
OpenCode TUI plugin that shows the active provider's usage limits (opencode-go 5h/week/month) or remaining credit (deepseek) stacked in the sidebar
0
1,053
近 7 天 46
38.6
生态多维模型
4 天前
2026-10-16
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-plugin-usage@2.0.4"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-plugin-usage@2.0.4"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-plugin-usageOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An OpenCode TUI plugin that shows your active provider's usage limits and remaining credit directly in the sidebar.
Follows whichever provider the current session is using, so the numbers you see are the ones that matter right now — refreshed before you start a query.
- opencode-go — rolling 5h / weekly / monthly usage limits as thin colored bars
- github-copilot — monthly premium requests / chat / completions quota from
api.github.com - deepseek — remaining API credit
- openrouter — remaining credit balance
- openai — remaining API credit balance
Usage limits
OpenCode Go updated just now
5h ━━━━━━━━ 78% in 55m
Week ━━━━ 37% in 2d 2h
Month ━━ 18% in 27d 15h
Limit bars are colored by severity: green <50%, amber 50–74%, orange 75–99%,
red 100%. Credit balances show in green while the account is usable, red when not.
Labels, bars, percentages, and reset countdowns use fixed-width columns so usage
updates and multiple windows stay aligned. in … is the time until that quota resets.
Requirements
- OpenCode
>= 2.0.0(V2 plugin API)
Install
opencode plugin add opencode-plugin-usage
That installs the TUI plugin and registers it in ~/.config/opencode/cli.json.
Keys are picked up automatically (see API keys).
Any options go in the cli.json entry:
{
"plugins": [
{
"package": "opencode-plugin-usage",
"options": { "providers": { "opencode-go": { "enabled": true } } }
}
]
}
Local development
git clone https://github.com/lhw/opencode-plugin-usage
cd opencode-plugin-usage
npm install
npm run typecheck # tsc --noEmit
npm test # parser + rendered layout checks (Node >=26.4)
npm run build # esbuild → dist/tui.js
OpenCode loads CLI plugins as packages from cli.json, so to try a local build
publish a prerelease (or serve npm pack output from a local registry) and run
opencode plugin add opencode-plugin-usage.
The plugin must NOT live in
~/.config/opencode/plugins/— that directory is scanned for server plugins, and opencode rejects this TUI-only module there. TUI plugins are loaded fromcli.json.
Configuration
All options are optional. They go in the options object of the plugin's
cli.json entry:
{
"plugins": [
{
"package": "opencode-plugin-usage",
"options": {
"refreshMs": 300000, // how often to re-fetch usage (ms)
"minRefreshMs": 30000, // minimum interval between extra refreshes (ms)
"timeoutMs": 10000, // per-request timeout (ms)
"default": "opencode-go", // provider shown when the active provider has no usage source
"providers": {
"opencode-go": { "enabled": true }, // apiKey is optional, see below
"deepseek": { "enabled": true, "apiKey": "sk-…" }
}
}
}
]
}
| Option | Default | Description |
|---|---|---|
enabled |
true |
show/hide this provider |
apiKey |
resolved automatically | explicit key override |
API keys
For providers other than OpenAI, credentials resolve from OpenCode in this order:
providers.<id>.apiKeyin the plugin optionsOPENCODE_AUTH_CONTENT(opencode's injectable auth file)- active OpenCode credential (V2 SQLite credential store)
- legacy
auth.jsonin OpenCode's data directory - the provider's env var (see table below)
So if you've already connected a provider in opencode (opencode auth login or
/connect), no extra configuration is needed.
OpenAI Codex uses the OpenCode OAuth access token and account ID for Codex
subscription limits. An OpenAI Platform API key (OPENAI_API_KEY or
providers.openai.apiKey) cannot access those limits and is not used.
| Provider | Credential source |
|---|---|
| opencode-go | OPENCODE_API_KEY |
| github-copilot | GITHUB_TOKEN (GH_TOKEN also) |
| deepseek | DEEPSEEK_API_KEY |
| openrouter | OPENROUTER_API_KEY |
| openai | OpenCode OAuth login |
Providers
| Provider | Source | Display |
|---|---|---|
| opencode-go | https://opencode.ai/zen/go/v1/usage |
5h/week/month windows + bars |
| github-copilot | https://api.github.com/copilot_internal/user |
premium/chat/completions + bars |
| deepseek | https://api.deepseek.com/user/balance |
remaining credit |
| openrouter | https://openrouter.ai/api/v1/credits |
remaining credit (credits − usage) |
| openai | https://chatgpt.com/backend-api/wham/usage |
Codex 5h + weekly quota windows |
Adding a provider is one new file in src/providers/ implementing the Provider
interface (key resolution + a fetchUsage) and adding it to the providers array
in src/tui.ts.
How it works
- A
Plugin.defineTUI plugin (@opencode/plugin/tui) that renders into thesidebar.contentslot via@opentui/solid. - Detects the active provider from the last assistant message's
model.providerID, falling back to opencode's configured default model. - Refreshes before you query: on startup, on new session, when a session goes
busy, onsession.idle, and everyrefreshMs. Extra triggers are throttled to at most one fetch perminRefreshMs, so balance/usage stays fresh without hammering the APIs. - Self-heals if data is missing (e.g. after loading an existing session): a signal-driven repaint + a 5-second check re-fetch until data is shown.
Development
npm run typecheck # tsc --noEmit
npm test # parser + rendered layout checks (Node >=26.4)
npm run build # esbuild → dist/tui.js
npm publish # runs typecheck + build + test first
License
MIT
同类生态推荐
Tui Quota Usage
opencode-tui-quota-usage
OpenCode quota usage sidebar tracker for OpenCode V2 CLI/TUI
Go Limits
opencode-go-limits
OpenCode TUI sidebar widget: opencode Go subscription usage limits (session/weekly/monthly) as bars + percentages
Usage Limits
opencode-usage-limits
Show OpenCode Go and ClinePass subscription usage (5-hour / weekly / monthly) in the OpenCode TUI sidebar.