Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opencode-context-view

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.

Commands

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.

How it works

  • The server plugin (./server) intercepts session.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 beta instead of the template's ^1.18.21: session hooks (session.hook("context")) only exist in the v2 branch API (npm tag beta); the published 1.18.x line does not have them.

Install

bun install

Use locally

Option 1 — auto-discovery

Copy 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-view

Dependencies of local plugins are not installed by OpenCode — keep node_modules in place (run bun install inside the plugin folder).

Option 2 — config entry

Add it to opencode.jsonc:

{
  "$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" } }
  ],
}

Verify loading

opencode2 api get /api/plugin

If the plugin is missing, check the server log: ~/.local/share/opencode/log/opencode.log (filter role=server).

Develop

bun run test        # bun test
bun run typecheck   # tsc --noEmit

Layout and roadmap: see PLAN.md. The V2 plugin API is beta; when upgrading OpenCode, re-check the @opencode-ai/plugin types.

Publish to npm

  1. Update name, version, repository, and author in package.json.
  2. Make sure every runtime import is listed in dependencies (OpenCode installs production dependencies into an isolated cache).
  3. Publish:
npm publish

Users then add it with:

opencode2 plugin add opencode-context-view

Privacy

  • 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.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages