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

v0.3.1

Published

Real-time token usage, cache analytics & performance dashboard plugin for OpenCode CLI

Downloads

419

Readme

opencode-tokenwatch

English · 简体中文

Sidebar

OpenCode CLI 的实时 Token 用量统计、缓存分析与性能指标插件。

功能

  • 侧边栏面板 — 会话级与按模型的实时统计(请求数、Token、缓存、成本)
  • 缓存命中率 — 模型行内彩色进度条,带趋势指示器(↑/↓),全局总计行显示加权命中率
  • 性能指标 — TTFT / TPS / 端到端延迟 + P50/P95/P99 延迟分位数
  • Token 分布 — 5 桶角色分解(system / user / toolCall / toolResult / output + other 兜底)
  • 错误率统计 — 识别并统计失败请求(空 Token 响应),实时计算错误率
  • 成本展示 — 按模型显示 cost(需 provider 返回计费数据)
  • /usage 命令 — HTML 报告 → JSON 导出 → 文本报告 → 设置
  • HTML 报告 — 交互式 ECharts 仪表盘:Token 分布、性能分位数、TPS 水平排名、错误率分析,自动在浏览器打开
  • 持久化统计 — 性能指标(TPS/TTFT/延迟)写入独立 JSON 文件,永久累积,不受日志轮转影响
  • 多级折叠 — 面板、模型、子区块均可折叠,状态持久化
  • 语言切换 — 中英双语,跟随系统或手动切换

安装

npm install opencode-tokenwatch

opencode.jsonopencode.jsonc 中添加:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-tokenwatch"]
}

配置

{
  "plugin": ["opencode-tokenwatch"],
  "pluginConfig": {
    "opencode-tokenwatch": {
      "sidebar": {
        "showPerformance": true,
        "showPricing": true,
        "showTokenDistribution": true,
        "showTrend": true
      },
      "language": "auto"
    }
  }
}

| 配置项 | 类型 | 默认值 | 说明 | |--------|------|--------|------| | sidebar.showPerformance | boolean | true | 显示 TTFT/TPS/延迟 | | sidebar.showPricing | boolean | true | 显示请求成本 | | sidebar.showTokenDistribution | boolean | true | 显示 Token 分布 | | sidebar.showTrend | boolean | true | 显示趋势指示器 | | language | "auto" / "zh" / "en" | "auto" | 界面语言 |

运行时也可通过 /usage → 设置 调整,优先级高于 pluginConfig

用法

在 OpenCode TUI 中输入 /usage,选择:

  • HTML 报告 — 选择日期范围,生成仪表盘并在浏览器打开
  • JSON 导出 — 导出完整用量数据至 ~/.opencode/reports/
  • 文本报告 — 导出 Markdown 格式至 ~/.opencode/reports/
  • 设置 — 开关侧边栏显示项、切换语言

数据文件

| 文件 | 路径 | 说明 | |------|------|------| | JSONL 日志 | ~/.opencode/tokenwatch.jsonl | 原始请求日志,超 5MB 自动轮转 | | 聚合统计 | ~/.opencode/tokenwatch-stats.json | 持久化性能统计,永久累积 | | 报告输出 | ~/.opencode/reports/ | HTML / JSON / Markdown 报告 |

系统要求

  • OpenCode CLI(支持 opencode db 命令)
  • Node.js 18+

构建

npm install
npm run build

相关项目

许可

MIT