ACP 支持
OpenCode 支持 Agent Client Protocol(简称 ACP),允许你在兼容的编辑器和 IDE 中直接使用它。
ACP 是一个开放协议,用于在代码编辑器与 AI 编程 agent 之间建立标准化的通信方式。
配置
要通过 ACP 使用 OpenCode,请将编辑器配置为运行 opencode acp 命令。
该命令会以 ACP 兼容子进程的方式启动 OpenCode,通过 stdio 上的 JSON-RPC 与编辑器通信。
下面是一些支持 ACP 的常用编辑器示例。
Zed
将其添加到你的 Zed 配置(~/.config/zed/settings.json):
{
"agent_servers": {
"OpenCode": {
"command": "opencode",
"args": ["acp"]
}
}
}
要打开它,在 Command Palette 中使用 agent: new thread 操作。
你也可以通过编辑 keymap.json 来绑定键盘快捷键:
[
{
"bindings": {
"cmd-alt-o": [
"agent::NewExternalAgentThread",
{
"agent": {
"custom": {
"name": "OpenCode",
"command": {
"command": "opencode",
"args": ["acp"]
}
}
}
}
]
}
}
]
JetBrains IDEs
按照 官方文档 将其添加到你的 JetBrains IDE acp.json 中:
{
"agent_servers": {
"OpenCode": {
"command": "/absolute/path/bin/opencode",
"args": ["acp"]
}
}
}
要打开它,在 AI Chat 的 agent 选择器中选择新的 ‘OpenCode’ agent。
Avante.nvim
将其添加到你的 Avante.nvim 配置中:
{
acp_providers = {
["opencode"] = {
command = "opencode",
args = { "acp" }
}
}
}
如果需要传递环境变量:
{
acp_providers = {
["opencode"] = {
command = "opencode",
args = { "acp" },
env = {
OPENCODE_API_KEY = os.getenv("OPENCODE_API_KEY")
}
}
}
}
CodeCompanion.nvim
要在 CodeCompanion.nvim 中将 OpenCode 用作 ACP agent,请将以下内容添加到你的 Neovim 配置中:
require("codecompanion").setup({
interactions = {
chat = {
adapter = {
name = "opencode",
model = "claude-sonnet-4",
},
},
},
})
该配置将 CodeCompanion 设置为在 chat 中使用 OpenCode 作为 ACP agent。
如果需要传递环境变量(例如 OPENCODE_API_KEY),请参阅 CodeCompanion.nvim 文档中的 Configuring Adapters: Environment Variables 以获取完整细节。
支持情况
OpenCode 通过 ACP 使用时与在终端中的体验一致。所有功能均受支持:
- 内置工具(文件操作、终端命令等)
- 自定义工具和斜杠命令
- 在 OpenCode 配置中配置的 MCP servers
- 来自
AGENTS.md的项目级规则 - 自定义 formatters 和 linters
- Agents 与 permissions 系统