npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-go-usage-tui

v1.3.4

Published

OpenCode TUI plugin displaying OpenCode Go usage in the sidebar

Readme

opencode-go-usage-tui

🌏 语言 / Language: 简体中文 | English

在 OpenCode 侧边栏实时显示 OpenCode Go 额度用量(5小时/每周/每月)与模型请求限额。

支持中英双语界面(/go-lang 切换,首次启动自动引导选择语言)。

功能

  • 双独立面板Go 用量(额度百分比 + 进度条)+ 模型限额,可独立折叠
  • 模型限额一览:折叠行显示各模型用量上限($),点击行内展开查看价格明细与完整请求数限额(每5小时/每周/每月)
  • 多档价格分档展示:支持按上下文分档计价的模型(如 GPT 5.6 Luna ≤272K / >272K、DeepSeek V4 Off-Peak / Peak),逐档列出输入/输出/缓存价
  • 变化高亮与记录:新增模型=绿色、价格变化=蓝色、限额变化=橙色;展开可见同档位涨跌箭头;面板底部显示最近一次变化的明细清单
  • 关注模型/go-settings 设置关注的白名单,只显示你关心的模型
  • 刷新间隔可调:用量刷新和限额刷新间隔均可通过 /go-settings 设置(秒)
  • 安全加密:auth cookie 用 AES-256-GCM 加密存储,旧明文自动迁移
  • 自动提醒:价格/限额变化时弹 toast 通知,变化历史保留最近 10 次

安装

方式一:OpenCode 命令安装(推荐)

在 OpenCode 中按 Ctrl+P 打开命令面板,搜索 install plugin,输入:

opencode-go-usage-tui@latest

回车完成安装,重启 OpenCode 后侧边栏即可看到两个面板。

方式二:npm 全局安装

npm install -g opencode-go-usage-tui

然后在 ~/.config/opencode/tui.jsonplugin 数组添加:

{
  "plugin": ["opencode-go-usage-tui@latest"]
}

重启 OpenCode 生效。

配置

方式一:斜杠命令(推荐)

在 TUI 中执行:

/go-config

按提示输入两项(每人不同,需登录 opencode.ai 获取):

  1. workspace_idwrk_ 开头,在 opencode.ai 控制台 URL 中获取
  2. auth cookie:浏览器 F12 → Application → Cookies → opencode.ai → 复制 auth 的值(Fe26.2* 开头)

配置保存在 ~/.config/opencode/

  • go-usage-config.json — workspace_id(明文,非敏感)
  • go-auth-cookie.enc — auth cookie(AES-256-GCM 加密
  • .encryption-key — 加密密钥(32 字节随机生成)

🔒 安全说明:cookie 以 AES-256-GCM 加密存储,密钥随机生成且独立保存,文件被备份/同步/日志收集不会泄露 cookie。旧版明文文件(go-auth-cookie.txt / config.json 内嵌 cookie)首次读取时自动迁移为加密存储并清理明文。

⚠️ 局限:密钥与密文同目录,能防御"被动泄露"(备份/同步),无法防御能读取该目录的本地恶意程序。如需更强保护可改用系统级凭据存储。

方式二:环境变量

| 环境变量 | 说明 | | -------- | ---- | | OPENCODE_GO_WORKSPACE_ID | 工作空间 ID | | OPENCODE_GO_AUTH_COOKIE | auth cookie 值 |

方式三:配置文件

手动创建 ~/.config/opencode/go-usage-config.json

{
  "workspace_id": "wrk_xxxxxxxxxxxx",
  "cookie": "Fe26.2*...",
  "ui": {
    "usage_panel": true,
    "price_panel": true
  },
  "focus_models": ["grok-4-5"],
  "refresh_interval_sec": 60,
  "pricing_interval_sec": 1800
}

| 字段 | 说明 | | ---- | ---- | | ui.usage_panel | 显示/隐藏用量面板(默认 true) | | ui.price_panel | 显示/隐藏限额面板(默认 true) | | focus_models | 关注模型白名单(空数组显示全部) | | refresh_interval_sec | 用量刷新间隔秒数(默认 60) | | pricing_interval_sec | 限额刷新间隔秒数(默认 1800) |

获取 auth cookie

  1. Chrome 登录 opencode.ai
  2. 按 F12 打开开发者工具 → Application → Cookies → 选中 opencode.ai
  3. 找到 auth 一项,复制 Value 值

Cookie 有效期约 1 年,过期后重新获取。

使用

  • /go-config:设置 workspace_id 和 auth cookie
  • /go-settings:设置关注模型、用量刷新间隔、限额刷新间隔
  • /go-lang:切换 中文 / English
  • 用量超过阈值(默认 80%,可用 OPENCODE_GO_WARN_THRESHOLD 调整)显示为红色
  • 点击面板标题可折叠/展开
  • 面板标题显示当前插件版本号(如 v1.3.4

模型请求限额面板

  • 折叠行:模型名 + 用量上限($),两端对齐、永不折行;点击任意行展开详情
  • 展开详情(逐行清单):
    • 价格明细——多档模型按档位逐块列出输入/输出/缓存读/缓存写($/MTok),价格变化时带 ↑/↓ 涨跌箭头
    • 请求限额——每5小时 / 每周 / 每月的完整精确请求数(千分位显示,如 2,050
    • 元数据——SDK、数据保留期、训练用途
  • 数据从 opencode.ai/docs/go 实时抓取公开页面(无需登录)
  • 默认每 30 分钟自动刷新(可用 /go-settingspricing_interval_sec 调整)
  • 每次刷新自动对比上次数据:
    • 变化行着色:新增=绿、价格变化=蓝、限额变化=橙,点击展开查看细节
    • toast 提醒 + 面板底部"限额变化记录"清单,历史保留最近 10 次到 go-pricing-data.json
  • 额度达到 100%(rate-limited 状态)时仍正常显示用量与重置时间,不会出现"查询失败"

语言

  • 首次安装启动时自动弹出语言选择,选择后若未配置账号会继续引导 /go-config
  • 随时执行 /go-lang 可切换 中文 / English,语言偏好会记住
  • 自动检测系统语言(中文系统默认中文,其余默认英文)

开发

# 构建
bun run build.tui.mjs
# 或
npm run build

License

MIT