7
近 30 天 +5
787
近 7 天 50
50.1
生态多维模型
12 天前
2026-09-23
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-sidebar-token-metrics@0.1.4"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-sidebar-token-metrics@0.1.4"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-sidebar-token-metricsOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
English | 简体中文
An OpenCode TUI plugin that adds a live metrics block to the sidebar:
Speed 12.4 tok/s
Cache 87%
TTFT 3.9s
| Metric | Meaning |
|---|---|
| Speed | Average generation speed: (output + reasoning tokens) / total generation time across completed assistant messages. |
| Cache | Prompt cache hit rate: cacheRead / (input + cacheRead + cacheWrite). |
| TTFT | Average time-to-first-token: for each assistant message, the earliest content item's time.created minus the message's time.created. Summary messages and messages with no content yet are skipped. |
Install
opencode plugin add opencode-sidebar-token-metrics
Or add it to your ~/.config/opencode/cli.json:
{
"plugins": ["opencode-sidebar-token-metrics"]
}
Restart the OpenCode TUI to see the metrics block.
Requirements
- OpenCode v2
- Terminal wide enough to show the sidebar (the block renders in
sidebar.content)
solid-js, @opentui/core, and @opentui/solid are peer dependencies resolved by the OpenCode runtime — you do not install them yourself.
The published entrypoint is pre-built (dist/tui.js, compiled with TypeScript using the @opentui/solid JSX runtime), so the OpenCode runtime never has to transpile TSX with an ambiguous JSX setting.
Development
# build dist/tui.js (also runs automatically via prepack before npm pack/publish)
bun run build
# try it locally without publishing
ln -s "$(pwd)/dist/tui.js" ~/.config/opencode/plugins/token-metrics/tui.js
dist/ is a build artifact and is gitignored; prepack regenerates it on every pack/publish.
Plugin id: top.youngxhui.sidebar.tokenmetrics
License
MIT
简体中文
English | 简体中文
一个 OpenCode TUI 插件,在侧边栏添加实时指标块:
Speed 12.4 tok/s
Cache 87%
TTFT 3.9s
| 指标 | 含义 |
|---|---|
| Speed | 平均生成速度:所有已完成的 assistant 消息的 (output + reasoning tokens) / 总生成耗时。 |
| Cache | 提示词缓存命中率:cacheRead / (input + cacheRead + cacheWrite)。 |
| TTFT | 平均首 token 返回时延(Time To First Token):对每条 assistant 消息,取其最早 content 项的 time.created 减去消息自身的 time.created。跳过 summary 消息和尚无 content 的消息。 |
安装
opencode plugin add opencode-sidebar-token-metrics
或者在 ~/.config/opencode/cli.json 中添加:
{
"plugins": ["opencode-sidebar-token-metrics"]
}
重启 OpenCode TUI 即可看到指标块。
环境要求
- OpenCode v2
- 终端宽度足以显示侧边栏(该块渲染在
sidebar.content槽位)
solid-js、@opentui/core、@opentui/solid 是 peer 依赖,由 OpenCode 运行时解析 —— 无需自行安装。
发布包的入口是预构建产物(dist/tui.js,用 TypeScript 配合 @opentui/solid JSX runtime 编译),因此 OpenCode 运行时无需再转译 TSX,也就不会遇到 JSX runtime 歧义问题。
本地开发
# 构建 dist/tui.js(npm pack/publish 前会通过 prepack 自动执行)
bun run build
# 不发布、直接本地试用
ln -s "$(pwd)/dist/tui.js" ~/.config/opencode/plugins/token-metrics/tui.js
dist/ 是构建产物,已被 gitignore;prepack 会在每次 pack/publish 时重新生成。
插件 id:top.youngxhui.sidebar.tokenmetrics
许可证
MIT
同类生态推荐
Skills Tui
opencode-skills-tui
OpenCode TUI plugin that shows skills and loaded state in the sidebar
Timeline
@memef1f1y/opencode-timeline-plugin
Conversation history node viewer for the OpenCode TUI (sidebar timeline)
Tui Context
opencode-tui-context
OpenCode TUI plugin that renders session context-window usage as a segmented bar in the sidebar