Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@dong5945/opencode-quota

English | 中文


English

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-quota

2. 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:

  1. Open https://opencode.ai/workspace/YOUR_WORKSPACE_ID/go in your browser
  2. Open DevTools (F12) → Network tab → refresh the page
  3. Find the request to /workspace/.../go, copy the Cookie header value
  4. The workspaceId is the wrk_... 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

opencode

You 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 dirs

The build script (build.mjs) bundles src/index.jsdist/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
└── .gitignore

中文

OpenCode Go TUI 插件,在 CLI 底部栏实时显示你的订阅套餐额度(滚动窗口 / 每周 / 每月)。

⚡ OpenCode Quota  Rolling: 30% (28m) | Weekly: 65% (2.8d) | Monthly: 60% (19d)

安装

1. 安装 npm 包

# 全局安装(推荐)
cd ~/.config/opencode
npm install @dong5945/opencode-quota

# 或项目级安装
cd <项目目录>/.opencode
npm install @dong5945/opencode-quota

2. 配置 tui.json

~/.config/opencode/tui.json(全局)或 <项目>/.opencode/tui.json(项目级)中添加插件:

{
  "plugin": [
    "@dong5945/opencode-quota"
  ]
}

3. 创建配置文件

创建 ~/.config/opencode/quota-plugin.json

{
  "workspaceId": "wrk_你的工作区ID",
  "cookie": "auth=你的认证Cookie; oc_locale=zh"
}

如何获取这些值:

  1. 在浏览器中打开 https://opencode.ai/workspace/你的工作区ID/go
  2. 打开开发者工具(F12)→ Network 标签 → 刷新页面
  3. 找到 /workspace/.../go 的请求,复制 Cookie 请求头的值
  4. workspaceId 就是 URL 中的 wrk_... 部分

注意: auth cookie 是 Iron session token,会定期过期。过期后底部栏会显示 ⚡ quota: error,只需更新配置文件中的 cookie 值即可。

4. 重启 OpenCode

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

License

MIT

About

OpenCode Go TUI plugin - display subscription quota/usage in the bottom bar

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages