@dong5945/opencode-quota
v0.1.0
Published
OpenCode Go TUI plugin - display subscription quota/usage in the bottom bar
Downloads
59
Readme
@dong5945/opencode-quota
OpenCode Go TUI plugin that displays your subscription quota usage (rolling / weekly / monthly) in the bottom bar of the CLI.
⚡ OpenCode Quota Rolling: 30% (28m) | Weekly: 65% (2.8d) | Monthly: 60% (19d)Installation
1. Install the npm package
# Global (recommended)
cd ~/.config/opencode
npm install @dong5945/opencode-quota
# Or project-level
cd <project>/.opencode
npm install @dong5945/opencode-quota2. Configure tui.json
Add the plugin to your ~/.config/opencode/tui.json (global) or <project>/.opencode/tui.json (project):
{
"plugin": [
"@dong5945/opencode-quota"
]
}3. Create config file
Create ~/.config/opencode/quota-plugin.json:
{
"workspaceId": "wrk_YOUR_WORKSPACE_ID",
"cookie": "auth=YOUR_AUTH_COOKIE; oc_locale=zh"
}How to get these values:
- Open
https://opencode.ai/workspace/YOUR_WORKSPACE_ID/goin your browser - Open DevTools (F12) → Network tab → refresh the page
- Find the request to
/workspace/.../go, copy theCookieheader value - The
workspaceIdis thewrk_...part in the URL
Note: The auth cookie is an Iron session token and will expire periodically. When it expires, the bar will show
⚡ quota: error. Simply update the cookie value in the config file.
4. Restart OpenCode
opencodeYou should see the quota bar at the bottom of the TUI.
Display
| Usage % | Color | |---------|-------| | < 50% | Green | | 50–79% | Yellow | | >= 80% | Red |
| State | Display |
|-------|---------|
| Normal | ⚡ OpenCode Quota Rolling: 30% (28m) \| Weekly: 65% (2.8d) \| Monthly: 60% (19d) |
| Loading | ⚡ OpenCode Quota loading... |
| Error | ⚡ quota: error |
| No config | ⚡ quota: no config |
How It Works
The plugin fetches the HTML page at https://opencode.ai/workspace/{workspaceId}/go using your auth cookie, then extracts usage data from the server-side rendered JavaScript:
// Data is embedded in the HTML like:
rollingUsage:$R[35]={status:"ok",resetInSec:1843,usagePercent:22}
weeklyUsage:$R[36]={status:"ok",resetInSec:239197,usagePercent:62}
monthlyUsage:$R[37]={status:"ok",resetInSec:1650407,usagePercent:59}Polling interval: 2 minutes (recursive setTimeout, no request stacking).
Development
git clone https://github.com/dong5945/opencode-quota-plugin.git
cd opencode-quota-plugin
npm install
node build.mjs # Bundle + sync to npm package dirsThe build script (build.mjs) bundles src/index.js → dist/tui.js via esbuild and auto-syncs to:
~/.config/opencode/node_modules/@dong5945/opencode-quota/dist/~/.cache/opencode/packages/@dong5945/opencode-quota/.../dist/
Restart OpenCode after each build to see changes.
Project Structure
opencode-quota-plugin/
├── src/
│ └── index.js # Plugin source (ES Module)
├── build.mjs # esbuild build script
├── package.json
├── dist/
│ └── tui.js # Build output
└── .gitignoreLicense
MIT
