OpenCode 支持 Agent Client Protocol(ACP),允许你在兼容的 editor 和 IDE 中直接使用它。

ACP 是一个开放协议,用于标准化 code editor 与 AI coding agent 之间的通信。


配置(Configure)

要通过 ACP 使用 OpenCode,需要将你的 editor 配置为运行 opencode acp 命令。

该命令会以 ACP 兼容的 subprocess 方式启动 OpenCode,并通过 stdio 使用 JSON-RPC 与 editor 进行通信。

下面是一些支持 ACP 的主流 editor 示例。


Zed

在你的 Zed 配置文件(~/.config/zed/settings.json)中添加:

```json title=”~/.config/zed/settings.json” { “agent_servers”: { “OpenCode”: { “command”: “opencode”, “args”: [“acp”] } } }

  1. 打开方式:在 **Command Palette** 中使用 `agent: new thread` 动作。
  2. 你也可以通过编辑 `keymap.json` 绑定快捷键:
  3. ```json title="keymap.json"
  4. [
  5. {
  6. "bindings": {
  7. "cmd-alt-o": [
  8. "agent::NewExternalAgentThread",
  9. {
  10. "agent": {
  11. "custom": {
  12. "name": "OpenCode",
  13. "command": {
  14. "command": "opencode",
  15. "args": ["acp"]
  16. }
  17. }
  18. }
  19. }
  20. ]
  21. }
  22. }
  23. ]

JetBrains IDEs

按照 JetBrains IDE 官方文档,在 acp.json 中添加配置:

```json title=”acp.json” { “agent_servers”: { “OpenCode”: { “command”: “/absolute/path/bin/opencode”, “args”: [“acp”] } } }

  1. 打开方式:在 AI Chat agent selector 中选择新的 OpenCode agent
  2. ---
  3. ### Avante.nvim
  4. 在你的 [Avante.nvim](https://github.com/yetone/avante.nvim) 配置中添加:
  5. ```lua
  6. {
  7. acp_providers = {
  8. ["opencode"] = {
  9. command = "opencode",
  10. args = { "acp" }
  11. }
  12. }
  13. }

如果需要传递 environment variables(环境变量):

{ acp_providers = { [“opencode”] = { command = “opencode”, args = { “acp” }, env = { OPENCODE_API_KEY = os.getenv(“OPENCODE_API_KEY”) } } } }


CodeCompanion.nvim

如果你想在 CodeCompanion.nvim 中将 OpenCode 作为 ACP agent 使用,可以在你的 Neovim 配置中添加:

  1. require("codecompanion").setup({
  2. strategies = {
  3. chat = {
  4. adapter = {
  5. name = "opencode",
  6. model = "claude-sonnet-4",
  7. },
  8. },
  9. },
  10. })

该配置会将 CodeCompanion 设置为使用 OpenCode 作为 chat 场景下的 ACP agent。

如果你需要传递 environment variables(例如 OPENCODE_API_KEY),请参考 CodeCompanion.nvim 文档中的 Configuring Adapters: Environment Variables


支持情况(Support)

通过 ACP 使用 OpenCode 时,其行为与在 terminal 中使用完全一致,所有功能均受支持:

  • 内置 tools(文件操作、terminal 命令等)
  • 自定义 tools 和 slash command
  • 在 OpenCode config 中配置的 MCP server
  • 来自 AGENTS.md 的 project-specific rules(项目级规则)
  • 自定义 formatter 和 linter
  • Agent 与 permissions system(权限系统)