opencode-throughputReal-time LLM performance monitoring plugin for OpenCode. Tracks TTFT, TPS, latency, token usage and cost per model with a TUI sidebar display.
25
近 30 天 +1
658
近 7 天 186
44.3
生态多维模型
4 个月前
2026-04-21
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-throughput@2.1.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-throughput@2.1.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-throughputopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Real-time LLM performance monitoring plugin for OpenCode. Tracks latency, throughput, token usage, and cost per model with toast notifications and JSONL logging.
Features
- TTFT (Time To First Token) — measures how fast the model starts generating
- TPS (Tokens Per Second) — generation throughput during streaming
- Total Latency — end-to-end request time
- Token Usage — input, output, reasoning, cache read/write
- Cost Tracking — per-request and cumulative cost
- Toast Notifications — real-time performance summary after each LLM response
- JSONL Logging — persistent logs at
~/.opencode/throughput.jsonl - Benchmark Tool — query historical stats on demand from the AI agent
Installation
Add to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-throughput"]
}
OpenCode will automatically install the plugin from npm at startup.
Usage
Once installed, the plugin runs automatically:
After each LLM response, a toast notification appears with metrics:
claude-sonnet-4 | 2.1s TTFT | 58.3 tok/s | 4.2s | ↑1.2k ↓892Logs are written to
~/.opencode/throughput.jsonl(one JSON object per line)Query benchmarks — ask the AI agent to use the
benchmarktool:"Show me the benchmark stats for claude" "Compare model performance" "Show the last 10 requests"
Benchmark Tool Args
| Arg | Type | Description |
|---|---|---|
model |
string (optional) | Filter by model name (partial match) |
last |
number (optional) | Only show the last N entries |
Log Format
Each line in ~/.opencode/throughput.jsonl:
{
"ts": "2026-03-21T10:00:00.000Z",
"model": "anthropic/claude-sonnet-4",
"providerID": "anthropic",
"modelID": "claude-sonnet-4",
"sessionID": "abc123",
"messageID": "def456",
"ttft_ms": 2100,
"tps": 58.3,
"latency_ms": 4200,
"inputTokens": 1200,
"outputTokens": 892,
"reasoningTokens": 0,
"cacheReadTokens": 500,
"cacheWriteTokens": 200,
"cost": 0.0234,
"finish": "stop"
}
How It Works
The plugin hooks into OpenCode's event system:
message.updated— capturesAssistantMessage.time.completed,tokens, andcostmessage.part.updated— captures the firstTextPart.time.startfor TTFT calculation
Development
Local development
{
"plugin": ["file:///absolute/path/to/opencode-throughput/src/index.ts"]
}
Build
bun install
bun run build
Publish
npm publish --access public
License
MIT