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)
# Global (recommended)
cd ~/.config/opencode
npm install @dong5945/opencode-quota
# Or project-level
cd <project>/.opencode
npm install @dong5945/opencode-quotaAdd the plugin to your ~/.config/opencode/tui.json (global) or <project>/.opencode/tui.json (project):
{
"plugin": [
"@dong5945/opencode-quota"
]
}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.
opencodeYou should see the quota bar at the bottom of the TUI.
| 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 |
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).
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.
opencode-quota-plugin/
├── src/
│ └── index.js # Plugin source (ES Module)
├── build.mjs # esbuild build script
├── package.json
├── dist/
│ └── tui.js # Build output
└── .gitignore
OpenCode Go TUI 插件,在 CLI 底部栏实时显示你的订阅套餐额度(滚动窗口 / 每周 / 每月)。
⚡ OpenCode Quota Rolling: 30% (28m) | Weekly: 65% (2.8d) | Monthly: 60% (19d)
# 全局安装(推荐)
cd ~/.config/opencode
npm install @dong5945/opencode-quota
# 或项目级安装
cd <项目目录>/.opencode
npm install @dong5945/opencode-quota在 ~/.config/opencode/tui.json(全局)或 <项目>/.opencode/tui.json(项目级)中添加插件:
{
"plugin": [
"@dong5945/opencode-quota"
]
}创建 ~/.config/opencode/quota-plugin.json:
{
"workspaceId": "wrk_你的工作区ID",
"cookie": "auth=你的认证Cookie; oc_locale=zh"
}如何获取这些值:
- 在浏览器中打开
https://opencode.ai/workspace/你的工作区ID/go - 打开开发者工具(F12)→ Network 标签 → 刷新页面
- 找到
/workspace/.../go的请求,复制Cookie请求头的值 workspaceId就是 URL 中的wrk_...部分
注意: auth cookie 是 Iron session token,会定期过期。过期后底部栏会显示
⚡ quota: error,只需更新配置文件中的 cookie 值即可。
opencode你应该能在 TUI 底部看到额度栏。
| 用量百分比 | 颜色 |
|---|---|
| < 50% | 绿色 |
| 50–79% | 黄色 |
| >= 80% | 红色 |
| 状态 | 显示 |
|---|---|
| 正常 | ⚡ OpenCode Quota Rolling: 30% (28m) | Weekly: 65% (2.8d) | Monthly: 60% (19d) |
| 加载中 | ⚡ OpenCode Quota loading... |
| 错误 | ⚡ quota: error |
| 未配置 | ⚡ quota: no config |
插件使用你的 auth cookie 请求 https://opencode.ai/workspace/{workspaceId}/go 页面,然后从服务端渲染的 JavaScript 中提取用量数据:
// 数据嵌入在 HTML 中,格式如下:
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}轮询间隔:2 分钟(递归 setTimeout,不会堆积请求)。
git clone https://github.com/dong5945/opencode-quota-plugin.git
cd opencode-quota-plugin
npm install
node build.mjs # 打包 + 同步到 npm 包目录构建脚本(build.mjs)通过 esbuild 将 src/index.js 打包为 dist/tui.js,并自动同步到:
~/.config/opencode/node_modules/@dong5945/opencode-quota/dist/~/.cache/opencode/packages/@dong5945/opencode-quota/.../dist/
每次构建后需重启 OpenCode 才能看到变更。
opencode-quota-plugin/
├── src/
│ └── index.js # 插件源码(ES Module)
├── build.mjs # esbuild 构建脚本
├── package.json
├── dist/
│ └── tui.js # 构建产物
└── .gitignore
MIT