中文
文档
ACP 支持

ACP 支持

在任何兼容 ACP 的编辑器中使用 OpenCode。

OpenCode 支持 Agent Client Protocol (opens in a new tab)(ACP),允许你在兼容的编辑器和 IDE 中直接使用它。

有关支持 ACP 的编辑器和工具列表,请查看 ACP 进展报告 (opens in a new tab)

ACP 是一个开放协议,标准化了代码编辑器与 AI 编码 Agent 之间的通信。


配置

要通过 ACP 使用 OpenCode,请配置你的编辑器运行 opencode acp 命令。

该命令将 OpenCode 作为 ACP 兼容的子进程启动,通过 stdio 使用 JSON-RPC 与编辑器通信。

以下是支持 ACP 的流行编辑器的配置示例。


Zed

添加到你的 Zed (opens in a new tab) 配置(~/.config/zed/settings.json):

~/.config/zed/settings.json
{
  "agent_servers": {
    "OpenCode": {
      "command": "opencode",
      "args": ["acp"]
    }
  }
}

要打开它,在命令面板中使用 agent: new thread 操作。

你也可以通过编辑 keymap.json 绑定键盘快捷键:

keymap.json
[
  {
    "bindings": {
      "cmd-alt-o": [
        "agent::NewExternalAgentThread",
        {
          "agent": {
            "custom": {
              "name": "OpenCode",
              "command": {
                "command": "opencode",
                "args": ["acp"]
              }
            }
          }
        }
      ]
    }
  }
]

JetBrains IDE

根据文档 (opens in a new tab)添加到你的 JetBrains IDE (opens in a new tab) acp.json:

acp.json
{
  "agent_servers": {
    "OpenCode": {
      "command": "/absolute/path/bin/opencode",
      "args": ["acp"]
    }
  }
}

要打开它,在 AI Chat agent 选择器中使用新的 'OpenCode' agent。


Avante.nvim

添加到你的 Avante.nvim (opens in a new tab) 配置:

{
  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 (opens in a new tab) 中将 OpenCode 用作 ACP agent,请在 Neovim 配置中添加以下内容:

require("codecompanion").setup({
  interactions = {
    chat = {
      adapter = {
        name = "opencode",
        model = "claude-sonnet-4",
      },
    },
  },
})

此配置将 CodeCompanion 设置为使用 OpenCode 作为聊天的 ACP agent。

如果需要传递环境变量(如 OPENCODE_API_KEY),请参阅 CodeCompanion.nvim 文档中的配置适配器:环境变量 (opens in a new tab)获取完整详情。

支持

OpenCode 通过 ACP 使用与在终端中使用完全相同。所有功能都受支持:

⚠️

某些内置斜杠命令如 /undo/redo 目前不受支持。

  • 内置工具(文件操作、终端命令等)
  • 自定义工具和斜杠命令
  • 在 OpenCode 配置中配置的 MCP 服务器
  • 来自 AGENTS.md 的项目特定规则
  • 自定义格式化器和代码检查器
  • Agent 和权限系统