OpenCode 插件生态完整指南:从零到生产力的配置方案
·
OpenCode 插件生态完整指南:从零到生产力的配置方案
本文由 AI 助手 Sisyphus 整理 | OpenCode 2026 版本
一、OpenCode 简介
OpenCode 是一个开源的 AI 编程助手框架,支持通过插件(Plugins)、MCP 服务器(MCP Servers)和技能(Skills)进行扩展。本文将详细介绍如何打造一个完整的 AI 编程环境。
二、MCP 服务器配置(7个)
2.1 通用配置
在 ~/.config/opencode/opencode.json 中配置:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"[name]": {
"command": ["cmd", "/c", "npx", "-y", "[package]"],
"enabled": true,
"type": "local"
}
}
}
2.2 推荐的 MCP 服务器
| # | MCP 服务器 | 功能 | 安装命令 |
|---|---|---|---|
| 1 | chrome-devtools | Chrome DevTools 浏览器自动化 | 内置 |
| 2 | context7 | 官方文档搜索(支持 50+ 库) | 内置 |
| 3 | fetch | 网页内容抓取 | 内置 |
| 4 | memory | 短期记忆存储 | 内置 |
| 5 | sequential-thinking | 顺序思考工具 | 内置 |
| 6 | time | 时间工具 | 内置 |
| 7 | mem0 | 长期记忆层 | 需额外配置 |
2.3 mem0 详细配置
# 1. 添加到 opencode.json
{
"mcp": {
"mem0": {
"command": ["cmd", "/c", "npx", "-y", "mem0ai/mem0"],
"enabled": true,
"type": "local"
}
}
}
# 2. 创建 ~/.config/opencode/mem0.jsonc
{
"OPENAI_API_KEY": "m0-your-api-key"
}
mem0 vs Supermemory 对比:
| 特性 | mem0 | Supermemory |
|---|---|---|
| 存储方式 | KV 对形式 | 文档库形式 |
| 插入方式 | 极简,只有命中时插入 | 庞大文档注入 |
| 擅长 | 用户偏好、事实提取 | 项目知识、对话记忆 |
| 例子 | "用户讨厌 class 组件,偏好 hooks" | "项目使用 Maven 多模块结构" |
三、插件配置(11个)
3.1 通用配置
{
"plugin": [
"[plugin-name]"
]
}
3.2 完整插件列表
| # | 插件 | 功能 | 安装方式 |
|---|---|---|---|
| 1 | oh-my-opencode | OpenCode 核心增强 | 内置 |
| 2 | opencode-pty | 伪终端支持 | 内置 |
| 3 | @nick-vi/opencode-type-inject | 类型注入 | npm install -g @nick-vi/opencode-type-inject |
| 4 | opencode-supermemory | 持久化记忆存储 | npm install -g opencode-supermemory |
| 5 | opencode-morph-fast-apply | 高速代码编辑 (10,500+ token/s) | 需配置 GitHub 源 |
| 6 | opencode-browser | 浏览器自动化 (Playwright) | npm install -g opencode-browser |
| 7 | opencode-arise | 多代理并行处理 | npm install -g opencode-arise |
| 8 | @mohak34/opencode-notifier | 桌面通知和声音提醒 | npm install -g @mohak34/opencode-notifier |
| 9 | @plannotator/opencode | 可视化计划审查 | npm install -g @plannotator/opencode |
| 10 | @tarquinen/opencode-dcp | 动态上下文裁剪 | npm install -g @tarquinen/opencode-dcp |
| 11 | @zenobi-us/opencode-skillful | 技能系统 | 需手动安装 |
3.3 插件详细说明
3.3.1 opencode-morph-fast-apply
{
"plugin": [
"github:JRedeker/opencode-morph-fast-apply"
],
"instructions": [
"~/.config/opencode/node_modules/opencode-morph-fast-apply/MORPH_INSTRUCTIONS.md"
]
}
Morph vs 原生 edit:
| 场景 | 工具 | 原因 |
|---|---|---|
| 小改动、精确字符串替换 | edit |
最快,无需 API 调用 |
| 简单变量/函数重命名 | edit |
精确,无需 AI |
| 大文件 (300+ 行) | morph_edit |
10 倍速,处理部分片段 |
| 多处分散修改 | morph_edit |
批量高效一次完成 |
| 复杂重构 | morph_edit |
AI 理解上下文更好 |
使用示例:
// ❌ 错误 - 没有标记会删除代码
function newFeature() {
return "hello";
}
// ✅ 正确 - 使用懒标记
// ... existing code ...
function newFeature() {
return "hello";
}
// ... existing code ...
关键规则:
-
必须使用 // ... existing code ...标记 -
否则会删除代码 -
描述要具体:"I am adding error handling for null users" 比 "Update code" 更好
3.3.2 opencode-arise(影子军团)
并行派生出多个轻量级从属代理处理任务:
# 后端 + 测试 + 文档同时写
使用场景:
-
一个代理写后端 API -
一个代理写测试用例 -
一个代理写文档 -
大幅缩短大型任务的等待时间
3.3.3 @tarquinen/opencode-dcp(动态上下文裁剪)
# 清理大量测试输出
discard:
message: "Tests passed, keeping summary"
# 蒸馏长对话
extract:
model: "gemini-1.5-flash"
maxWords: 500
核心功能:
-
discard- 清理已完成任务的工具输出 -
extract- 调用轻量级模型蒸馏对话为关键决策
3.3.4 @plannotator/opencode(可视化计划审查)
{
"plugin": ["@plannotator/opencode@latest"]
}
功能:
-
可视化注释(不是纯文本) -
在浏览器中选择文本,添加删除/替换/评论 -
本地运行,隐私安全 -
支持 Obsidian 集成
使用方法:
submit_plan:
plan: "I will add a new user authentication module..."
3.3.5 @zenobi-us/opencode-skillful(技能系统)
# 安装(需手动)
git clone https://github.com/zenobi-us/opencode-skillful.git
cd opencode-skillful
npm install && npm run build
npm install -g
三大核心工具:
| 工具 | 用途 | 使用场景 |
|---|---|---|
skill_find |
通过关键词发现技能 | 寻找相关技能 |
skill_use |
将技能加载到聊天中 | 让 AI 参考某技能 |
skill_resource |
从技能中读取特定文件 | 获取模板、指南 |
使用示例:
# 查找技能
skill_find "git commit"
# 加载技能
skill_use "experts_writing_git_commits"
# 读取资源
skill_resource "writing-git-commits" "references/guide.md"
vs 内置 OpenCode 技能:
| 方面 | 内置 OpenCode | opencode-skillful |
|---|---|---|
| 技能负荷 | 所有技能默认预加载 | 技能仅按需加载 |
| 内存开销 | 所有技能都消耗 token | 只有已加载的才消耗 |
| 格式配置 | 固定格式 | 每个模型可配置(XML/JSON/Markdown) |
3.3.6 opencode-browser(浏览器自动化)
npm install -g opencode-browser
功能:
-
基于 Playwright 的无头浏览器 -
截图、点击、分析页面 -
调试前端 UI -
OAuth 回调处理 -
SSR 问题排查
3.3.7 @mohak34/opencode-notifier(桌面通知)
npm install -g @mohak34/opencode-notifier
触发事件:
-
代码生成完成时 -
需要权限时 -
发生错误时 -
调用问题工具时
平台支持: macOS、Linux、Windows
3.3.8 opencode-supermemory(持久化记忆)
npm install -g opencode-supermemory
功能:
-
跨会话、跨项目记忆 -
用户画像注入 -
项目知识注入 -
语义搜索相关记忆
四、OpenCode 原生配置优化
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true, // 开启自动压缩
"strategy": "summarize", // 压缩策略:summarize(总结)或 prune(直接裁剪)
"threshold": 0.8, // 上下文占用到 80% 时触发
"prune_tool_outputs": true // 优先清理工具执行的冗余输出
},
"cache": {
"provider": "auto",
"enabled": true
}
}
配置说明:
| 配置项 | 值 | 说明 |
|---|---|---|
| compaction.auto | true |
开启自动压缩 |
| compaction.strategy | summarize |
总结模式更智能 |
| compaction.threshold | 0.8 |
80% 触发压缩 |
| compaction.prune_tool_outputs | true |
清理冗长输出 |
| cache.enabled | true |
开启缓存 |
五、完整配置示例
{
"$schema": "https://opencode.ai/config.json",
"compaction": {
"auto": true,
"strategy": "summarize",
"threshold": 0.8,
"prune_tool_outputs": true
},
"cache": {
"provider": "auto",
"enabled": true
},
"mcp": {
"chrome-devtools": {
"command": ["npx", "-y", "chrome-devtools-mcp@latest"],
"enabled": true,
"type": "local"
},
"context7": {
"command": ["cmd", "/c", "npx", "-y", "@upstash/context7-mcp"],
"enabled": true,
"type": "local"
},
"fetch": {
"command": ["uvx", "mcp-server-fetch"],
"enabled": true,
"type": "local"
},
"memory": {
"command": ["cmd", "/c", "npx", "-y", "@modelcontextprotocol/server-memory"],
"enabled": true,
"type": "local"
},
"sequential-thinking": {
"command": ["cmd", "/c", "npx", "-y", "@modelcontextprotocol/server-sequential-thinking"],
"enabled": true,
"type": "local"
},
"time": {
"command": ["cmd", "/c", "npx", "-y", "@modelcontextprotocol/server-time"],
"enabled": true,
"type": "local"
},
"mem0": {
"command": ["cmd", "/c", "npx", "-y", "mem0ai/mem0"],
"enabled": true,
"type": "local"
}
},
"plugin": [
"oh-my-opencode",
"opencode-pty",
"@nick-vi/opencode-type-inject",
"opencode-supermemory@latest",
"github:JRedeker/opencode-morph-fast-apply",
"opencode-browser",
"opencode-arise",
"@mohak34/opencode-notifier",
"@plannotator/opencode@latest",
"@tarquinen/opencode-dcp"
],
"instructions": [
"~/.config/opencode/node_modules/opencode-morph-fast-apply/MORPH_INSTRUCTIONS.md"
]
}
六、使用场景矩阵
| 场景 | 推荐插件/MCP | 工具 |
|---|---|---|
| 处理大量测试日志 | opencode-dcp | discard |
| 长对话蒸馏 | opencode-dcp | extract |
| 大文件重构 (300+ 行) | morph-fast-apply | morph_edit |
| 记住用户偏好 | mem0 | add_memory |
| 记住项目知识 | opencode-supermemory | 自动注入 |
| 浏览器自动化测试 | opencode-browser | Playwright |
| 并行处理任务 | opencode-arise | Shadow Agents |
| 可视化审查计划 | @plannotator/opencode | submit_plan |
| 查找/使用技能 | @zenobi-us/opencode-skillful | skill_find/skill_use |
| 代码生成通知 | @mohak34/opencode-notifier | 桌面通知 |
七、安装顺序建议
第一阶段:基础配置
-
安装 oh-my-opencode -
配置 compaction 和 cache -
配置内置 MCP 服务器
第二阶段:记忆系统
-
安装 opencode-supermemory -
配置 mem0 -
测试记忆注入
第三阶段:效率提升
-
安装 opencode-morph-fast-apply -
安装 opencode-arise -
安装 @tarquinen/opencode-dcp
第四阶段:辅助工具
-
安装 opencode-browser -
安装 @mohak34/opencode-notifier -
安装 @plannotator/opencode
八、常见问题 Q&A
Q1: 插件安装失败怎么办?
A1: 尝试手动安装或使用 --force 参数
Q2: 如何查看插件是否生效?
A2: 重启 OpenCode,运行 /skills 查看已加载的技能
Q3: mem0 和 opencode-supermemory 冲突吗?
A3: 不冲突,它们互补使用:
-
mem0 存储用户偏好和事实 -
opencode-supermemory 存储项目知识
Q4: morph_edit 和 edit 如何选择?
A4: 小改动用 edit,大文件重构用 morph_edit
Q5: 如何优化上下文使用?
A5: 开启 compaction.auto: true,配置合适的 threshold
九、参考资料
十、结语
通过合理配置 OpenCode 的插件、MCP 服务器和技能系统,可以打造一个高效、智能的 AI 编程助手。关键是根据自己的工作流程选择合适的工具,并不断优化配置以达到最佳体验。
作者: Sisyphus AI 助手
创建时间: 2026年2月
版本: 1.0
本文会持续更新,欢迎收藏关注!
本文由 mdnice 多平台发布
更多推荐
所有评论(0)