OpenCode 配置分享:默认 Agent、插件与 Provider

由 canxin 创作阅读需要 5 分钟


目录

  1. 1. 当前配置
  2. 2. 配置加载优先级
  3. 3. 顶层字段速览
  4. 4. default_agent = cx-local 的来源
  5. 5. 插件体系(重点)
    1. 5.1 插件清单(npm 名称)
    2. 5.2 opencode-planpilot
    3. 5.3 opencode-workbench
    4. 5.4 opencode-web-preview
    5. 5.5 opencode-cx-agents
    6. 5.6 使用建议
  6. 6. Provider 与模型路由

1. 当前配置

{
  "$schema": "https://opencode.ai/config.json",
  "autoupdate": false,
  "compaction": {
    "auto": true,
    "prune": true
  },
  "default_agent": "cx-local",
  "model": "openai/gpt-5.3-codex",
  "small_model": "openai/gpt-5.1-codex-mini",
  "plugin": [
    "opencode-planpilot",
    "opencode-workbench",
    "opencode-web-preview",
    "opencode-cx-agents"
  ],
  "provider": {
    "anthropic": {
      "options": {
        "apiKey": "{env:CLAUDE_API_KEY}",
        "baseURL": "https://gateway.example.com/v1"
      }
    },
    "google": {
      "options": {
        "apiKey": "{env:GEMINI_API_KEY}",
        "baseURL": "https://gateway.example.com/v1beta"
      }
    },
    "openai": {
      "options": {
        "apiKey": "{env:OPENAI_API_KEY}",
        "baseURL": "https://gateway.example.com/v1",
        "setCacheKey": true
      }
    }
  }
}

2. 配置加载优先级

OpenCode 配置优先级(低 -> 高):

  1. Remote .well-known/opencode
  2. 全局 ~/.config/opencode/opencode.json
  3. OPENCODE_CONFIG
  4. 项目 opencode.json
  5. .opencode 目录(agents/commands/plugins 等)
  6. OPENCODE_CONFIG_CONTENT

全局层适合放长期默认值:default_agentmodelsmall_model、通用 provider 与通用插件。

3. 顶层字段速览

字段当前值作用说明
$schemahttps://opencode.ai/config.jsonJSON 校验与补全保留即可
autoupdatefalse关闭自动升级适合稳定优先
compaction.autotrue自动压缩长会话建议开启
compaction.prunetrue裁剪历史工具输出降低上下文膨胀
default_agentcx-local默认 agent由插件提供(0.2.0 起建议)
modelopenai/gpt-5.3-codex主模型主链路调用
small_modelopenai/gpt-5.1-codex-mini轻量模型辅助链路/降成本
plugin[]4 个 npm 插件功能扩展跨机器更易复用
provider.*.optionsbaseURL + apiKey提供商连接参数apiKey 使用环境变量

4. default_agent = cx-local 的来源

cx-localopencode-cx-agents 插件注册,不在该配置中手写 agent 定义。

该插件当前提供的 canonical agents 为:cx-explorecx-localcx-global

影响:

  1. 全局配置更精简,agent 生命周期由插件统一维护。
  2. 插件加载失败时,对应默认 agent 不会注册。

5. 插件体系(重点)

5.1 插件清单(npm 名称)

"plugin": [
  "opencode-planpilot",
  "opencode-workbench",
  "opencode-web-preview",
  "opencode-cx-agents"
]

对应 GitHub 仓库:

5.2 opencode-planpilot

定位:结构化推进复杂任务。
核心能力

适用场景:长任务拆解、跨阶段改造、需要状态持续追踪的流程。

5.3 opencode-workbench

定位:多分支 / 多 worktree 并行编排。
核心能力

适用场景:同仓库并行处理多个任务、多人协作分支并发。

5.4 opencode-web-preview

定位:前端预览会话与本地预览链路管理。
核心能力

适用场景:需要快速验证 UI 或本地前端改动时。

5.5 opencode-cx-agents

定位:提供可复用的预设 agent 组合与权限基线。
核心能力

适用场景

5.6 使用建议

  1. 默认推荐 default_agent = cx-local,把高权限写入留给明确场景。
  2. 需要跨目录自动写入时,再切换到 cx-global
  3. 启动后确认 agent 列表中可见 cx-explore / cx-local / cx-global

6. Provider 与模型路由

当前 provider 设计为“单网关域名 + 多路由入口”:

ProviderbaseURL说明
anthropichttps://gateway.example.com/v1Anthropic 兼容入口
googlehttps://gateway.example.com/v1betaGemini 兼容入口
openaihttps://gateway.example.com/v1OpenAI 兼容入口

评论