An OpenCode V2 plugin that visualizes how the model's context window is filled and reveals the "invisible" parts of the context: the system prompt, tool definitions and injections.
| Command | Action |
|---|---|
/context |
Open the context usage view |
/context usage |
Same as above |
/context injections |
Tree of hidden injections: prompt, tools |
Navigation: ↑↓ move, Enter preview content, Esc close.
The command is also available in the command palette.
- The server plugin (
./server) interceptssession.hook("context")on every model dispatch, classifies the context into categories (system prompt, tools, user/agent/thinking messages, tool calls/output, compacted data) and atomically stores a snapshot in~/.cache/opencode/context-view/<sessionID>.json(0600 permissions). - The TUI plugin (
./tui) reads the current session's snapshot, resolves the model's context window from the OpenCode model list and renders the view. Outside a session it falls back to the most recent snapshot. - Token estimates use a ~4 chars/token heuristic; values are estimates and may differ from provider-reported numbers.
The plugin declares tui: true: adding it to opencode.json(c) is enough —
the TUI loads the same package's ./tui export automatically (see
syncServerPlugins in the TUI sources).
Why
betainstead of the template's^1.18.21: session hooks (session.hook("context")) only exist in the v2 branch API (npm tagbeta); the published 1.18.x line does not have them.
bun installCopy or symlink into .opencode/plugins/ of any project (or
~/.config/opencode/plugins/ for all projects):
mkdir -p .opencode/plugins
ln -s /absolute/path/to/opencode-context-view .opencode/plugins/opencode-context-viewDependencies of local plugins are not installed by OpenCode — keep
node_modules in place (run bun install inside the plugin folder).
Add it to opencode.jsonc:
opencode2 api get /api/pluginIf the plugin is missing, check the server log:
~/.local/share/opencode/log/opencode.log (filter role=server).
bun run test # bun test
bun run typecheck # tsc --noEmitLayout and roadmap: see PLAN.md. The V2 plugin API is beta; when
upgrading OpenCode, re-check the @opencode-ai/plugin types.
- Update
name,version,repository, andauthorinpackage.json. - Make sure every runtime import is listed in
dependencies(OpenCode installs production dependencies into an isolated cache). - Publish:
npm publishUsers then add it with:
opencode2 plugin add opencode-context-view- Raw content stays in the user's local cache only and is revealed only after
an explicit
Enter. - Nothing is logged and nothing ever flows back into the model.
- Snapshots older than 7 days are pruned automatically.
MIT
{ "$schema": "https://opencode.ai/config.json", "plugins": [ "/absolute/path/to/opencode-context-view", // with options: // { "package": "/absolute/path/to/opencode-context-view", "options": { "base": "/tmp/snapshots" } } ], }