3.Open Code

1.安装

进入官网进行安装。https://opencode.ai 目前opencode 提供 cli 和 desktop(支持使用cli命令) 两种方式。

2.常用命令

命令 说明
/init 初始化项目,分析项目结构并生成 AGENTS.md 文件
/models 切换模型
/new 新建会话
/session 查看会话(Ctrl + D 删除)
/undo 撤销更改
/share 分享会话
/commands 所有命令
/connect 添加 Provider 认证
/agents 切换 Agent
/compact 压缩上下文(token 不够时用)
/share 分享当前会话
/help 帮助
/exit 退出 OpenCode

init 命令用于初始化项目上下文:

  1. 扫描项目结构
  2. 分析技术栈
  3. 识别关键文件
  4. 生成 AGENTS.md 文件,提供项目上下文信息

其他命令

  • 更新 :opencode upgrade
  • 执行命令 :! ls
  • 退出终端 :Ctrl + Z
  • 切换最近使用过的模型 :F2
  • 切换 Plan/Build 模式 :tab
    • Plan 模式 :规划和设计阶段
    • Build 模式 :实现和执行阶段

3.provider

3.1.介绍

Provider 就是模型的"来源"。opencode 支持 75+ Provider,包括:

类型 代表 Provider 特点
官方订阅 Anthropic (Claude Pro/Max)、OpenAI (ChatGPT Plus/Pro) 用订阅账号登录,无需 API Key
OAuth 代理 Google Antigravity 用 Gemini 订阅调用多种模型
API Key DeepSeek、Groq、OpenRouter 传统 API Key 认证
本地模型 Ollama、LM Studio、llama.cpp 完全免费,离线可用
企业级 Amazon Bedrock、Azure OpenAI、Google Vertex AI 企业合规需求

3.2. 配置方式。

使用provider支持多种方式。

  1. 方式1: 【入门推荐】OpenCode Zen,官方提供的一种类似于auto模式的托管服务,可以自动使用经过官方测试过的模型。
  2. 方式2: 【进阶推荐】用现有订阅(推荐)。如果你已经有 Claude Pro/Max 或 ChatGPT Plus/Pro 订阅,可以直接用。
一、使用OpenCode Zen模式
# 1. 在 opencode 里运行
/connect

# 2. 选择 opencode

# 3. 访问 https://opencode.ai/auth 登录并创建 API Key

# 4. 粘贴 API Key

# 5. 运行 /models 查看可用模型
/models

二、Anthropic (Claude Pro/Max)
opencode auth login
# Provider 选 Anthropic
# Login method 选 Claude Pro/Max
# 浏览器登录完成 OAuth

三、Google Gemini (Antigravity OAuth) 推荐使用,因为gemni支持:
• 多账号负载均衡(最多 10 个,一个限流自动切下一个)
• 调用 Gemini 3 Pro/Flash
• 通过 Antigravity 还能调用 Claude 模型

需要安装opencode-antigravity-auth插件。

四、OpenAI (ChatGPT Plus/Pro)。需要安装opencode-openai-codex-auth插件。

五、本地模型
Ollama(本地模型,完全免费)。在 opencode.json 里配置:
{
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "llama2": {
          "name": "Llama 2"
        }
      }
    }
  }
}

3.3.最佳实践

角色 Provider 模型 用途
主力 Google Antigravity Claude Opus 4.5 Thinking High 复杂编排、深度思考
快枪手 Google Antigravity Gemini 3 Flash 快速搜索、简单任务
大脑 OpenAI GPT 5.2 架构决策、代码审查
前端 Google Antigravity Gemini 3 Pro UI/UX 设计

4.配置

opencode 有两套配置:

配置文件 位置 作用
opencode.json ~/.config/opencode/opencode.json(全局) ./opencode.json(项目级) opencode 核心配置
oh-my-opencode.json ~/.config/opencode/oh-my-opencode.json(全局) ./.opencode/oh-my-opencode.json(项目级) oh-my-opencode 插件配置

配置优先级(从低到高):配置是合并的,不是替换。后面的配置只覆盖冲突的字段。

  1. 远程组织配置(.well-known/opencode)← 最低
  2. 全局配置(~/.config/opencode/opencode.json)
  3. 自定义配置(OPENCODE_CONFIG 环境变量)
  4. 项目配置(./opencode.json)
  5. .opencode 目录
  6. 运行时内联配置(OPENCODE_CONFIG_CONTENT)← 最高

配置说明

{
  "$schema": "https://opencode.ai/config.json",

  // ========== 插件配置 ==========
  "plugin": [
    "oh-my-opencode",         
    "opencode-openai-codex-auth@4.3.0",
    "opencode-antigravity-auth@1.2.8"
  ],

  // ========== Provider 配置 ==========
  "enabled_providers": ["google", "openai"],  // 只启用这些
  "disabled_providers": ["ollama"],           // 禁用这些(优先级更高)

  // ========== 模型配置 ==========
  "default_agent": "plan",
  "model": "google/antigravity-claude-opus-4-5-thinking-high", // 主模型
  "small_model": "google/antigravity-claude-sonnet-4-5", // 轻量任务(标题生成等)

  // ========== TUI 界面配置 ==========
  "tui": {
    "scroll_speed": 3,
    "scroll_acceleration": {
      "enabled": true
    },
    "diff_style": "auto"   // 或 "stacked"
  },

  // ========== 文件监控配置 ==========
  "watcher": {
    "ignore": [
      "node_modules/**",
      "dist/**",
      ".git/**",
      ".next/**",
      "build/**",
      "target/**",
      "*.log",
      ".cache/**"
    ]
  },

  // ========== 权限配置 ==========
  "permission": {
    "read": {
      "*": "allow",
      "*.env": "deny",
      "*.env.*": "deny",
      "*.env.example": "allow",
      "**/.env": "deny",
      "**/credentials*": "deny",
      "**/*secret*": "deny"
    },
    "edit": "ask",    // 修改文件前询问
    "bash": {
      "*": "ask",
      "git status": "allow",
      "git diff": "allow",
      "git log": "allow",
      "git branch": "allow",
      "npm test": "allow",
      "npm run lint": "allow",
      "npm run build": "allow",
      "pnpm test": "allow",
      "pnpm lint": "allow",
      "yarn test": "allow",
      "yarn lint": "allow"
    }
  },

  // ========== 上下文压缩配置 ==========
  "compaction": {
    "auto": true,   // 上下文满了自动压缩
    "prune": true   // 删除旧的工具输出节省 token
  },

  // ========== 自动更新 ==========
  "autoupdate": true,

  // ========== 分享配置 ==========
  "share": "manual",

  // ========== Provider 详细配置 ==========
  "provider": {
    "openai": {
      "name": "OpenAI",
      "options": {
        "timeout": 600000,        // 请求超时(毫秒)
        "setCacheKey": true       // 启用缓存
        "reasoningEffort": "medium",
        "reasoningSummary": "auto",
        "textVerbosity": "medium",
        "include": ["reasoning.encrypted_content"],
        "store": false
      },
      "models": {
        "gpt-5.2": {
          "name": "GPT 5.2 (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "variants": {
            "none": {
              "reasoningEffort": "none",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.2-codex": {
          "name": "GPT 5.2 Codex (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "auto",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        },
        "gpt-5.1-codex-max": {
          "name": "GPT 5.1 Codex Max (OAuth)",
          "limit": {
            "context": 272000,
            "output": 128000
          },
          "modalities": {
            "input": ["text", "image"],
            "output": ["text"]
          },
          "variants": {
            "low": {
              "reasoningEffort": "low",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "medium": {
              "reasoningEffort": "medium",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "high": {
              "reasoningEffort": "high",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            },
            "xhigh": {
              "reasoningEffort": "xhigh",
              "reasoningSummary": "detailed",
              "textVerbosity": "medium"
            }
          }
        }
      }
    },
    "google": {
      "name": "Google",
      "models": {
        "antigravity-gemini-3-pro-high": {
          "name": "Gemini 3 Pro High (Antigravity)",
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-gemini-3-pro-low": {
          "name": "Gemini 3 Pro Low (Antigravity)",
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65535
          },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-gemini-3-flash": {
          "name": "Gemini 3 Flash (Antigravity)",
          "attachment": true,
          "limit": {
            "context": 1048576,
            "output": 65536
          },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-sonnet-4-5": {
          "name": "Claude Sonnet 4.5 (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-sonnet-4-5-thinking-low": {
          "name": "Claude Sonnet 4.5 Low (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-sonnet-4-5-thinking-medium": {
          "name": "Claude Sonnet 4.5 Medium (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-sonnet-4-5-thinking-high": {
          "name": "Claude Sonnet 4.5 High (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-opus-4-5-thinking-low": {
          "name": "Claude Opus 4.5 Low (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-opus-4-5-thinking-medium": {
          "name": "Claude Opus 4.5 Medium (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        },
        "antigravity-claude-opus-4-5-thinking-high": {
          "name": "Claude Opus 4.5 High (Antigravity)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": {
            "input": ["text", "image", "pdf"],
            "output": ["text"]
          }
        }
      }
    }
  },

7 自定义 Agent
  "agent": {
    "code-reviewer": {
      "description": "代码审查专家",
      "model": "anthropic/claude-sonnet-4-5",
      "prompt": "你是代码审查专家,关注安全、性能和可维护性。",
      "tools": {
        "write": false,  // 禁止修改文件
        "edit": false
      }
    }
  },
  "default_agent": "plan"  // 默认使用的 Agent

8 变量替换。配置文件支持变量:
  // 环境变量
  "model": "{env:OPENCODE_MODEL}",
    // 文件内容
    "provider": {
      "openai": {
        "options": {
          "apiKey": "{file:~/.secrets/openai-key}"
        }
      }
    }
}

5.MCP

OpenCode自带了3个MCP。

MCP 作用 底层工具 使用场景
Context7 查询最新官方文档 context7_query-docs "React 19 的新特性?"
grep.app 在百万 GitHub 仓库中秒搜代码 grep_app_searchGitHub "找个 JWT 认证的例子"
Exa 联网搜索 websearch / websearch_web_search_exa "最近有什么新的 AI 框架?"

如何单独使用:

// 搜索网络
websearch "React useEffect cleanup best practices"

// 查询官方文档
context7_query-docs "/facebook/react" "how to use useState"

// GitHub 代码搜索
grep_app_searchGitHub "useState(" language="TypeScript"

6.Claude Code 兼容层

如果你之前用 Claude Code,现有配置可以直接迁移:

Claude Code 路径 作用
~/.claude/commands/ 自定义斜杠命令
~/.claude/skills/ 技能目录
~/.claude/agents/ 自定义 Agent
~/.claude/.mcp.json MCP 服务器配置
~/.claude/settings.json Hooks(PreToolUse、PostToolUse 等)

默认是开启的:

{
  "claude_code": {
    "mcp": false,
    "commands": false,
    "hooks": false
  }
}

7.权限

生产环境最怕两件事:

  1. 读取敏感信息(.env、私钥、token)
  2. 执行破坏性命令(rm、批量替换、错误脚本)

7.1.推荐权限配置

权限的枚举

  • allow:直接放行,不询问
  • ask: 每次都询问用户确认
  • deny: 直接拒绝

修改配置文件:opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "read": {
      "*": "allow",
      "*.env": "deny",
      "*.env.*": "deny",
      "*.env.example": "allow"
    },
    "edit": "ask",
    "bash": {
      "*": "ask",
      "git status": "allow",
      "git diff": "allow",
      "git log": "allow",
      "npm test": "allow",
      "npm run lint": "allow"
    }
  },
  "agent": {
    "build": {
      "permission": {
        "bash": {
          "*": "ask",
          "git *": "allow",
          "git commit *": "ask",
          "git push *": "deny",
          "grep *": "allow"
        }
      }
    }
  }
}

7.2.Agent级别权限

oh-my-opencode提供的 Agent 权限控制:

{
  "agents": {
    "explore": {
      "permission": {
        "edit": "deny",     // 不允许修改文件
        "bash": "ask",      // 执行命令前询问
        "webfetch": "allow" // 允许上网
      }
    }
  }
}

7.3.

7.4.

8.最佳实践

8.1.大仓库卡顿、CPU 飙高

  • 症状:opencode 启动慢,CPU 占用高
  • 原因:watcher 扫描了 node_modules 等大目录
  • 解决:扩展 ignore 配置
{
  "watcher": {
    "ignore": [
      "node_modules/**",
      "dist/**",
      ".git/**",
      ".next/**",
      "build/**",
      "target/**",
      "*.log"
    ]
  }
}

8.2.权限控制

bash 自动执行让人不放心

  • 症状:Agent 自动执行了危险命令
  • 原因:bash 权限设成了 allow
  • 解决:限制 bash 权限,每次执行都必须询问。
{
  "permission": {
    "bash": {
      "*": "ask",
      "git status": "allow"
    }
  }
}

8.3.Token 爆了

症状:对话到一半报错 token 超限

解决:

  1. 开启自动压缩:"compaction": { "auto": true, "prune": true }
  2. 开启预防性压缩(oh-my-opencode 默认开启)
  3. 手动运行 /compact

8.4.工作流模版

在使用opencode的过程中,可以配置工作流模版,提高效率。

模版1:基础模版(强制分派agent任务):方案→证据→边界→实现→复核
1. @oracle:出架构方案 + 风险清单 + 回滚策略
2. @librarian:找证据(现有实现、提交记录、规范文档)
3. @explore:画模块地图(入口、边界、调用链路)
4. Sisyphus:拆 Todo 并逐项推进(每步可验证)
5. @oracle:最终 review(边界条件、失败路径、回归风险)


模版2:一键工作流:ultrawork:最简单的方式——在提示词里加上 ultrawork(或简写 ulw):

帮我实现用户认证功能 ultrawork

Agent 会自动:
1. 分析项目结构
2. 并行搜索相关代码和文档
3. 制定实现计划
4. 创建 Todo 列表
5. 逐项实现并验证
6. 完成后自我 review

场景工作流示例

场景一:新功能开发
我要实现一个新的支付功能 ultrawork
需要:
1. 集成 Stripe API
2. 支持微信/支付宝
3. 有订单管理后台


场景二:Bug 修复
analyze 用户登录偶尔失败的问题
已知信息:
- 错误日志:xxx
- 复现步骤:xxx

场景三:代码重构
帮我重构 auth 模块 ultrawork
要求:
1. 拆分成更小的模块
2. 增加单元测试
3. 保持 API 兼容

场景四:代码审查
让 @oracle review 这个 PR:
重点关注:
1. 安全性
2. 性能影响
3. 边界条件

9.插件

插件允许你通过挂钩各种事件和自定义行为来扩展 OpenCode。你可以创建插件来添加新功能、集成外部服务,或修改 OpenCode 的默认行为。

10.项目

基于opencode开发的项目

  • OpenWork:Claude Cowork 的开源替代方案,由 OpenCode 驱动
  • kimaki:用于控制 OpenCode 会话的 Discord 机器人,基于 SDK 构建
  • opencode.nvim:Neovim 插件,提供编辑器感知的提示词,基于 API 构建
  • portal:通过 Tailscale/VPN 使用的移动优先 OpenCode Web UI
  • opencode plugin template:用于构建 OpenCode 插件的模板
  • opencode.nvim:OpenCode 的 Neovim 前端——基于终端的 AI 编码代理
  • ai-sdk-provider-opencode-sdk:Vercel AI SDK 提供商,用于通过 @opencode-ai/sdk 使用 OpenCode
  • OpenChamber:OpenCode 的 Web / 桌面应用和 VS Code 扩展
  • OpenCode-Obsidian:将 OpenCode 嵌入 Obsidian UI 的 Obsidian 插件
  • ocx:OpenCode 扩展管理器,支持可移植的隔离配置
  • CodeNomad:OpenCode 的桌面、Web、移动和远程客户端应用

重点:

  1. OpenWork官网:https://openworklabs.com/

Oh My OpenCode

开发项目的时候,一定要在项目根目录执行:/init-deep 命令。不同与init,/init-deep 会深度分析项目结构,生成更详细的配置。 并且在项目的核心目录中创建多个 AGENTS.md 文件,用于定义不同目录下的 Agent 配置。 便于Agent在执行命令的过程中,自动将项目上下文注入到Agent中。

1.介绍

opencode目前最强形态是配合它的外挂插件oh-my-opencode。 这一步的目标:让 opencode 具备"可用、好用、可扩展"的基础体验。 一句话总结:oh-my-opencode 是经过 $24,000 token 验证的生产级配置,装上就能用。

oh-my-opencode 提供:

  1. 预置 Agent 团队:Sisyphus(主编排)、Oracle(架构师)、Librarian(文档专家)等,各司其职
  2. 订阅直接用:Claude Pro/Max、ChatGPT Plus/Pro、Gemini 订阅无需 API Key
  3. LSP 重构工具:不只分析,还能重命名、跳转、代码操作
  4. 后台并行 Agent:多个 Agent 同时干活,不用干等
  5. Claude Code 兼容:现有的 .claude/ 配置直接迁移
  6. 精选 MCP:Context7(官方文档)、grep.app(GitHub 代码搜索)内置

2.对比

Oh My OpenCode与OpenCode + Oh My OpenCode 对比:

对比维度 传统 AI 编程工具 OpenCode + Oh My OpenCode
模型使用 单模型处理所有任务 多专业子智能体分工协作
上下文处理 上下文增大时性能下降 子智能体分工减少上下文压力
任务完成 容易中断、留下 TODO 持续执行直到完成
IDE 工具 无法利用 LSP 等功能 充分利用 IDE 级工具
并行能力 顺序执行 后台并行执行

3.ultrawork

ultrawork(简写为 ulw)是 Oh My OpenCode 的核心关键字,通过别名唤醒Oh My OpenCode,启动完整功能集:

功能 说明
并行执行 多个子智能体同时处理任务
后台任务激活 在后台执行耗时任务
Todo Continuation Enforcer 确保任务列表持续执行
专业子智能体自动委托 根据任务类型自动调用合适的子智能体
持续执行 持续工作直至任务完成,不中断

使用方法 :在任务提示词中添加 ultrawork 或 ulw

"帮我分析这个项目的架构,ultrawork"
"重构这个模块,ulw"

4.专业子智能体

4.1.预置子智能体

OMO自带了多个专业子智能体,覆盖了从架构师、研究员、探索者到前端工程师和文档撰写的各个方面。

Agent 默认模型 角色定位 最佳使用场景 调用方式
Sisyphus(主协调器) Claude Opus 4.5 主编排器 整体任务规划、协调多Agent和结果整合 默认激活
oracle (架构师) GPT 5.2 架构师 + 调试专家 架构设计、代码审查、疑难杂症 @oracle
librarian(研究员) Gemini 3 Flash / Claude Sonnet 文档专家 查官方文档、找开源实现、代码考古、代码研究和实现示例 @librarian
explore (探索者) Grok Code / Gemini 3 Flash 快速扫描器 代码库结构、模式匹配、快速定位 @explore
Frontend UI/UX Engineer (前端工程师) Gemini 3 Pro 前端设计师 UI/UX 设计、样式调整、组件开发 自动调用
document-writer (文档撰写者) Gemini 3 Pro 技术作家 README、API 文档、架构文档 自动调用
Multimodal Looker (多模态分析师) Gemini 3 Flash 视觉专家 图片/PDF/图表分析 自动调用

修改智能体的默认模型:~/.config/opencode/oh-my-opencode.json:

{
  "agents": {
    "Sisyphus": { "model": "opencode/grok-code" },
    "oracle": { "model": "opencode/grok-code" },
    "librarian": { "model": "opencode/grok-code" },
    "explore": { "model": "opencode/minimax-m2.1-free" },
    "frontend": { "model": "opencode/glm-4.7-free" },
    "document_writer": { "model": "opencode/glm-4.7-free" },
    "multimodal": { "model": "opencode/grok-code" }
  }
}

4.2.使用子智能体

方式1. 直接调用:使用 `@` 符号直接调用指定子智能体:
# 调用架构师
"@oracle 审核这个设计并提出架构方案,列出风险点"

# 调用研究员
"@librarian 说明这是如何实现的——为什么行为总在变化?"

# 调用探索者
"@explore 找出所有用户认证相关的代码"

方式2. 自动调用:某些子智能体会根据任务类型自动调用:
    Frontend UI/UX Engineer :检测到前端开发相关任务时自动调用
    Document Writer :检测到文档撰写相关任务时自动调用
    Multimodal Looker :检测到 PDF、图像或图表分析任务时自动调用
    
方式3. 自动模型切换机制:用户无需手动指定模型,系统会根据所调用的子智能体,自动使用其对应配置的模型。工作流程示例:
    1. 用户输入任务,例如 "帮我分析架构,ultrawork"
    2. Sisyphus(主协调器)解析任务并制定执行计划
    3. Sisyphus 调用 @oracle(架构师)
    4. 系统自动切换至 @oracle 配置的模型(如 grok-code)
    5. @oracle 执行任务并返回结果
    6. Sisyphus 汇总各子智能体的输出,生成最终结果    
    
    
你:帮我重构 auth 模块 ultrawork

Sisyphus 会自动:
1. 派 @explore 并行扫描 auth 相关代码
2. 派 @librarian 查最新的认证最佳实践
3. 派 @oracle 出架构方案 + 风险评估
4. 自己创建 Todo 列表并逐项推进
5. 完成后派 @oracle 做最终 review    

4.3.子智能体工作流程

整个过程为全自动化,用户只需输入任务描述,即可获得高质量的开发成果。

用户输入任务
    ↓
Sisyphus(主协调器)解析任务并制定执行计划
    ↓
Sisyphus 将任务分派给相应的专业子智能体
    ↓
子智能体在后台并行执行各自任务
    ↓
Sisyphus 汇总各子智能体的输出
    ↓
生成最终结果

4.4.自定义Agent

在 oh-my-opencode.json 里覆盖(只能覆盖,不能新增):

{
  "agents": {
    "oracle": {
      "model": "openai/gpt-5.2",
      "temperature": 0.3,
      "prompt_append": "回答时用中文。"
    },
    "explore": {
      "permission": {
        "edit": "deny",
        "bash": "ask"
      }
    }
  }
}

5.工作原理

oh-my-openagent 是一个多模型 Agent 编排引擎,作为 OpenCode 的插件运行。它将单个 AI agent 扩展为一个专业分工、协同作战的虚拟开发团队。 核心哲学是:用对的人(模型)做对的事。

5.1.架构总览:三层编排

用户请求
    ↓
    [IntentGate] — 意图分类(研究/实现/调查/修复)
    ↓
    [Sisyphus] — 主编排器,规划+委派
    ↓
    ├─→ [Prometheus] — 战略规划(面试模式,只读)
    ├─→ [Metis/Momus] — 方案质量保障
    ├─→ [Atlas] — 计划执行(指挥者)
    │    ↓
    │    ├─→ Sisyphus-Junior(category 委派 → 写代码)
    │    ├─→ Oracle(架构咨询,只读)
    │    ├─→ Librarian(文档/OSS 搜索)
    │    └─→ Explore(快速代码搜索)
层次 组件 职责
规划层 Prometheus + Metis + Momus 面试式需求澄清,生成 .sisyphus/plans/*.md 计划文件
执行层 Atlas 读取计划,分解任务,委派给工作 agent,积累经验
工作层 Sisyphus-Junior, Oracle, Explore, Librarian 实际写代码、搜索、咨询

5.2.核心组件详解

IntentGate(意图门):

  • 每个请求进来时,Sisyphus 首先分类意图:是研究(research)、实现(implementation)、调查(investigation)、还是修复(fix)?不同意图路由到不同行为模式,避免字面理解偏差。
  • 本质就是一段提交给Sisyphus的prompt。
  • 排歧:有没有多种理解?有没有缺关键信息?用户设计有没有坑?
  • 决定路径:直接回答 → 探索 → 规划 → 实施?

Sisyphus — 主编排器:它的核心行为:

  • 不直接写代码,而是规划、分解、委派
  • 优先使用并行 background agents
  • 内置 Todo 强制系统(完不成不罢休)
  • 自称 "you write prompts, not code"

Prometheus — 战略规划师

  • 只读模式,只能写 .sisyphus/ 下的 markdown 文件
  • 像个真正的工程师一样面试你,追问 scope、边界、技术方案
  • 生成结构化的计划文件,待 Momus 审查

Atlas — 计划执行指挥

  • 读取 Prometheus 的计划,分解成原子任务
  • 按 category 委派给 Sisyphus-Junior
  • 每完成一个子任务,提取 learnings 传递给后续任务(Wisdom Accumulation)
  • 用 boulder.json 跟踪进度,支持跨 session 恢复

Hephaestus — 自治深度工作者

  • 默认跑在 GPT-5.5 上
  • 给目标不给步骤,自己探索、研究、执行
  • 适合深度架构推理和复杂调试

Category 系统(核心创新):按意图选模型,而不是按模型名选任务:

  • task(category="visual-engineering", …) // → 前端/UI 工作(Gemini)
  • task(category="ultrabrain", …) // → 硬逻辑/架构(GPT-5.5 xhigh)
  • task(category="deep", …) // → 自治研究+执行(GPT-5.5)
  • task(category="quick", …) // → 快速任务(GPT-5.4 Mini)

5.3.作为插件的工作机制

oh-my-openagent 是一个 OpenCode 插件,基于 @opencode-ai/plugin SDK构建:

// opencode.json
{
  "plugin": ["oh-my-openagent@latest"]
}

插件通过 Hooks 接口注入功能:

  • config hook — 修改配置
  • tool hook — 注册自定义工具(task, explore, 等所有工具)
  • chat.params hook — 修改 LLM 参数
  • command.execute.before hook — 拦截 /start-work 等命令
  • experimental.session.compacting hook — 自定义会话压缩

8.Ralph Loop(持续工作模式)

Ralph Loop 是 Oh My OpenCode 的持续工作模式。灵感来自 Anthropic 的 Ralph Wiggum 插件——自参照开发循环: 启用后,系统会自动循环执行任务,直到完成为止,特别适用于需要多轮迭代完成的任务,如实现复杂功能、重构大型模块或持续调试项目。

也就是:干到完才停

使用方法 :

# 启动 Ralph Loop
/ralph-loop "实现用户认证功能"

Agent 会一直干,直到:
• 检测到 <promise>DONE</promise> 标记
• 达到最大迭代次数(默认 100)
• 用户输出取消命令: /cancel-ralph

特点:

  • 支持所有编程语言
  • 中途停了会自动续上
  • 不需要人工干预

配置示例 :

{
  "ralph_loop": {
    "enabled": true,
    "default_max_iterations": 100
  }
}

9.后台并发控制

传统 AI 编程工具是串行的——一个任务做完才能做下一个。oh-my-opencode 支持后台并行执行任务:

根据不同 LLM 提供商和模型的限制,动态调整任务的并行执行策略。

配置示例 :

{
  "background_task": {
    "defaultConcurrency": 5,
    "providerConcurrency": {
      "anthropic": 3,
      "google": 5,
      "opencode": 5,
      "iflowcn": 8
    },
    "modelConcurrency": {
      "opencode/glm-4.7-free": 8,
      "google/gemini-3-flash": 5,
      "iflowcn/glm-4.6": 10
    }
  }
}

工作原理:

  1. 主 Agent 启动后台任务,拿到 task_id
  2. 继续处理其他事情
  3. 后台任务完成时收到通知
  4. 需要结果时用 background_output(task_id) 获取

10.LSP支持

oh-my-opencode 把 IDE 的能力给了 Agent:

工具 作用 示例
lsp_hover 查看类型和文档 光标放到函数上看签名
lsp_goto_definition 跳转到定义 从调用跳到函数定义
lsp_find_references 查找所有引用 看这个函数被哪里调用了
lsp_rename 全项目重命名 安全重命名变量/函数
lsp_code_actions 快速修复和重构 自动导入、提取函数
ast_grep_search AST 感知代码搜索 用语法模式搜索(支持 25 种语言)

11.Todo 驱动开发

oh-my-opencode 强制 Agent 完成 Todo。本质不是某个命令或功能,而是prompt+agent驱动的。 开发人员不需关注这块,因为在使用的过程中会自动使用Todo模式。

12.上下文注入器

Directory AGENTS.md 注入:读文件时自动把路径上的所有 AGENTS.md 注入上下文。

project/
├── AGENTS.md              # 项目级规则
├── src/
│   ├── AGENTS.md          # src 规则
│   └── components/
│       ├── AGENTS.md      # 组件规则
│       └── Button.tsx     # 读它时,上面 3 个 AGENTS.md 全生效

条件规则注入:从 .claude/rules/ 按条件加载规则

---
globs: ["*.ts", "src/**/*.js"]
description: "TypeScript/JavaScript coding rules"
---
- Use PascalCase for interface names
- Use camelCase for function names

13.其他功能

其他实用功能 功能 说明
注释检查器 注释质量控制 禁止 AI 写废话注释,保持代码干净
思考模式 深度思考触发 检测到 "think deeply" 自动启用深度思考
上下文窗口监控 上下文使用监控 用了 70% 时提醒 Agent,防止焦虑
预防性压缩 上下文压缩策略 85% 时自动压缩,不等爆了再处理
会话恢复 异常恢复机制 工具出错、消息为空自动恢复
会话通知 任务完成提醒 Agent 完成任务发系统通知

14.配置详情

{
  "$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",

  // ========== 认证配置 ==========
  // 使用外部 opencode-antigravity-auth 插件时设为 false
  "google_auth": false,

  // ========== Agent 模型覆盖 ==========
  "agents": {
    "Sisyphus": {
      "model": "google/antigravity-claude-opus-4-5-thinking-high"
    },
    "oracle": {
      "model": "openai/gpt-5.2",
      "temperature": 0.3
    },
    "librarian": {
      "model": "google/antigravity-gemini-3-flash"
    },
    "explore": {
      "model": "google/antigravity-gemini-3-flash"
    },
    "frontend-ui-ux-engineer": {
      "model": "google/antigravity-gemini-3-pro-high"
    },
    "document-writer": {
      "model": "google/antigravity-gemini-3-pro-high"
    },
    "multimodal-looker": {
      "model": "google/antigravity-gemini-3-flash"
    }
  },

  // ========== Sisyphus Agent 配置 ==========
  "sisyphus_agent": {
    "disabled": false,
    "default_builder_enabled": false,
    "planner_enabled": true,
    "replace_plan": true
  },

  // ========== Ralph Loop 配置 ==========
  "ralph_loop": {
    "enabled": true,
    "default_max_iterations": 100
  },

  // ========== 后台任务并发配置 ==========
  "background_task": {
    "defaultConcurrency": 5,
    "providerConcurrency": {
      "anthropic": 3,
      "openai": 5,
      "google": 10
    },
    "modelConcurrency": {
      "anthropic/claude-opus-4-5": 2,
      "google/antigravity-gemini-3-flash": 10
    }
  },

  // ========== 禁用的 Hook ==========
  // 可选值: todo-continuation-enforcer, context-window-monitor, 
  // session-recovery, session-notification, comment-checker,
  // grep-output-truncator, tool-output-truncator, directory-agents-injector,
  // directory-readme-injector, empty-task-response-detector, think-mode,
  // anthropic-context-window-limit-recovery, rules-injector,
  // background-notification, auto-update-checker, startup-toast,
  // keyword-detector, agent-usage-reminder, non-interactive-env,
  // interactive-bash-session, empty-message-sanitizer,
  // compaction-context-injector, thinking-block-validator,
  // claude-code-hooks, ralph-loop, preemptive-compaction
  "disabled_hooks": [],

  // ========== 禁用的 Agent ==========
  // 可选值: oracle, librarian, explore, frontend-ui-ux-engineer,
  // document-writer, multimodal-looker
  "disabled_agents": [],

  // ========== 禁用的 MCP ==========
  // 可选值: context7, grep_app
  "disabled_mcps": [],

  // ========== Claude Code 兼容性 ==========
  "claude_code": {
    "mcp": true,
    "commands": true,
    "skills": true,
    "agents": true,
    "hooks": true,
    "plugins": true
  },

  // ========== 实验性功能 ==========
  "experimental": {
    "preemptive_compaction_threshold": 0.85,
    "truncate_all_tool_outputs": false,
    "aggressive_truncation": false,
    "auto_resume": false,
    "dcp_for_compaction": false
  }
}

文章信息

张雪随笔
master
Homepage
Issues
Download

This Software is under the terms of The Unlicense.