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
Multi-signal model
23 hours ago
2026-10-04
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-context@0.1.1"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-context@0.1.1"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D @jeffreyjyz/opencode-contextOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
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.
Similar plugins
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.