contextpilot-opencodeContextPilot plugin for OpenCode — per-turn context optimization via lossless deduplication of repeated tool outputs.
0
25
近 7 天 9
25.5
生态多维模型
2 个月前
2026-06-16
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["contextpilot-opencode@0.2.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["contextpilot-opencode@0.2.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D contextpilot-opencodeopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
ContextPilot OpenCode Plugin is a native OpenCode plugin that reduces repeated LLM-bound context before each model call. It is adapted from the ContextPilot project for OpenCode's plugin system.
What it does
- Hooks OpenCode's
experimental.chat.messages.transformlifecycle before provider requests. - Replaces repeated completed tool outputs with short references to the earlier result.
- Deduplicates shared blocks inside large tool outputs with content-defined chunking.
- Tracks estimated session and all-time savings in OpenCode's data directory.
- Adds a
contextpilot_statustool for cumulative savings and dedup stats. - Optionally exposes a TUI sidebar widget showing session and all-time token savings.
The plugin is lossless: it keeps the first occurrence of content intact and only replaces repeated content with references. It does not call another LLM and does not require a proxy.
Install
Add the main plugin to your OpenCode config for context optimization and the contextpilot_status tool:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
"contextpilot-opencode@latest"
]
}
If you already use other OpenCode plugins, keep them and append ContextPilot in the same plugin array:
{
"plugin": [
"oh-my-openagent@latest",
"contextpilot-opencode@latest"
]
}
To show savings in the terminal sidebar, add the TUI package tag to your OpenCode TUI config (tui.json):
{
"$schema": "https://opencode.ai/tui.json",
"plugin": [
"contextpilot-opencode@tui"
]
}
Restart OpenCode after changing either plugin list so it loads the new plugins.
Let an agent install it
Use this prompt with an OpenCode-capable agent:
Install the ContextPilot OpenCode plugin in the same style as oh-my-openagent.
Preserve my existing OpenCode plugins, append `contextpilot-opencode@latest` to my OpenCode `opencode.json` plugin list, append `contextpilot-opencode@tui` to my OpenCode `tui.json` plugin list, verify both configs still parse, verify both plugin specs resolve, and tell me to restart OpenCode if it is already running.
Use contextpilot-opencode@latest for the main server plugin and contextpilot-opencode@tui for the TUI sidebar plugin.
Check savings
Inside an OpenCode session, ask the agent to call the contextpilot_status tool. Example output:
ContextPilot Status:
Turns optimized: 8
Chars saved: 12,840
Tokens saved: ~3,210
Docs deduped: 2
Tracked hashes: 5
Reorder: dedup-only
Runtime logs are written next to OpenCode logs at:
~/.local/share/opencode/log/contextpilot.log
Savings snapshots are written to:
~/.local/share/opencode/contextpilot/savings.json
Local development
bun install
bun test ./src
bun run typecheck
bun run build
npm pack --dry-run
For local OpenCode testing, add the absolute path of this repository to your OpenCode plugin array.
Relationship to ContextPilot
This repository contains only the OpenCode plugin package. The broader ContextPilot project includes the original context optimization engine, Hermes integration, runtime hooks, docs, and examples:
- ContextPilot: https://github.com/EfficientContext/ContextPilot
License
Apache-2.0.