# OpenCode

> 全部文档的索引见 [llms.txt](https://ark.volcengine.com/llms.txt)；在任一文档页面地址后追加 `.md` 可获取该页的 Markdown 版本。

本文介绍如何配置方舟 Agent Plan 到 OpenCode 中使用。

<span id="f7095ac5"></span>
# 一、前提条件

* 您已按需订阅 Agent Plan 套餐。如未，请访问 [开通管理-Agent Plan](https://ark.volcengine.com/region:cn-beijing/subscription/agent-plan?agentMode=close) 页面订阅套餐。

* 您已正确安装 OpenCode，如未，请参见以下操作完成软件安装。

  前提条件：安装 [Node.js 18 或更新版本](https://nodejs.org/en/download/)。
  在命令行界面，执行以下命令安装 OpenCode。

    ```Bash
    npm install -g opencode-ai
    ```

  安装结束后，执行以下命令查看安装结果，若显示版本号则安装成功。

    ```Bash
    opencode --version
    ```

<span id="c807cb71"></span>
# 二、配置 OpenCode

<span id="f0cc194f"></span>
## 方式 1：自动化助手（推荐）

ArkCLI Helper 是一个编码工具助手，支持快速配置选择的工具接入 Agent Plan。安装并运行该助手，根据界面提示操作可自动完成工具配置，降低手动配置的时间成本和出错风险。

> **注意**
>
> * ArkCLI Helper 是基于 Ark Helper 升级演进的工具配置服务，相关能力将持续在 ArkCLI Helper 上迭代更新。建议优先使用 ArkCLI Helper 完成工具配置。
> * ArkCLI Helper 支持 macOS、Linux、Windows 系统。

1. 安装 Ark CLI。

    ```Bash
    # 1. 通过 NPM 安装
    npm install -g @volcengine/ark-cli@latest
    
    # 2. 验证安装
    arkcli --version
    ```

2. 登录 Ark CLI。

    ```Bash
    arkcli auth login
    ```

    ![image-20260624-144256-509.png](https://arkdocs.tos-cn-beijing.volces.com/images/CodingPlan/image-20260624-144256-509.png)

    根据界面提示选择登录方式。若之前已登录过 arkcli，会沿用上次选择的配置；如需重新选择，请先执行 `arkcli config reset` 后再运行 `arkcli auth login`。首次登录时，按提示完成以下配置：

    1. **选择项目（Project）**：可按需选择，或默认选择**账号全部资源**。
    2. **选择消费模式（Type）**：选择 `agent-plan`。

        ![image-20260624-145424-871.png](https://arkdocs.tos-cn-beijing.volces.com/images/CodingPlan/image-20260624-145424-871.png)

3. 运行 ArkCLI Helper，根据界面提示完成 OpenCode 的配置。

    1. 在命令行界面输入 `arkcli helper` 命令，启动 ArkCLI Helper。
    2. **选择要配置的 Plan profile**：`agent-plan_cn-beijing_personal (Agent Plan)`。
        ![image-20260624-162749-221.png](https://arkdocs.tos-cn-beijing.volces.com/images/CodingPlan/image-20260624-162749-221.png)
    3. **选择默认 model**：按需选择。
    4. **选择要配置的 AI Agent**：`OpenCode`。
        当前支持的 Harness 包括：豆包搜索、专业数据集、Agent 记忆（OpenViking）、AI Native 应用开发底座，根据界面提示按需选择`配置`或者`跳过`。

        ![image-20260624-163041-690.png](https://arkdocs.tos-cn-beijing.volces.com/images/CodingPlan/image-20260624-163041-690.png)

完成上述操作后，将自动完成 OpenCode 的基础配置，并按选择结果自动安装对应的 Harness 工具，无需手动安装。
<span id="7cfb68d3"></span>
## 方式 2：手动配置

1. 创建并打开 OpenCode 的配置文件。文件路径因系统而异，具体操作如下：

    **选项：macOS/Linux**

    macOS/Linux 系统 OpenCode 配置文件路径：`~/.config/opencode/opencode.json`。
    1. 如果在主目录下没有`.config/opencode`目录，执行以下命令创建目录。

        ```Bash
        mkdir -p ~/.config/opencode
        ```

    2. 创建并打开配置文件。

        ```Bash
        nano ~/.config/opencode/opencode.json
        ```

    **选项：Windows**

    Windows 系统 OpenCode 配置文件路径：`%USERPROFILE%\.config\opencode\opencode.json`。以 CMD 命令行方式为例，操作如下。
    1. 如果当前用户目录下没有`.config\opencode`目录，执行以下命令创建目录。

        ```Bash
        if not exist "%USERPROFILE%\.config\opencode" mkdir "%USERPROFILE%\.config\opencode"
        ```

    2. 创建并打开配置文件。

        ```Bash
        notepad "%USERPROFILE%\.config\opencode\opencode.json"
        ```

2. 编辑 `opencode.json`，需关注的配置信息如下：

    * `<ARK_API_KEY>`：替换为您自己的 [专属 API Key](https://ark.volcengine.com/region:cn-beijing/openManagement?LLM=%7B%7D&OpenModelVisible=false&advancedActiveKey=agentPlan)。

        ![image-20260908-203322-616.png](https://arkdocs.tos-cn-beijing.volces.com/images/CodingPlan/image-20260908-203322-616.png)

    * `model`：见[支持模型及 Harness](/docs/agent-plan-personal-plan-overview#3d801f5f)，需配置文本生成模型。

    Agent Plan 兼容 OpenAI 接口协议，支持 Responses API、Chat API。推荐使用 Responses API 的配置，推理效果更好。

    支持的两类 API 仅在 npm 配置上不同：

    * Responses API 配置：`"npm": "@ai-sdk/openai"`
    * Chat API 配置：`"npm": "@ai-sdk/openai-compatible"`

    以配置`ark-code-latest`为例，具体信息如下。

> **注意**
>
> * `glm-5.3`、`deepseek-v4-flash`、`deepseek-v4-pro`、`kimi-k3`、`kimi-k2.8-preview` 支持 1M 上下文窗口用于包含大型代码库的长会话，可以通过 `limit.context` 字段显式指定窗口大小。
> * `provider.volcengine-agent-plan.models` 节点下有**两处**（对象键、`name`字段）需**替换为同一 Model Name**，切勿遗漏。
> * 若需开启模型图片理解能力，需在模型配置节点下新增如下配置项：`"modalities": {"input": ["text", "image"], "output": ["text"]}`

**选项：Responses API**

> **说明**
>
> npm 必须使用 `@ai-sdk/openai`，模型才会使用 Responses API，在 `baseURL` 的基础上自动拼接 `/responses`。

```JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "volcengine-agent-plan/ark-code-latest",
  "provider": {
    "volcengine-agent-plan": {
      "npm": "@ai-sdk/openai",
      "name": "Volcano Engine（Responses API）",
      "options": {
        "baseURL": "https://ark.cn-beijing.volces.com/api/plan/v3",
        "apiKey": "<ARK_API_KEY>"
      },
      "models": {
        "ark-code-latest": {
          "name": "ark-code-latest",
          "limit": {
            "context": 256000,
            "output": 32000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-pro": {
          "name": "doubao-seed-2.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-evolving": {
          "name": "doubao-seed-evolving",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3": {
          "name": "glm-5.3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3-flash": {
          "name": "glm-5.3-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-latest": {
          "name": "glm-latest",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4.1-flash": {
          "name": "deepseek-v4.1-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-flash": {
          "name": "deepseek-v4-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-pro": {
          "name": "deepseek-v4-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-lite": {
          "name": "doubao-seed-2.1-lite",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.0-mini": {
          "name": "doubao-seed-2.0-mini",
          "limit": {
            "context": 256000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "minimax-m3": {
          "name": "minimax-m3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k3": {
          "name": "kimi-k3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k2.8-preview": {
          "name": "kimi-k2.8-preview",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    }
  }
}
```

**选项：Chat API**

> **说明**
>
> npm 必须使用 `@ai-sdk/openai-compatible`，模型才会使用 Chat API，在 `baseURL` 的基础上自动拼接 `/chat/completions`。

```JSON
{
  "$schema": "https://opencode.ai/config.json",
  "model": "volcengine-agent-plan/ark-code-latest",
  "provider": {
    "volcengine-agent-plan": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Volcano Engine（Chat API）",
      "options": {
        "baseURL": "https://ark.cn-beijing.volces.com/api/plan/v3",
        "apiKey": "<ARK_API_KEY>"
      },
      "models": {
        "ark-code-latest": {
          "name": "ark-code-latest",
          "limit": {
            "context": 256000,
            "output": 32000
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-pro": {
          "name": "doubao-seed-2.1-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-evolving": {
          "name": "doubao-seed-evolving",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3": {
          "name": "glm-5.3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3-flash": {
          "name": "glm-5.3-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-latest": {
          "name": "glm-latest",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4.1-flash": {
          "name": "deepseek-v4.1-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-flash": {
          "name": "deepseek-v4-flash",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "deepseek-v4-pro": {
          "name": "deepseek-v4-pro",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.1-lite": {
          "name": "doubao-seed-2.1-lite",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "doubao-seed-2.0-mini": {
          "name": "doubao-seed-2.0-mini",
          "limit": {
            "context": 256000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "minimax-m3": {
          "name": "minimax-m3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k3": {
          "name": "kimi-k3",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "kimi-k2.8-preview": {
          "name": "kimi-k2.8-preview",
          "limit": {
            "context": 1024000,
            "output": 65536
          },
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    }
  }
}
```

<span id="30a7ef0d"></span>
# 三、启动并使用 OpenCode

1. 启动OpenCode：

    ```Bash
    opencode
    ```

2. 输入`/models`，选择配置的模型并在 OpenCode 中使用。

<span id="807452ad"></span>
# 其他操作

<span id="853d7fc7"></span>
## 添加图片生成/视频生成能力

方舟 Agent Plan Medium 及以上套餐提供图片生成模型配额，Large 及以上套餐提供视频生成模型配额。方舟提供 Skill 帮助 AI 工具快速接入并使用。具体配置方法请参见：[配置视觉模型](/docs/agent-plan-personal-visual-models)。

> **注意**
>
> * 不同的套餐支持的视觉模型有所不同，具体参见[支持模型及 Harness](/docs/agent-plan-personal-plan-overview#3d801f5f)。
> * 视觉模型不支持通过 Auto 及控制台切换使用。

<span id="449b88b3"></span>
## 切换模型

你可以随时根据需求切换**文本生成模型**。方舟支持多种方式切换模型。

|配置方式 |通过控制台 |通过命令参数 |修改配置文件 |
|---|---|---|---|
|切换模型操作 |1. 参考[二、配置 OpenCode](/docs/agent-plan-personal-opencode#c807cb71)配置模型名称为`ark-code-latest`。 |启动 OpenCode后，执行`/models`切换模型。 |参考[二、配置 OpenCode](/docs/agent-plan-personal-opencode#c807cb71)配置模型名称为您需要的模型。 | \
| |2. 在 [开通管理页面](https://ark.volcengine.com/region:cn-beijing/openManagement?LLM=%7B%7D&advancedActiveKey=agentPlan) 选择要使用的模型，切换后3-5分钟即可生效。 | | |
