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-context-sidebar

v1.0.0

Published

Provider-agnostic context usage sidebar for OpenCode TUI

Readme

opencode-context-sidebar

English | 简体中文

适用于 OpenCode TUI、不依赖特定提供商的上下文用量侧边栏。

功能

  • 显示最近一次助手调用的 token 总量
  • 分别显示输入、缓存命中、缓存未命中和缓存写入用量
  • 分别显示输出、思考和响应内容用量
  • 显示缓存命中率和彩色分布条
  • 使用绿色、黄色和红色阈值显示上下文窗口用量
  • 显示会话累计费用,与 OpenCode 内置 Context 面板的行为一致
  • 分隔线宽度随侧边栏可用宽度动态调整

只要提供商通过 OpenCode 标准字段报告 token 用量,此插件即可正常工作。

安装

通过 OpenCode 安装此包,然后在 ~/.config/opencode/tui.json 或 .opencode/tui.json 中禁用内置 Context 面板:

{
  "$schema": "https://opencode.ai/tui.json",
  "plugin": ["opencode-context-sidebar"],
  "plugin_enabled": {
    "internal:sidebar-context": false
  }
}

修改配置后重启 OpenCode。

工作原理

插件使用 OpenCode 已经标准化的数据,不会直接调用各模型提供商的 API。

模型提供商响应
  -> OpenCode 标准化 Token 用量
  -> 插件读取最近一条助手消息
  -> 侧边栏计算并显示用量明细

| 界面项目 | OpenCode 字段 | 含义 | | --- | --- | --- | | Cache miss | tokens.input | 未读取缓存、也未写入缓存的普通输入 | | Cache hit | tokens.cache.read | 从缓存复用的输入 | | Cache write | tokens.cache.write | 写入缓存、供后续请求使用的输入 | | Response | tokens.output | 不含思考过程的模型输出 | | Thinking | tokens.reasoning | 模型报告的思考 Token |

界面中的统计值按以下方式计算:

Input         = Cache miss + Cache hit + Cache write
Output        = Response + Thinking
Total         = Input + Output
Context usage = Total / 模型上下文上限 * 100%

上下文上限来自当前模型的元数据。费用直接使用 OpenCode 累计的 session.cost,不同提供商的 Token 价格仍由 OpenCode 处理。由于数据来自当前会话状态,每次产生新的助手消息后,侧边栏都会随之更新。

开发

npm install
npm run build

本地加载配置:

{
  "$schema": "https://opencode.ai/tui.json",
  "plugin": ["file:///root/opencode-context-sidebar"],
  "plugin_enabled": {
    "internal:sidebar-context": false
  }
}

许可证

MIT