Context
Context-window breakdown for opencode: a /context dialog plus a context_breakdown tool showing where the window went (system prompt, tool definitions, thinking, tool I/O, messages), delta.app style.
0
0
20.0
生态多维模型
23 小时前
2026-10-04
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-context@0.1.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-context@0.1.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @jeffreyjyz/opencode-contextOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Context-window breakdown for opencode. /context opens a dialog showing where
the window went — system prompt, tool definitions, thinking, tool inputs and
outputs (split per tool), user and assistant messages — with a stacked bar and a
measured used / limit header, in the style of delta.app's Context Window. A
context_breakdown tool returns the same numbers as markdown so a model can ask
for them itself.
Install
Add it to the plugins array in ~/.config/opencode/opencode.json and restart
(or /reload) opencode:
{
"plugins": ["@jeffreyjyz/opencode-context"]
}
For local development point at the checkout instead — an absolute path is treated as a local plugin:
{
"plugins": ["/Users/you/dev/cmdcode-tools/opencode-context"]
}
A symlink under ~/.config/opencode/plugins/ is also picked up. After bun run build in the checkout, the root index.js / tui.js shims load dist/.
Use
/context— opens the breakdown for the current session.context_breakdown— the model calls it and gets the breakdown as markdown.
How it works
Two halves of one package, because they run in different processes:
| half | file | job |
|---|---|---|
| server | src/index.ts |
measures the assembled system prompt and tool definitions on every request (their sizes only) and registers the tool |
| TUI | src/tui.tsx |
the /context slash command and the dialog |
The message store holds no system prompt or tool schemas, so the server half
records their byte sizes in $XDG_CACHE_HOME/opencode-context/<session>.json
(one small JSON per session; no prompt text) and the dialog reads them. The rest
of the breakdown comes straight from opencode's live data — the replayable
context (session.context, post-compaction), the model's context limit, and the
agent instructions as a fallback.
Units: each row shows UTF-8 bytes (delta's size column) and the header shows the provider's measured tokens over the model limit. Per-row percentages are share of the byte total.
Development
bun install
bun test
bun run typecheck
bun run build
Notes
- The System Prompt and Tool Definitions rows need one request to have happened in the session (that is when they are measured); before that the System Prompt row falls back to the agent instructions and Tool Definitions is hidden.
- Only sizes are cached, never prompt or tool text.
- The install cache for a published version can lag npm; see the ecosystem notes
in
AGENTS.mdbefore publishing.
同类生态推荐
Smartsnip
opencode-smartsnip
Cuts shell-output tokens in opencode. Wraps only what snip can filter — everything else runs byte-identical.
V2 Slim
@serkanalgur/opencodev2-slim
Smart context management plugin for OpenCode v2 - semantic compression, cost-aware pruning, adaptive thresholds
Context Pruner
opencode-context-pruner
Continuous verbatim context pruning for OpenCode, powered by TypeSafe Jev. Port of fast-jev-compaction adapted to OpenCode's context hook.