OpenCode Memory 插件(opencode-mem) + Go 套餐:安装、配置、使用全指南

OpenCode Memory 插件 + Go 套餐:安装、配置、使用全指南

概述

OpenCode Memory (opencode-mem)是 OpenCode 的长期记忆插件。它自动捕捉对话中的关键信息,构建用户画像,并通过向量数据库实现跨会话记忆检索。结合 Go 套餐,无需自备 API Key,开箱即用。


一、前置条件


二、安装

2.1 安装 opencode-mem 插件

bash 复制代码
# 通过 opencode 插件市场安装
opencode plugin opencode-mem

2.2 验证安装

bash 复制代码
# 查看配置文件中的插件列表
cat ~/.config/opencode/opencode.json
# "plugin" 数组应包含 "opencode-mem"

2.3 确认 Go 套餐登录

bash 复制代码
opencode auth status
# 应显示已登录及 Go 套餐信息

三、配置

3.1 启用插件

编辑 ~/.config/opencode/opencode.json:

json 复制代码
{
  "$schema": "https://opencode.ai/config.json",
  "permission": "allow",
  "server": {
    "hostname": "127.0.0.1",
    "port": 4096
  },
  "plugin": [
    "opencode-mem"
  ]
}

三、配置

3.1 启用插件

编辑 ~/.config/opencode/opencode.json:

json 复制代码
{
  "$schema": "https://opencode.ai/config.json",
  "permission": "allow",
  "server": {
    "hostname": "127.0.0.1",
    "port": 4096
  },
  "plugin": [
    "opencode-mem"
  ]
}

3.2 配置 opencode-mem(Go 套餐原生方式,推荐)

编辑 ~/.config/opencode/opencode-mem.jsonc:

jsonc 复制代码
{
  // ---- 存储 ----
  "storagePath": "~/.opencode-mem/data",

  // ---- 嵌入模型(本地运行,无需联网) ----
  "embeddingModel": "Xenova/nomic-embed-text-v1",

  // ---- Go 套餐原生 Provider(推荐) ----
  // 无需硬编码 API Key,opencode 负责认证
  "opencodeProvider": "opencode-go",
  "opencodeModel": "opencode-go/deepseek-v4-flash",

  // ---- 自动记忆捕捉 ----
  "autoCaptureEnabled": true,
  "autoCaptureMaxRetries": 3,
  "autoCaptureIterationTimeout": 30000,

  // ---- Web 管理界面 ----
  "webServerEnabled": true,
  "webServerPort": 4747,
  "webServerHost": "127.0.0.1",

  // ---- 去重与清理 ----
  "deduplicationEnabled": true,
  "deduplicationSimilarityThreshold": 0.90,
  "autoCleanupEnabled": true,
  "autoCleanupRetentionDays": 30,

  // ---- 用户画像 ----
  "injectProfile": true,
  "userProfileAnalysisInterval": 10,

  // ---- 搜索 ----
  "similarityThreshold": 0.6,
  "maxMemories": 10
}

3.3 配置 opencode-mem(手动 API Key 方式,备选)

如果你偏好显式指定 API Key 而非使用 Go Provider:

jsonc 复制代码
{
  // 注释掉 Go Provider 相关行
  // "opencodeProvider": "opencode-go",
  // "opencodeModel": "opencode-go/deepseek-v4-flash",

  // 使用手动配置
  "memoryProvider": "openai-chat",
  "memoryModel": "deepseek-v4-flash",
  "memoryApiUrl": "https://opencode.ai/zen/go/v1",
  "memoryApiKey": "你的 Go 套餐 API Key"
}
text 复制代码
推荐使用方式 3.2(Go Provider),更安全简洁,Key 变更时无需修改配置文件。

四、重启生效

修改配置文件后,需重启 opencode:

bash 复制代码
# 重启 opencode 终端会话即可重新加载插件
# (opencode 配置变更后新会话自动生效)

重启后插件自动加载,日志路径:

bash 复制代码
tail -f ~/.opencode-mem/opencode-mem.log

五、使用

5.1 自动记忆捕捉(Auto-Capture)

配置项:

jsonc 复制代码
"autoCaptureEnabled": true

插件会在每次对话空闲约 10 秒后自动分析当前会话内容,提取关键信息存入向量数据库。无需手动干预。

示例

5.2 Web 管理界面

浏览器打开 http://localhost:4747,或命令行一键打开:

bash 复制代码
# Windows
Start-Process "http://127.0.0.1:4747"

# macOS
open http://127.0.0.1:4747

# Linux
xdg-open http://127.0.0.1:4747

Web 界面可:

text 复制代码
- 浏览所有记忆条目
- 按项目/时间筛选
- 搜索记忆
- 手动添加/编辑/删除记忆
- 查看用户画像

5.3 在对话中使用记忆

OpenCode 会自动将相关记忆注入 AI 上下文。你也可以通过 injectProfile 功能让 AI 了解你的偏好。

配置项:

jsonc 复制代码
"injectProfile": true

5.4 记忆搜索

记忆搜索通过 Web UI(http://localhost:4747)完成,支持关键词检索和项目筛选。


六、测试与验证

6.1 检查 API 连通性

bash 复制代码
# Go Provider 方式(无需 Key)
curl -s -X POST "https://opencode.ai/zen/go/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
text 复制代码
Go Provider 方式下,opencode 自动处理认证,curl 测试仅用于验证端点可达。

6.2 验证插件加载

bash 复制代码
# 查看配置文件中的插件列表
cat ~/.config/opencode/opencode.json
# "plugin" 数组应包含 "opencode-mem"

6.3 检查日志确认无报错

bash 复制代码
Get-Content ~/.opencode-mem/opencode-mem.log -Tail 30

正常日志示例:

log 复制代码
[INFO] Auto-capture session: xxx
[INFO] Memory stored successfully: xxx
[INFO] Web server started on http://127.0.0.1:4747

异常排查:

text 复制代码
错误                                   原因                    解决
401 Incorrect API key                 API Key 无效            切换到 Go Provider 方式或更新 Key
session.create returned no session id Go Provider 未连接       检查 opencode auth list
API request timeout                   网络波动                增大 autoCaptureIterationTimeout
opencode provider is not connected    opencode 未登录         执行 opencode auth login

6.4 验证 Web UI

powershell 复制代码
curl -s http://127.0.0.1:4747 | Select-String -Pattern "opencode"
# 应返回 HTML 页面内容

6.5 完整端到端测试

text 复制代码
1. 在 opencode 中执行一条对话(如"我的名字是张三")
2. 等待约 10-15 秒(auto-capture 触发)
3. 查看日志确认记忆已存储
4. 打开 http://127.0.0.1:4747 确认该条记忆出现在列表中

七、常见问题

Q: 如何查看 Go 套餐用量?

bash 复制代码
opencode stats
# 或浏览器访问 https://opencode.ai/auth

Q: 如何切换到不同的模型?

Go 套餐支持以下模型:

text 复制代码
- deepseek-v4-flash
- mimo-v2.5
- qwen3.7-plus

修改 opencodeModel 即可。

Q: 记忆数据存在哪里?

text 复制代码
本地路径: ~/.opencode-mem/data/
存储方式: SQLite 向量数据库
网络依赖: 无需外部服务
项目隔离: 每个项目自动分片存放

Q: 可以关闭自动捕捉吗?

jsonc 复制代码
// 设为 false 即可关闭
"autoCaptureEnabled": false

关闭后仅通过 Web UI 或 API 手动管理记忆。


八、总结

text 复制代码
opencode-mem + Go 套餐 = 🎯
  - 零外部依赖(嵌入模型本地运行)
  - 零 API Key 管理(Go Provider 自动认证)
  - 全自动记忆捕捉
  - 本地向量数据库,数据不出域
  - Web UI 可视化管理

Go 套餐下配置 opencode-mem 仅需两步:

bash 复制代码
# 1. 配置 Go Provider
"opencodeProvider": "opencode-go"

# 2. 重启 opencode 终端会话使配置生效
text 复制代码
就这么简单。
相关推荐
瑶山6 天前
开源编程Agent-OpenCode完整使用教程
开源·agent·ai编程·opencode
slacker-kian7 天前
[实践]-让 SAP 工程 Skill 脱离 opencode跑在自定义Agent 上
ai·llm·sap·agent·abap·adt·opencode
VIP_CQCRE8 天前
OpenCode IDE 插件接入 Ace Data Cloud:把主流编辑器里的 AI Coding 能力统一到一个模型入口
大模型·ai编程·开发工具·opencode·acedatacloud
liulilittle9 天前
Linux AI 开发环境搭建实录
linux·ai·llm·agent·hyper-v·dev·opencode
孟郎郎10 天前
Windows 环境使用 OpenCode 配置使用大模型
人工智能·windows·ai·大模型·开源软件·opencode
liulilittle10 天前
OpenCode 中解禁 Muse-Spark 1.3 - max 档
ai·spark·llm·agent·tools·opencode·muse
VIP_CQCRE11 天前
在 VS Code / Cursor / Windsurf 中接入 Ace Data Cloud:OpenCode IDE Extension 实战配置
ai编程·opencode·acedatacloud
VIP_CQCRE14 天前
在 VS Code、Cursor、Windsurf 里接入 Ace Data Cloud:OpenCode IDE Extension 配置指南
ai编程·vs code·cursor·opencode·ace data cloud
VIP_CQCRE14 天前
在 OpenCode IDE 里接入 Ace Data Cloud:把多模型 AI 能力带进开发工作流
大模型·ai编程·开发工具·opencode·ace data cloud
梦想的颜色15 天前
【AI速览】2026 最新 开箱即用型开源成品 Agent :DeepSeek Harness 、Pi-Agent、 Opencode 横向 全面 对比
开源·agent·opencode·dsh·piagent