team
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTeam Skill
Team Skill
Spawn N coordinated agents working on a shared task list using Claude Code's native team tools. Replaces the legacy skill (SQLite-based) with built-in team management, inter-agent messaging, and task dependencies -- no external dependencies required.
/swarm利用Claude Code的原生团队工具,生成N个协同工作的Agent,处理共享任务列表。替代了旧版基于SQLite的技能,内置团队管理、Agent间通信和任务依赖管理——无需外部依赖。
/swarmUsage
使用方法
/oh-my-claudecode:team N:agent-type "task description"
/oh-my-claudecode:team "task description"
/oh-my-claudecode:team ralph "task description"/oh-my-claudecode:team N:agent-type "task description"
/oh-my-claudecode:team "task description"
/oh-my-claudecode:team ralph "task description"Parameters
参数说明
- N - Number of teammate agents (1-20). Optional; defaults to auto-sizing based on task decomposition.
- agent-type - OMC agent to spawn for the stage (e.g., executor, build-fixer, designer). Optional; defaults to stage-aware routing (see Stage Agent Routing below).
team-exec - task - High-level task to decompose and distribute among teammates
- ralph - Optional modifier. When present, wraps the team pipeline in Ralph's persistence loop (retry on failure, architect verification before completion). See Team + Ralph Composition below.
- N - 协作Agent的数量(1-20)。可选参数;默认根据任务分解自动调整数量。
- agent-type - 为阶段生成的OMC Agent类型(例如executor、build-fixer、designer)。可选参数;默认采用阶段感知路由(见下文的阶段Agent路由)。
team-exec - task - 需要分解并分配给协作Agent的高级任务描述
- ralph - 可选修饰符。添加后会将团队工作流包裹在Ralph的持久化循环中(失败时重试,完成前需架构师验证)。见下文的Team + Ralph组合部分。
Examples
示例
bash
/team 5:executor "fix all TypeScript errors across the project"
/team 3:build-fixer "fix build errors in src/"
/team 4:designer "implement responsive layouts for all page components"
/team "refactor the auth module with security review"
/team ralph "build a complete REST API for user management"bash
/team 5:executor "修复项目中所有TypeScript错误"
/team 3:build-fixer "修复src/目录下的构建错误"
/team 4:designer "为所有页面组件实现响应式布局"
/team "重构认证模块并进行安全审查"
/team ralph "构建完整的用户管理REST API"Architecture
架构
User: "/team 3:executor fix all TypeScript errors"
|
v
[TEAM ORCHESTRATOR (Lead)]
|
+-- TeamCreate("fix-ts-errors")
| -> lead becomes team-lead@fix-ts-errors
|
+-- Analyze & decompose task into subtasks
| -> explore/architect produces subtask list
|
+-- TaskCreate x N (one per subtask)
| -> tasks #1, #2, #3 with dependencies
|
+-- TaskUpdate x N (pre-assign owners)
| -> task #1 owner=worker-1, etc.
|
+-- Task(team_name="fix-ts-errors", name="worker-1") x 3
| -> spawns teammates into the team
|
+-- Monitor loop
| <- SendMessage from teammates (auto-delivered)
| -> TaskList polling for progress
| -> SendMessage to unblock/coordinate
|
+-- Completion
-> SendMessage(shutdown_request) to each teammate
<- SendMessage(shutdown_response, approve: true)
-> TeamDelete("fix-ts-errors")
-> rm .omc/state/team-state.jsonStorage layout (managed by Claude Code):
~/.claude/
teams/fix-ts-errors/
config.json # Team metadata + members array
tasks/fix-ts-errors/
.lock # File lock for concurrent access
1.json # Subtask #1
2.json # Subtask #2 (may be internal)
3.json # Subtask #3
...用户: "/team 3:executor fix all TypeScript errors"
|
v
[团队编排器(负责人)]
|
+-- TeamCreate("fix-ts-errors")
| -> 负责人成为team-lead@fix-ts-errors
|
+-- 分析并将任务分解为子任务
| -> explore/architect生成子任务列表
|
+-- TaskCreate x N(每个子任务对应一个)
| -> 生成带有依赖关系的任务#1、#2、#3
|
+-- TaskUpdate x N(预分配负责人)
| -> 任务#1的负责人为worker-1,以此类推
|
+-- Task(team_name="fix-ts-errors", name="worker-1") x 3
| -> 生成协作Agent加入团队
|
+-- 监控循环
| <- 接收协作Agent发送的SendMessage(自动投递)
| -> 轮询TaskList获取进度
| -> 发送SendMessage以解除阻塞/协调工作
|
+-- 完成
-> 向每个协作Agent发送shutdown_request
<- 接收shutdown_response(approve: true)
-> TeamDelete("fix-ts-errors")
-> 删除.omc/state/team-state.json存储结构(由Claude Code管理):
~/.claude/
teams/fix-ts-errors/
config.json # 团队元数据 + 成员数组
tasks/fix-ts-errors/
.lock # 并发访问的文件锁
1.json # 子任务#1
2.json # 子任务#2(可能为内部任务)
3.json # 子任务#3
...Staged Pipeline (Canonical Team Runtime)
阶段化工作流(标准团队运行时)
Team execution follows a staged pipeline:
team-plan -> team-prd -> team-exec -> team-verify -> team-fix (loop)团队执行遵循阶段化工作流:
team-plan -> team-prd -> team-exec -> team-verify -> team-fix (循环)Stage Agent Routing
阶段Agent路由
Each pipeline stage uses specialized agents -- not just executors. The lead selects agents based on the stage and task characteristics.
| Stage | Required Agents | Optional Agents | Selection Criteria |
|---|---|---|---|
| team-plan | | | Use |
| team-prd | | | Use |
| team-exec | | | Match agent to subtask type. Use |
| team-verify | | | Always run |
| team-fix | | | Use |
Routing rules:
- The lead picks agents per stage, not the user. The user's parameter only overrides the
N:agent-typestage worker type. All other stages use stage-appropriate specialists.team-exec - MCP providers complement Claude agents. Route analysis/review to Codex () and UI/large-context work to Gemini (
ask_codex) when available. MCP workers are one-shot and don't participate in team communication.ask_gemini - Cost mode affects model tier. In ecomode, downgrade: agents to
opus,sonnettosonnetwhere quality permits.haikualways uses at leastteam-verify.sonnet - Risk level escalates review. Security-sensitive or >20 file changes must include +
security-reviewer(opus) incode-reviewer.team-verify
每个工作流阶段使用专业Agent——不只是执行器。负责人会根据阶段和任务特性选择Agent。
| 阶段 | 必填Agent | 可选Agent | 选择标准 |
|---|---|---|---|
| team-plan | | | 需求不明确时使用 |
| team-prd | | | 面向用户的功能使用 |
| team-exec | | | 根据子任务类型匹配Agent。复杂自主工作使用 |
| team-verify | | | 始终运行 |
| team-fix | | | 类型/构建错误使用 |
路由规则:
- 负责人按阶段选择Agent,而非用户。用户的参数仅覆盖
N:agent-type阶段的工作类型。所有其他阶段使用适合该阶段的专业Agent。team-exec - MCP提供商补充Claude Agent。可用时,将分析/审查任务路由到Codex (),UI/大上下文工作路由到Gemini (
ask_codex)。MCP工作者为一次性任务,不参与团队通信。ask_gemini - 成本模式影响模型层级。在节能模式下,降级模型:Agent降级为
opus,sonnet在质量允许时降级为sonnet。haiku始终至少使用team-verify。sonnet - 风险级别提升审查要求。安全敏感或超过20个文件的变更必须在阶段包含
team-verify+security-reviewer(opus)。code-reviewer
Stage Entry/Exit Criteria
阶段进入/退出标准
- team-plan
- Entry: Team invocation is parsed and orchestration starts.
- Agents: scans codebase,
explorecreates task graph, optionallyplanner/analystfor complex tasks.architect - Exit: decomposition is complete and a runnable task graph is prepared.
- team-prd
- Entry: scope is ambiguous or acceptance criteria are missing.
- Agents: extracts requirements, optionally
analyst/product-manager.critic - Exit: acceptance criteria and boundaries are explicit.
- team-exec
- Entry: ,
TeamCreate, assignment, and worker spawn are complete.TaskCreate - Agents: workers spawned as the appropriate specialist type per subtask (see routing table).
- Exit: execution tasks reach terminal state for the current pass.
- Entry:
- team-verify
- Entry: execution pass finishes.
- Agents: + task-appropriate reviewers (see routing table).
verifier - Exit (pass): verification gates pass with no required follow-up.
- Exit (fail): fix tasks are generated and control moves to .
team-fix
- team-fix
- Entry: verification found defects/regressions/incomplete criteria.
- Agents: /
executor/build-fixerdepending on defect type.debugger - Exit: fixes are complete and flow returns to then
team-exec.team-verify
- team-plan
- 进入:团队调用已解析,编排开始。
- Agent:扫描代码库,
explore创建任务图,复杂任务可选择planner/analyst。architect - 退出:任务分解完成,可运行的任务图已准备好。
- team-prd
- 进入:范围不明确或验收标准缺失。
- Agent:提取需求,可选择
analyst/product-manager。critic - 退出:验收标准和边界已明确。
- team-exec
- 进入:、
TeamCreate、任务分配和工作Agent生成完成。TaskCreate - Agent:根据子任务类型生成相应的专业工作Agent(见路由表)。
- 退出:当前轮次的执行任务达到终端状态。
- 进入:
- team-verify
- 进入:执行轮次完成。
- Agent:+ 适合任务的审查Agent(见路由表)。
verifier - 退出(通过):验证关卡通过,无后续修复需求。
- 退出(失败):生成修复任务,控制转移到。
team-fix
- team-fix
- 进入:验证发现缺陷/回归/未完成的标准。
- Agent:根据缺陷类型使用/
executor/build-fixer。debugger - 退出:修复完成,流程返回然后
team-exec。team-verify
Verify/Fix Loop and Stop Conditions
验证/修复循环和停止条件
Continue until:
team-exec -> team-verify -> team-fix- verification passes and no required fix tasks remain, or
- work reaches an explicit terminal blocked/failed outcome with evidence.
team-fixfailed继续循环,直到:
team-exec -> team-verify -> team-fix- 验证通过且无待修复任务,或
- 工作达到明确的终端阻塞/失败状态并提供证据。
team-fixfailedResume and Cancel Semantics
恢复和取消语义
- Resume: restart from the last non-terminal stage using staged state + live task status.
- Cancel: requests teammate shutdown, waits for responses (best effort), marks phase
/oh-my-claudecode:cancelwithcancelled, captures cancellation metadata, then deletes team resources and clears/preserves Team state per policy.active=false - Terminal states are ,
complete, andfailed.cancelled
- 恢复: 使用阶段状态+实时任务状态,从最后一个非终端阶段重新开始。
- 取消: 请求协作Agent关闭,等待响应(尽力而为),将阶段标记为
/oh-my-claudecode:cancel且cancelled,捕获取消元数据,然后根据策略删除团队资源并清除/保留团队状态。active=false - 终端状态为、
complete和failed。cancelled
Workflow
工作流程
Phase 1: Parse Input
阶段1:解析输入
- Extract N (agent count), validate 1-20
- Extract agent-type, validate it maps to a known OMC subagent
- Extract task description
- 提取N(Agent数量),验证1-20的范围
- 提取agent-type,验证其映射到已知的OMC子Agent
- 提取task描述
Phase 2: Analyze & Decompose
阶段2:分析与分解
Use or (via MCP or agent) to analyze the codebase and break the task into N subtasks:
explorearchitect- Each subtask should be file-scoped or module-scoped to avoid conflicts
- Subtasks must be independent or have clear dependency ordering
- Each subtask needs a concise and detailed
subjectdescription - Identify dependencies between subtasks (e.g., "shared types must be fixed before consumers")
使用或(通过MCP或Agent)分析代码库,将任务分解为N个子任务:
explorearchitect- 每个子任务应以文件或模块为范围,避免冲突
- 子任务必须独立或有明确的依赖顺序
- 每个子任务需要简洁的和详细的
subjectdescription - 识别子任务之间的依赖关系(例如,“共享类型必须先修复,然后才能处理依赖它的任务”)
Phase 3: Create Team
阶段3:创建团队
Call with a slug derived from the task:
TeamCreatejson
{
"team_name": "fix-ts-errors",
"description": "Fix all TypeScript errors across the project"
}Response:
json
{
"team_name": "fix-ts-errors",
"team_file_path": "~/.claude/teams/fix-ts-errors/config.json",
"lead_agent_id": "team-lead@fix-ts-errors"
}The current session becomes the team lead ().
team-lead@fix-ts-errorsWrite OMC state using the MCP tool for proper session-scoped persistence:
state_writestate_write(mode="team", active=true, current_phase="team-plan", state={
"team_name": "fix-ts-errors",
"agent_count": 3,
"agent_types": "executor",
"task": "fix all TypeScript errors",
"fix_loop_count": 0,
"max_fix_loops": 3,
"linked_ralph": false,
"stage_history": "team-plan"
})Note: The MCPtool transports all values as strings. Consumers must coercestate_write,agent_count,fix_loop_countto numbers andmax_fix_loopsto boolean when reading state.linked_ralph
State schema fields:
| Field | Type | Description |
|---|---|---|
| boolean | Whether team mode is active |
| string | Current pipeline stage: |
| string | Slug name for the team |
| number | Number of worker agents |
| string | Comma-separated agent types used in team-exec |
| string | Original task description |
| number | Current fix iteration count |
| number | Maximum fix iterations before failing (default: 3) |
| boolean | Whether team is linked to a ralph persistence loop |
| string | Comma-separated list of stage transitions with timestamps |
Update state on every stage transition:
state_write(mode="team", current_phase="team-exec", state={
"stage_history": "team-plan:2026-02-07T12:00:00Z,team-prd:2026-02-07T12:01:00Z,team-exec:2026-02-07T12:02:00Z"
})Read state for resume detection:
state_read(mode="team")If and is non-terminal, resume from the last incomplete stage instead of creating a new team.
active=truecurrent_phase使用从任务派生的slug调用:
TeamCreatejson
{
"team_name": "fix-ts-errors",
"description": "修复项目中所有TypeScript错误"
}响应:
json
{
"team_name": "fix-ts-errors",
"team_file_path": "~/.claude/teams/fix-ts-errors/config.json",
"lead_agent_id": "team-lead@fix-ts-errors"
}当前会话成为团队负责人()。
team-lead@fix-ts-errors使用 MCP工具写入OMC状态,实现适当的会话范围持久化:
state_writestate_write(mode="team", active=true, current_phase="team-plan", state={
"team_name": "fix-ts-errors",
"agent_count": 3,
"agent_types": "executor",
"task": "fix all TypeScript errors",
"fix_loop_count": 0,
"max_fix_loops": 3,
"linked_ralph": false,
"stage_history": "team-plan"
})注意: MCP工具将所有值作为字符串传输。读取状态时,消费者必须将state_write、agent_count、fix_loop_count转换为数字,将max_fix_loops转换为布尔值。linked_ralph
状态架构字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| boolean | 团队模式是否激活 |
| string | 当前工作流阶段: |
| string | 团队的slug名称 |
| number | 工作Agent的数量 |
| string | team-exec阶段使用的Agent类型,逗号分隔 |
| string | 原始任务描述 |
| number | 当前修复迭代次数 |
| number | 失败前的最大修复迭代次数(默认:3) |
| boolean | 团队是否链接到Ralph持久化循环 |
| string | 包含时间戳的阶段转换列表,逗号分隔 |
每次阶段转换时更新状态:
state_write(mode="team", current_phase="team-exec", state={
"stage_history": "team-plan:2026-02-07T12:00:00Z,team-prd:2026-02-07T12:01:00Z,team-exec:2026-02-07T12:02:00Z"
})读取状态以检测恢复:
state_read(mode="team")如果且为非终端状态,则从最后一个未完成的阶段恢复,而不是创建新团队。
active=truecurrent_phasePhase 4: Create Tasks
阶段4:创建任务
Call for each subtask. Set dependencies with using .
TaskCreateTaskUpdateaddBlockedByjson
// TaskCreate for subtask 1
{
"subject": "Fix type errors in src/auth/",
"description": "Fix all TypeScript errors in src/auth/login.ts, src/auth/session.ts, and src/auth/types.ts. Run tsc --noEmit to verify.",
"activeForm": "Fixing auth type errors"
}Response stores a task file (e.g. ):
1.jsonjson
{
"id": "1",
"subject": "Fix type errors in src/auth/",
"description": "Fix all TypeScript errors in src/auth/login.ts...",
"activeForm": "Fixing auth type errors",
"owner": "",
"status": "pending",
"blocks": [],
"blockedBy": []
}For tasks with dependencies, use after creation:
TaskUpdatejson
// Task #3 depends on task #1 (shared types must be fixed first)
{
"taskId": "3",
"addBlockedBy": ["1"]
}Pre-assign owners from the lead to avoid race conditions (there is no atomic claiming):
json
// Assign task #1 to worker-1
{
"taskId": "1",
"owner": "worker-1"
}为每个子任务调用。使用和设置依赖关系。
TaskCreateTaskUpdateaddBlockedByjson
// 子任务1的TaskCreate
{
"subject": "修复src/auth/中的类型错误",
"description": "修复src/auth/login.ts、src/auth/session.ts和src/auth/types.ts中的所有TypeScript错误。运行tsc --noEmit进行验证。",
"activeForm": "修复认证模块类型错误"
}响应存储为任务文件(例如):
1.jsonjson
{
"id": "1",
"subject": "修复src/auth/中的类型错误",
"description": "修复src/auth/login.ts...",
"activeForm": "修复认证模块类型错误",
"owner": "",
"status": "pending",
"blocks": [],
"blockedBy": []
}对于有依赖关系的任务,创建后使用:
TaskUpdatejson
// 任务#3依赖任务#1(共享类型必须先修复)
{
"taskId": "3",
"addBlockedBy": ["1"]
}由负责人预分配所有者以避免竞争条件(无原子声明):
json
// 将任务#1分配给worker-1
{
"taskId": "1",
"owner": "worker-1"
}Phase 5: Spawn Teammates
阶段5:生成协作Agent
Spawn N teammates using with and parameters. Each teammate gets the team worker preamble (see below) plus their specific assignment.
Taskteam_namenamejson
{
"subagent_type": "oh-my-claudecode:executor",
"team_name": "fix-ts-errors",
"name": "worker-1",
"prompt": "<worker-preamble + assigned tasks>"
}Response:
json
{
"agent_id": "worker-1@fix-ts-errors",
"name": "worker-1",
"team_name": "fix-ts-errors"
}Side effects:
- Teammate added to members array
config.json - An internal task is auto-created (with ) tracking the agent lifecycle
metadata._internal: true - Internal tasks appear in output -- filter them when counting real tasks
TaskList
IMPORTANT: Spawn all teammates in parallel (they are background agents). Do NOT wait for one to finish before spawning the next.
使用带有和参数的生成N个协作Agent。每个协作Agent会获得团队工作前导(见下文)以及其特定的任务分配。
team_namenameTaskjson
{
"subagent_type": "oh-my-claudecode:executor",
"team_name": "fix-ts-errors",
"name": "worker-1",
"prompt": "<工作前导 + 分配的任务>"
}响应:
json
{
"agent_id": "worker-1@fix-ts-errors",
"name": "worker-1",
"team_name": "fix-ts-errors"
}副作用:
- 协作Agent添加到的成员数组中
config.json - 自动创建一个内部任务(带有)跟踪Agent生命周期
metadata._internal: true - 内部任务会出现在输出中——统计实际任务进度时需要过滤掉它们
TaskList
重要提示: 并行生成所有协作Agent(它们是后台Agent)。不要等待一个完成后再生成下一个。
Phase 6: Monitor
阶段6:监控
The lead orchestrator monitors progress through two channels:
-
Inbound messages -- Teammates sendto
SendMessagewhen they complete tasks or need help. These arrive automatically as new conversation turns (no polling needed).team-lead -
TaskList polling -- Periodically callto check overall progress:
TaskList#1 [completed] Fix type errors in src/auth/ (worker-1) #3 [in_progress] Fix type errors in src/api/ (worker-2) #5 [pending] Fix type errors in src/utils/ (worker-3)Format:#ID [status] subject (owner)
Coordination actions the lead can take:
- Unblock a teammate: Send a with guidance or missing context
message - Reassign work: If a teammate finishes early, use to assign pending tasks to them and notify via
TaskUpdateSendMessage - Handle failures: If a teammate reports failure, reassign the task or spawn a replacement
负责人通过两个渠道监控进度:
-
入站消息——协作Agent完成任务或需要帮助时,会向发送
team-lead。这些消息会自动作为新的对话轮次到达(无需轮询)。SendMessage -
TaskList轮询——定期调用检查整体进度:
TaskList#1 [completed] 修复src/auth/中的类型错误 (worker-1) #3 [in_progress] 修复src/api/中的类型错误 (worker-2) #5 [pending] 修复src/utils/中的类型错误 (worker-3)格式:#ID [状态] 主题 (所有者)
负责人可采取的协调操作:
- 解除协作Agent的阻塞: 发送带有指导或缺失上下文的
message - 重新分配工作: 如果某个协作Agent提前完成,使用将待处理任务分配给它,并通过
TaskUpdate通知SendMessage - 处理失败: 如果协作Agent报告失败,重新分配任务或生成替代Agent
Task Watchdog Policy
任务监控策略
Monitor for stuck or failed teammates:
- Max in-progress age: If a task stays for more than 5 minutes without messages, send a status check
in_progress - Suspected dead worker: No messages + stuck task for 10+ minutes → reassign task to another worker
- Reassign threshold: If a worker fails 2+ tasks, stop assigning new tasks to it
监控卡住或失败的协作Agent:
- 最大进行中时长:如果任务在状态下超过5分钟且无消息,发送状态检查
in_progress - 疑似工作Agent死亡:无消息+任务卡住10分钟以上 → 将任务重新分配给其他工作Agent
- 重新分配阈值:如果工作Agent失败2次以上,停止向其分配新任务
Phase 6.5: Stage Transitions (State Persistence)
阶段6.5:阶段转换(状态持久化)
On every stage transition, update OMC state:
// Entering team-exec after planning
state_write(mode="team", current_phase="team-exec", state={
"stage_history": "team-plan:T1,team-prd:T2,team-exec:T3"
})
// Entering team-verify after execution
state_write(mode="team", current_phase="team-verify")
// Entering team-fix after verify failure
state_write(mode="team", current_phase="team-fix", state={
"fix_loop_count": 1
})This enables:
- Resume: If the lead crashes, reveals the last stage and team name for recovery
state_read(mode="team") - Cancel: The cancel skill reads to know what cleanup is needed
current_phase - Ralph integration: Ralph can read team state to know if the pipeline completed or failed
每次阶段转换时,更新OMC状态:
// 规划完成后进入team-exec
state_write(mode="team", current_phase="team-exec", state={
"stage_history": "team-plan:T1,team-prd:T2,team-exec:T3"
})
// 执行完成后进入team-verify
state_write(mode="team", current_phase="team-verify")
// 验证失败后进入team-fix
state_write(mode="team", current_phase="team-fix", state={
"fix_loop_count": 1
})这实现了:
- 恢复:如果负责人崩溃,会显示最后一个阶段和团队名称以进行恢复
state_read(mode="team") - 取消:取消技能读取以了解需要清理的内容
current_phase - Ralph集成:Ralph可以读取团队状态以了解工作流是否完成或失败
Phase 7: Completion
阶段7:完成
When all real tasks (non-internal) are completed or failed:
- Verify results -- Check that all subtasks are marked via
completedTaskList - Shutdown teammates -- Send to each active teammate:
shutdown_requestjson{ "type": "shutdown_request", "recipient": "worker-1", "content": "All work complete, shutting down team" } - Await responses -- Each teammate responds with and terminates
shutdown_response(approve: true) - Delete team -- Call to clean up:
TeamDeleteResponse:json{ "team_name": "fix-ts-errors" }json{ "success": true, "message": "Cleaned up directories and worktrees for team \"fix-ts-errors\"", "team_name": "fix-ts-errors" } - Clean OMC state -- Remove
.omc/state/team-state.json - Report summary -- Present results to the user
当所有实际任务(非内部任务)完成或失败时:
- 验证结果——通过检查所有子任务是否标记为
TaskListcompleted - 关闭协作Agent——向每个活跃的协作Agent发送:
shutdown_requestjson{ "type": "shutdown_request", "recipient": "worker-1", "content": "所有工作完成,正在关闭团队" } - 等待响应——每个协作Agent回复并终止
shutdown_response(approve: true) - 删除团队——调用进行清理:
TeamDelete响应:json{ "team_name": "fix-ts-errors" }json{ "success": true, "message": "清理团队\"fix-ts-errors\"的目录和工作树", "team_name": "fix-ts-errors" } - 清理OMC状态——删除
.omc/state/team-state.json - 报告总结——向用户展示结果
Agent Preamble
Agent前导
When spawning teammates, include this preamble in the prompt to establish the work protocol. Adapt it per teammate with their specific task assignments.
You are a TEAM WORKER in team "{team_name}". Your name is "{worker_name}".
You report to the team lead ("team-lead").
== WORK PROTOCOL ==
1. CLAIM: Call TaskList to see your assigned tasks (owner = "{worker_name}").
Pick the first task with status "pending" that is assigned to you.
Call TaskUpdate to set status "in_progress":
{"taskId": "ID", "status": "in_progress", "owner": "{worker_name}"}
2. WORK: Execute the task using your tools (Read, Write, Edit, Bash).
Do NOT spawn sub-agents. Do NOT delegate. Work directly.
3. COMPLETE: When done, mark the task completed:
{"taskId": "ID", "status": "completed"}
4. REPORT: Notify the lead via SendMessage:
{"type": "message", "recipient": "team-lead", "content": "Completed task #ID: <summary of what was done>", "summary": "Task #ID complete"}
5. NEXT: Check TaskList for more assigned tasks. If you have more pending tasks, go to step 1.
If no more tasks are assigned to you, notify the lead:
{"type": "message", "recipient": "team-lead", "content": "All assigned tasks complete. Standing by.", "summary": "All tasks done, standing by"}
6. SHUTDOWN: When you receive a shutdown_request, respond with:
{"type": "shutdown_response", "request_id": "<from the request>", "approve": true}
== BLOCKED TASKS ==
If a task has blockedBy dependencies, skip it until those tasks are completed.
Check TaskList periodically to see if blockers have been resolved.
== ERRORS ==
If you cannot complete a task, report the failure to the lead:
{"type": "message", "recipient": "team-lead", "content": "FAILED task #ID: <reason>", "summary": "Task #ID failed"}
Do NOT mark the task as completed. Leave it in_progress so the lead can reassign.
== RULES ==
- NEVER spawn sub-agents or use the Task tool
- ALWAYS use absolute file paths
- ALWAYS report progress via SendMessage to "team-lead"
- Use SendMessage with type "message" only -- never "broadcast"生成协作Agent时,在提示中包含此内容以建立工作协议。根据每个协作Agent的特定任务分配进行调整。
你是团队"{team_name}"中的TEAM WORKER。你的名字是"{worker_name}"。
你向团队负责人("team-lead")汇报。
== 工作协议 ==
1. 认领任务:调用TaskList查看分配给你的任务(owner = "{worker_name}")。
选择第一个状态为"pending"且分配给你的任务。
调用TaskUpdate将状态设置为"in_progress":
{"taskId": "ID", "status": "in_progress", "owner": "{worker_name}"}
2. 工作:使用你的工具(Read、Write、Edit、Bash)执行任务。
不要生成子Agent。不要委托任务。直接工作。
3. 完成:完成后,将任务标记为已完成:
{"taskId": "ID", "status": "completed"}
4. 报告:通过SendMessage通知负责人:
{"type": "message", "recipient": "team-lead", "content": "完成任务#ID:<完成内容摘要>", "summary": "任务#ID完成"}
5. 下一个任务:检查TaskList是否有更多分配给你的任务。如果有更多待处理任务,回到步骤1。
如果没有更多分配给你的任务,通知负责人:
{"type": "message", "recipient": "team-lead", "content": "所有分配的任务完成。待命。", "summary": "所有任务完成,待命"}
6. 关闭:收到shutdown_request时,回复:
{"type": "shutdown_response", "request_id": "<来自请求的ID>", "approve": true}
== 阻塞任务 ==
如果任务有blockedBy依赖项,请跳过它,直到这些任务完成。
定期检查TaskList以查看阻塞是否已解决。
== 错误 ==
如果无法完成任务,向负责人报告失败:
{"type": "message", "recipient": "team-lead", "content": "任务#ID失败:<原因>", "summary": "任务#ID失败"}
不要将任务标记为已完成。保持in_progress状态,以便负责人重新分配。
== 规则 ==
- 永远不要生成子Agent或使用Task工具
- 始终使用绝对文件路径
- 始终通过SendMessage向"team-lead"报告进度
- 仅使用类型为"message"的SendMessage——不要使用"broadcast"Communication Patterns
通信模式
Teammate to Lead (task completion report)
协作Agent到负责人(任务完成报告)
json
{
"type": "message",
"recipient": "team-lead",
"content": "Completed task #1: Fixed 3 type errors in src/auth/login.ts and 2 in src/auth/session.ts. All files pass tsc --noEmit.",
"summary": "Task #1 complete"
}json
{
"type": "message",
"recipient": "team-lead",
"content": "完成任务#1:修复了src/auth/login.ts中的3个类型错误和src/auth/session.ts中的2个类型错误。所有文件通过tsc --noEmit验证。",
"summary": "任务#1完成"
}Lead to Teammate (reassignment or guidance)
负责人到协作Agent(重新分配或指导)
json
{
"type": "message",
"recipient": "worker-2",
"content": "Task #3 is now unblocked. Also pick up task #5 which was originally assigned to worker-1.",
"summary": "New task assignment"
}json
{
"type": "message",
"recipient": "worker-2",
"content": "任务#3现在已解除阻塞。同时接手原本分配给worker-1的任务#5。",
"summary": "新任务分配"
}Broadcast (use sparingly -- sends N separate messages)
广播(谨慎使用——发送N条单独消息)
json
{
"type": "broadcast",
"content": "STOP: shared types in src/types/index.ts have changed. Pull latest before continuing.",
"summary": "Shared types changed"
}json
{
"type": "broadcast",
"content": "停止:src/types/index.ts中的共享类型已更改。继续前请拉取最新版本。",
"summary": "共享类型已更改"
}Shutdown Protocol
关闭协议
Lead sends:
json
{
"type": "shutdown_request",
"recipient": "worker-1",
"content": "All work complete, shutting down team"
}Teammate receives and responds:
json
{
"type": "shutdown_response",
"request_id": "shutdown-1770428632375@worker-1",
"approve": true
}After approval:
- Teammate process terminates
- Teammate auto-removed from members array
config.json - Internal task for that teammate completes
IMPORTANT: The is provided in the shutdown request message that the teammate receives. The teammate must extract it and pass it back. Do NOT fabricate request IDs.
request_id负责人发送:
json
{
"type": "shutdown_request",
"recipient": "worker-1",
"content": "所有工作完成,正在关闭团队"
}协作Agent接收并回复:
json
{
"type": "shutdown_response",
"request_id": "shutdown-1770428632375@worker-1",
"approve": true
}批准后:
- 协作Agent进程终止
- 协作Agent自动从成员中移除
config.json - 该协作Agent的内部任务完成
重要提示: 在协作Agent收到的关闭请求JSON中提供。协作Agent必须提取它并返回。不要编造此ID,否则关闭会静默失败。
request_idMCP Workers (Hybrid Roles)
MCP工作者(混合角色)
The team skill supports hybrid execution combining Claude agent teammates with external MCP workers (Codex and Gemini CLIs). Both types can make code changes -- they differ in capabilities and cost.
团队技能支持混合执行,将Claude Agent协作Agent与外部MCP工作者(Codex和Gemini CLI)结合使用。两种类型都可以进行代码更改——它们的能力和成本不同。
Execution Modes
执行模式
Tasks are tagged with an execution mode during decomposition:
| Execution Mode | Provider | Capabilities |
|---|---|---|
| Claude agent | Full Claude Code tool access (Read/Write/Edit/Bash/Task). Best for tasks needing Claude's reasoning + iterative tool use. |
| Codex CLI ( | Full filesystem access in working_directory. Runs autonomously. Best for code review, security analysis, refactoring, architecture. |
| Gemini CLI ( | Full filesystem access + 1M token context. Runs autonomously. Best for UI/frontend work, large-scale changes, documentation. |
任务在分解时会标记执行模式:
| 执行模式 | 提供商 | 能力 |
|---|---|---|
| Claude Agent | 完全访问Claude Code工具(Read/Write/Edit/Bash/Task)。最适合需要Claude推理+迭代工具使用的任务。 |
| Codex CLI ( | 完全访问working_directory中的文件系统。自主运行。最适合代码审查、安全分析、重构、架构设计。 |
| Gemini CLI ( | 完全访问文件系统+1M token上下文。自主运行。最适合UI/前端工作、大规模变更、文档。 |
How MCP Workers Operate
MCP工作者的运行方式
Codex and Gemini CLIs run in full-auto mode with filesystem access. They are autonomous executors, not just analysts:
- Lead writes task instructions to a
prompt_file - Lead calls or
ask_codexwithask_geminiset to the project rootworking_directory - The CLI reads files, makes changes, runs commands -- all within the working directory
- Results/summary are written to
output_file - Lead reads the output, marks the task complete, and feeds results to dependent tasks
Key difference from Claude teammates:
- MCP workers operate via CLI, not Claude Code's tool system
- They cannot use TaskList/TaskUpdate/SendMessage (no team awareness)
- They run as one-shot autonomous jobs, not persistent teammates
- The lead manages their lifecycle (spawn, monitor, collect results)
Codex和Gemini CLI在全自动化模式下运行,具有文件系统访问权限。它们是自主执行器,而不仅仅是分析器:
- 负责人将任务说明写入
prompt_file - 负责人调用或
ask_codex,将ask_gemini设置为项目根目录working_directory - CLI读取文件、进行更改、运行命令——所有操作都在工作目录内
- 结果/摘要写入
output_file - 负责人读取输出,标记任务完成,并将结果提供给依赖任务
与Claude协作Agent的主要区别:
- MCP工作者通过CLI运行,而非Claude Code的工具系统
- 他们无法使用TaskList/TaskUpdate/SendMessage(无团队意识)
- 他们作为一次性自主作业运行,而非持久化协作Agent
- 负责人管理他们的生命周期(生成、监控、收集结果)
When to Route Where
路由选择
| Task Type | Best Route | Why |
|---|---|---|
| Iterative multi-step work | Claude teammate | Needs tool-mediated iteration + team communication |
| Code review / security audit | Codex MCP | Specialized, cheaper than Claude opus |
| Architecture analysis / planning | Codex MCP | External perspective, strong analytical reasoning |
| Refactoring (well-scoped) | Codex MCP | Autonomous execution, good at structured transforms |
| UI/frontend implementation | Gemini MCP | 1M context window, design expertise, can edit many files |
| Large-scale documentation | Gemini MCP | Writing expertise + large context for consistency |
| Visual/image analysis | Gemini MCP | Multimodal capability |
| Build/test iteration loops | Claude teammate | Needs Bash tool + iterative fix cycles |
| Tasks needing team coordination | Claude teammate | Needs SendMessage for status updates |
| 任务类型 | 最佳路由 | 原因 |
|---|---|---|
| 迭代式多步骤工作 | Claude协作Agent | 需要工具介导的迭代+团队沟通 |
| 代码审查/安全审计 | Codex MCP | 专业,比Claude opus便宜 |
| 架构分析/规划 | Codex MCP | 外部视角,强大的分析推理能力 |
| 重构(范围明确) | Codex MCP | 自主执行,擅长结构化转换 |
| UI/前端实现 | Gemini MCP | 1M上下文窗口,设计专长,可编辑多个文件 |
| 大规模文档 | Gemini MCP | 写作专长+大上下文确保一致性 |
| 视觉/图像分析 | Gemini MCP | 多模态能力 |
| 构建/测试迭代循环 | Claude协作Agent | 需要Bash工具+迭代修复周期 |
| 需要团队协调的任务 | Claude协作Agent | 需要SendMessage进行状态更新 |
Example: Hybrid Team with MCP Executors
示例:带有MCP执行器的混合团队
/team 3:executor "refactor auth module with security review"
Task decomposition:
#1 [mcp_codex] Security review of current auth code -> output to .omc/research/auth-security.md
#2 [mcp_codex] Refactor auth/login.ts and auth/session.ts (uses #1 findings)
#3 [mcp_gemini] Redesign auth UI components (login form, session indicator)
#4 [claude_worker] Update auth tests + fix integration issues
#5 [mcp_codex] Final code review of all changesThe lead runs #1 (Codex analysis), then #2 and #3 in parallel (Codex refactors backend, Gemini redesigns frontend), then #4 (Claude teammate handles test iteration), then #5 (final Codex review).
/team 3:executor "重构认证模块并进行安全审查"
任务分解:
#1 [mcp_codex] 现有认证代码的安全审查 -> 输出到.omc/research/auth-security.md
#2 [mcp_codex] 重构auth/login.ts和auth/session.ts(使用#1的发现)
#3 [mcp_gemini] 重新设计认证UI组件(登录表单、会话指示器)
#4 [claude_worker] 更新认证测试+修复集成问题
#5 [mcp_codex] 所有变更的最终代码审查负责人运行#1(Codex分析),然后并行运行#2和#3(Codex重构后端,Gemini重新设计前端),然后运行#4(Claude协作Agent处理测试迭代),最后运行#5(最终Codex审查)。
MCP Pre-flight Analysis (Optional)
MCP预飞行分析(可选)
For large ambiguous tasks, run analysis before team creation:
- Call to discover deferred MCP tools (required before first use)
ToolSearch("mcp") - Call (planner role) with task description + codebase context
ask_codex - Use the analysis to produce better task decomposition
- Create team and tasks with enriched context
If ToolSearch finds no MCP tools, skip MCP pre-flight and use Claude agents instead.
This is especially useful when the task scope is unclear and benefits from external reasoning before committing to a specific decomposition.
对于大型模糊任务,在创建团队前运行分析:
- 调用发现延迟的MCP工具(首次使用前需要)
ToolSearch("mcp") - 调用(规划师角色),提供任务描述+代码库上下文
ask_codex - 使用分析结果生成更好的任务分解
- 创建团队和任务,使用丰富的上下文
如果ToolSearch未找到MCP工具,则跳过MCP预飞行,使用Claude Agent。
当任务范围不明确,且在提交特定分解前需要外部推理时,这尤其有用。
Monitor Enhancement: Outbox Auto-Ingestion
监控增强:发件箱自动摄取
The lead can proactively ingest outbox messages from MCP workers using the outbox reader utilities, enabling event-driven monitoring without relying solely on delivery.
SendMessage负责人可以使用发件箱读取工具主动摄取MCP工作者的发件箱消息,实现事件驱动的监控,而不仅仅依赖投递。
SendMessageOutbox Reader Functions
发件箱读取函数
readNewOutboxMessages(teamName, workerName)readNewInboxMessages()readAllTeamOutboxMessages(teamName){ workerName, messages }resetOutboxCursor(teamName, workerName)readNewOutboxMessages(teamName, workerName)readNewInboxMessages()readAllTeamOutboxMessages(teamName){ workerName, messages }resetOutboxCursor(teamName, workerName)Using getTeamStatus()
in the Monitor Phase
getTeamStatus()在监控阶段使用getTeamStatus()
getTeamStatus()The function provides a unified snapshot combining:
getTeamStatus(teamName, workingDirectory, heartbeatMaxAgeMs?)- Worker registration -- Which MCP workers are registered (from shadow registry / config.json)
- Heartbeat freshness -- Whether each worker is alive based on heartbeat age
- Task progress -- Per-worker and team-wide task counts (pending, in_progress, completed)
- Current task -- Which task each worker is actively executing
- Recent outbox messages -- New messages since the last status check
Example usage in the monitor loop:
typescript
const status = getTeamStatus('fix-ts-errors', workingDirectory);
for (const worker of status.workers) {
if (!worker.isAlive) {
// Worker is dead -- reassign its in-progress tasks
}
for (const msg of worker.recentMessages) {
if (msg.type === 'task_complete') {
// Mark task complete, unblock dependents
} else if (msg.type === 'task_failed') {
// Handle failure, possibly retry or reassign
} else if (msg.type === 'error') {
// Log error, check if worker needs intervention
}
}
}
if (status.taskSummary.pending === 0 && status.taskSummary.inProgress === 0) {
// All work done -- proceed to shutdown
}getTeamStatus(teamName, workingDirectory, heartbeatMaxAgeMs?)- 工作者注册——已注册的MCP工作者(来自影子注册表/config.json)
- 心跳新鲜度——根据心跳时长判断每个工作者是否存活
- 任务进度——每个工作者和团队范围的任务计数(pending、in_progress、completed)
- 当前任务——每个工作者正在执行的任务
- 最近的发件箱消息——自上次状态检查以来的新消息
监控循环中的示例用法:
typescript
const status = getTeamStatus('fix-ts-errors', workingDirectory);
for (const worker of status.workers) {
if (!worker.isAlive) {
// 工作者已死亡——重新分配其进行中的任务
}
for (const msg of worker.recentMessages) {
if (msg.type === 'task_complete') {
// 标记任务完成,检查阻塞任务是否现在已解除阻塞,通知依赖工作者
} else if (msg.type === 'task_failed') {
// 处理失败,决定重试、重新分配或跳过
} else if (msg.type === 'error') {
// 记录错误,检查心跳中的consecutiveErrors是否达到隔离阈值
}
}
}
if (status.taskSummary.pending === 0 && status.taskSummary.inProgress === 0) {
// 所有工作完成——进入关闭流程
}Event-Based Actions from Outbox Messages
发件箱消息的事件驱动操作
| Message Type | Action |
|---|---|
| Mark task completed, check if blocked tasks are now unblocked, notify dependent workers |
| Increment failure sidecar, decide retry vs reassign vs skip |
| Worker has no assigned tasks -- assign pending work or begin shutdown |
| Log the error, check |
| Worker acknowledged shutdown -- safe to remove from team |
| Update liveness tracking (redundant with heartbeat files but useful for latency monitoring) |
This approach complements the existing -based communication by providing a pull-based mechanism for MCP workers that cannot use Claude Code's team messaging tools.
SendMessage| 消息类型 | 操作 |
|---|---|
| 标记任务完成,检查阻塞任务是否已解除阻塞,通知依赖工作者 |
| 增加失败次数,决定重试、重新分配或跳过 |
| 工作者无分配任务——分配待处理工作或开始关闭 |
| 记录错误,检查 |
| 工作者确认关闭——可以安全地从团队中移除 |
| 更新活跃度跟踪(与心跳文件冗余,但对延迟监控有用) |
这种方法通过为无法使用Claude Code团队消息工具的MCP工作者提供基于拉取的机制,补充了现有的基于的通信。
SendMessageError Handling
错误处理
Teammate Fails a Task
协作Agent任务失败
- Teammate sends to lead reporting the failure
SendMessage - Lead decides: retry (reassign same task to same or different worker) or skip
- To reassign: to set new owner, then
TaskUpdateto the new ownerSendMessage
- 协作Agent向负责人发送报告失败
SendMessage - 负责人决定:重试(将同一任务重新分配给相同或不同的工作者)或跳过
- 重新分配:使用设置新所有者,然后向新所有者发送
TaskUpdateSendMessage
Teammate Gets Stuck (No Messages)
协作Agent卡住(无消息)
- Lead detects via -- task stuck in
TaskListfor too longin_progress - Lead sends to the teammate asking for status
SendMessage - If no response, consider the teammate dead
- Reassign the task to another worker via
TaskUpdate
- 负责人通过检测到——任务卡在
TaskList状态太久in_progress - 负责人向协作Agent发送询问状态
SendMessage - 如果无响应,认为协作Agent已死亡
- 通过将任务重新分配给其他工作者
TaskUpdate
Dependency Blocked
依赖阻塞
- If a blocking task fails, the lead must decide whether to:
- Retry the blocker
- Remove the dependency (with modified blockedBy)
TaskUpdate - Skip the blocked task entirely
- Communicate decisions to affected teammates via
SendMessage
- 如果阻塞任务失败,负责人必须决定:
- 重试阻塞任务
- 移除依赖(使用修改blockedBy)
TaskUpdate - 完全跳过被阻塞的任务
- 通过向受影响的协作Agent传达决定
SendMessage
Teammate Crashes
协作Agent崩溃
- Internal task for that teammate will show unexpected status
- Teammate disappears from members
config.json - Lead reassigns orphaned tasks to remaining workers
- If needed, spawn a replacement teammate with
Task(team_name, name)
- 该协作Agent的内部任务会显示异常状态
- 协作Agent从成员中消失
config.json - 负责人将孤立任务重新分配给剩余工作者
- 如果需要,使用生成替代协作Agent
Task(team_name, name)
Team + Ralph Composition
Team + Ralph组合
When the user invokes , says "team ralph", or combines both keywords, team mode wraps itself in Ralph's persistence loop. This provides:
/team ralph- Team orchestration -- multi-agent staged pipeline with specialized agents per stage
- Ralph persistence -- retry on failure, architect verification before completion, iteration tracking
当用户调用、说"team ralph"或组合这两个关键词时,团队模式会将自身包裹在Ralph的持久化循环中。这提供了:
/team ralph- 团队编排——多Agent阶段化工作流,每个阶段使用专业Agent
- Ralph持久化——失败时重试,完成前需架构师验证,迭代跟踪
Activation
激活
Team+Ralph activates when:
- User invokes or
/team ralph "task"/oh-my-claudecode:team ralph "task" - Keyword detector finds both and
teamin the promptralph - Hook detects alongside team context
MAGIC KEYWORD: RALPH
Team+Ralph在以下情况激活:
- 用户调用或
/team ralph "task"/oh-my-claudecode:team ralph "task" - 关键字检测器在提示中同时发现和
teamralph - 钩子检测到和团队上下文
MAGIC KEYWORD: RALPH
State Linkage
状态链接
Both modes write their own state files with cross-references:
// Team state (via state_write)
state_write(mode="team", active=true, current_phase="team-plan", state={
"team_name": "build-rest-api",
"linked_ralph": true,
"task": "build a complete REST API"
})
// Ralph state (via state_write)
state_write(mode="ralph", active=true, iteration=1, max_iterations=10, current_phase="execution", state={
"linked_team": true,
"team_name": "build-rest-api"
})两种模式都会写入自己的状态文件,并带有交叉引用:
// 团队状态(通过state_write)
state_write(mode="team", active=true, current_phase="team-plan", state={
"team_name": "build-rest-api",
"linked_ralph": true,
"task": "构建完整的REST API"
})
// Ralph状态(通过state_write)
state_write(mode="ralph", active=true, iteration=1, max_iterations=10, current_phase="execution", state={
"linked_team": true,
"team_name": "build-rest-api"
})Execution Flow
执行流程
- Ralph outer loop starts (iteration 1)
- Team pipeline runs:
team-plan -> team-prd -> team-exec -> team-verify - If passes: Ralph runs architect verification (STANDARD tier minimum)
team-verify - If architect approves: both modes complete, run
/oh-my-claudecode:cancel - If fails OR architect rejects: team enters
team-verify, then loops back toteam-fixteam-exec -> team-verify - If fix loop exceeds : Ralph increments iteration and retries the full pipeline
max_fix_loops - If Ralph exceeds : terminal
max_iterationsstatefailed
- Ralph外部循环开始(迭代1)
- 团队工作流运行:
team-plan -> team-prd -> team-exec -> team-verify - 如果通过:Ralph运行架构师验证(最低STANDARD tier)
team-verify - 如果架构师批准:两种模式都完成,运行
/oh-my-claudecode:cancel - 如果失败或架构师拒绝:团队进入
team-verify,然后循环回到team-fixteam-exec -> team-verify - 如果修复循环超过:Ralph增加迭代次数并重试整个工作流
max_fix_loops - 如果Ralph超过:终端
max_iterations状态failed
Cancellation
取消
Cancel either mode cancels both:
- Cancel Ralph (linked): Cancel Team first (graceful shutdown), then clear Ralph state
- Cancel Team (linked): Clear Team, mark Ralph iteration cancelled, stop loop
See Cancellation section below for details.
取消任一模式都会取消两者:
- 取消Ralph(已链接): 先取消团队(优雅关闭),然后清除Ralph状态
- 取消团队(已链接): 清除团队状态,标记Ralph迭代为已取消,停止循环
详情见下文的取消部分。
Idempotent Recovery
幂等恢复
If the lead crashes mid-run, the team skill should detect existing state and resume:
- Check for teams matching the task slug
~/.claude/teams/ - If found, read to discover active members
config.json - Resume monitor mode instead of creating a duplicate team
- Call to determine current progress
TaskList - Continue from the monitoring phase
This prevents duplicate teams and allows graceful recovery from lead failures.
如果负责人在运行中崩溃,团队技能应检测现有状态并恢复:
- 检查是否有与任务slug匹配的团队
~/.claude/teams/ - 如果找到,读取发现活跃成员
config.json - 恢复监控模式,而非创建重复团队
- 调用确定当前进度
TaskList - 从监控阶段继续
这防止了重复团队,并允许从负责人失败中优雅恢复。
Comparison: Team vs Legacy Swarm
对比:Team vs 旧版Swarm
| Aspect | Team (Native) | Swarm (Legacy SQLite) |
|---|---|---|
| Storage | JSON files in | SQLite in |
| Dependencies | | Requires |
| Task claiming | | SQLite IMMEDIATE transaction -- atomic |
| Race conditions | Possible if two agents claim same task (mitigate by pre-assigning) | None (SQLite transactions) |
| Communication | | None (fire-and-forget agents) |
| Task dependencies | Built-in | Not supported |
| Heartbeat | Automatic idle notifications from Claude Code | Manual heartbeat table + polling |
| Shutdown | Graceful request/response protocol | Signal-based termination |
| Agent lifecycle | Auto-tracked via internal tasks + config members | Manual tracking via heartbeat table |
| Progress visibility | | SQL queries on tasks table |
| Conflict prevention | Owner field (lead-assigned) | Lease-based claiming with timeout |
| Crash recovery | Lead detects via missing messages, reassigns | Auto-release after 5-min lease timeout |
| State cleanup | | Manual |
When to use Team over Swarm: Always prefer for new work. It uses Claude Code's built-in infrastructure, requires no external dependencies, supports inter-agent communication, and has task dependency management.
/team| 方面 | Team(原生) | Swarm(旧版SQLite) |
|---|---|---|
| 存储 | JSON文件存储在 | SQLite存储在 |
| 依赖 | 不需要 | 需要 |
| 任务认领 | | SQLite IMMEDIATE事务——原子操作 |
| 竞争条件 | 如果两个Agent认领同一任务可能发生(通过预分配缓解) | 无(SQLite事务) |
| 通信 | | 无(一发即忘的Agent) |
| 任务依赖 | 内置 | 不支持 |
| 心跳 | Claude Code自动发送空闲通知 | 手动心跳表+轮询 |
| 关闭 | 优雅的请求/响应协议 | 基于信号的终止 |
| Agent生命周期 | 通过内部任务+配置成员自动跟踪 | 通过心跳表手动跟踪 |
| 进度可见性 | | 对任务表的SQL查询 |
| 冲突预防 | 所有者字段(负责人分配) | 基于租约的认领,带超时 |
| 崩溃恢复 | 负责人通过缺失消息检测,重新分配 | 5分钟租约超时后自动释放 |
| 状态清理 | | 手动删除SQLite数据库 |
何时使用Team而非Swarm: 新工作始终优先使用。它使用Claude Code的内置基础设施,无需外部依赖,支持Agent间通信,并具有任务依赖管理。
/teamCancellation
取消
The skill handles team cleanup:
/oh-my-claudecode:cancel- Read team state via to get
state_read(mode="team")andteam_namelinked_ralph - Send to all active teammates (from
shutdown_requestmembers)config.json - Wait for from each (15s timeout per member)
shutdown_response - Call to remove team and task directories
TeamDelete - Clear state via
state_clear(mode="team") - If is true, also clear ralph:
linked_ralphstate_clear(mode="ralph")
/oh-my-claudecode:cancel- 通过读取团队状态,获取
state_read(mode="team")和team_namelinked_ralph - 向所有活跃协作Agent发送(来自
shutdown_request成员)config.json - 等待每个Agent的(每个成员15秒超时)
shutdown_response - 调用删除团队和任务目录
TeamDelete - 通过清除状态
state_clear(mode="team") - 如果为true,也清除Ralph状态:
linked_ralphstate_clear(mode="ralph")
Linked Mode Cancellation (Team + Ralph)
链接模式取消(Team + Ralph)
When team is linked to ralph, cancellation follows dependency order:
- Cancel triggered from Ralph context: Cancel Team first (graceful shutdown of all teammates), then clear Ralph state. This ensures workers are stopped before the persistence loop exits.
- Cancel triggered from Team context: Clear Team state, then mark Ralph as cancelled. Ralph's stop hook will detect the missing team and stop iterating.
- Force cancel (): Clears both
--forceandteamstate unconditionally viaralph.state_clear
If teammates are unresponsive, may fail. In that case, the cancel skill should wait briefly and retry, or inform the user to manually clean up and .
TeamDelete~/.claude/teams/{team_name}/~/.claude/tasks/{team_name}/当团队链接到Ralph时,取消遵循依赖顺序:
- 从Ralph上下文触发取消: 先取消团队(优雅关闭所有协作Agent),然后清除Ralph状态。这确保在持久化循环退出前停止工作者。
- 从Team上下文触发取消: 清除团队状态,然后标记Ralph迭代为已取消。Ralph的停止钩子会检测到团队缺失并停止迭代。
- 强制取消(): 通过
--force无条件清除state_clear和team状态。ralph
如果协作Agent无响应,可能失败。在这种情况下,取消技能应短暂等待并重试,或告知用户手动清理和。
TeamDelete~/.claude/teams/{team_name}/~/.claude/tasks/{team_name}/Configuration
配置
Optional settings via :
.omc-config.jsonjson
{
"team": {
"maxAgents": 20,
"defaultAgentType": "executor",
"monitorIntervalMs": 30000,
"shutdownTimeoutMs": 15000
}
}- maxAgents - Maximum teammates (default: 20)
- defaultAgentType - Agent type when not specified (default: )
executor - monitorIntervalMs - How often to poll (default: 30s)
TaskList - shutdownTimeoutMs - How long to wait for shutdown responses (default: 15s)
Note: Team members do not have a hardcoded model default. Each teammate is a separate Claude Code session that inherits the user's configured model. Since teammates can spawn their own subagents, the session model acts as the orchestration layer while subagents can use any model tier.
通过进行可选设置:
.omc-config.jsonjson
{
"team": {
"maxAgents": 20,
"defaultAgentType": "executor",
"monitorIntervalMs": 30000,
"shutdownTimeoutMs": 15000
}
}- maxAgents - 最大协作Agent数量(默认:20)
- defaultAgentType - 未指定时的默认Agent类型(默认:)
executor - monitorIntervalMs - 轮询的频率(默认:30秒)
TaskList - shutdownTimeoutMs - 等待关闭响应的时长(默认:15秒)
注意: 团队成员没有硬编码的模型默认值。每个协作Agent是独立的Claude Code会话,继承用户配置的模型。由于协作Agent可以生成自己的子Agent,会话模型作为编排层,而子Agent可以使用任何模型层级。
State Cleanup
状态清理
On successful completion:
- handles all Claude Code state:
TeamDelete- Removes (config)
~/.claude/teams/{team_name}/ - Removes (all task files + lock)
~/.claude/tasks/{team_name}/
- Removes
- OMC state cleanup via MCP tools:
If linked to Ralph:
state_clear(mode="team")state_clear(mode="ralph") - Or run which handles all cleanup automatically.
/oh-my-claudecode:cancel
IMPORTANT: Call only AFTER all teammates have been shut down. will fail if active members (besides the lead) still exist in the config.
TeamDeleteTeamDelete成功完成后:
- 处理所有Claude Code状态:
TeamDelete- 移除(配置)
~/.claude/teams/{team_name}/ - 移除(所有任务文件+锁)
~/.claude/tasks/{team_name}/
- 移除
- 通过MCP工具清理OMC状态:
如果链接到Ralph:
state_clear(mode="team")state_clear(mode="ralph") - 或运行自动处理所有清理。
/oh-my-claudecode:cancel
重要提示: 仅在所有协作Agent关闭后调用。负责人(唯一剩余成员)不在此检查范围内。
TeamDeleteGit Worktree Integration
Git工作树集成
MCP workers can operate in isolated git worktrees to prevent file conflicts between concurrent workers.
MCP工作者可以在隔离的git工作树中操作,防止并发工作者之间的文件冲突。
How It Works
工作原理
-
Worktree creation: Before spawning a worker, callto create an isolated worktree at
createWorkerWorktree(teamName, workerName, repoRoot)with branch.omc/worktrees/{team}/{worker}.omc-team/{teamName}/{workerName} -
Worker isolation: Pass the worktree path as thein the worker's
workingDirectory. The worker operates exclusively in its own worktree.BridgeConfig -
Merge coordination: After a worker completes its tasks, useto verify the branch can be cleanly merged, then
checkMergeConflicts()to merge withmergeWorkerBranch()for clear history.--no-ff -
Team cleanup: On team shutdown, callto remove all worktrees and their branches.
cleanupTeamWorktrees(teamName, repoRoot)
-
工作树创建:生成工作者前,调用在
createWorkerWorktree(teamName, workerName, repoRoot)创建隔离工作树,分支为.omc/worktrees/{team}/{worker}。omc-team/{teamName}/{workerName} -
工作者隔离:将工作树路径作为传递给工作者的
workingDirectory。工作者仅在自己的工作树中操作。BridgeConfig -
合并协调:工作者完成任务后,使用验证分支是否可以干净合并,然后使用
checkMergeConflicts()以mergeWorkerBranch()合并,确保历史清晰。--no-ff -
团队清理:团队关闭时,调用移除所有工作树及其分支。
cleanupTeamWorktrees(teamName, repoRoot)
API Reference
API参考
| Function | Description |
|---|---|
| Create isolated worktree |
| Remove worktree and branch |
| List all team worktrees |
| Remove all team worktrees |
| Non-destructive conflict check |
| Merge worker branch (--no-ff) |
| Merge all completed workers |
| 函数 | 描述 |
|---|---|
| 创建隔离工作树 |
| 移除工作树和分支 |
| 列出所有团队工作树 |
| 移除所有团队工作树 |
| 非破坏性冲突检查 |
| 合并工作者分支(--no-ff) |
| 合并所有已完成的工作者分支 |
Important Notes
重要说明
- in
createSession()does NOT handle worktree creation — worktree lifecycle is managed separately viatmux-session.tsgit-worktree.ts - Worktrees are NOT cleaned up on individual worker shutdown — only on team shutdown, to allow post-mortem inspection
- Branch names are sanitized via to prevent injection
sanitizeName() - All paths are validated against directory traversal
- 中的
tmux-session.ts不处理工作树创建——工作树生命周期通过createSession()单独管理git-worktree.ts - 工作树不会在单个工作者关闭时清理——仅在团队关闭时清理,以便事后检查
- 分支名称通过进行清理,防止注入
sanitizeName() - 所有路径都会验证,防止目录遍历
Gotchas
注意事项
-
Internal tasks pollute TaskList -- When a teammate is spawned, the system auto-creates an internal task with. These appear in
metadata._internal: trueoutput. Filter them when counting real task progress. The subject of an internal task is the teammate's name.TaskList -
No atomic claiming -- Unlike SQLite swarm, there is no transactional guarantee on. Two teammates could race to claim the same task. Mitigation: The lead should pre-assign owners via
TaskUpdatebefore spawning teammates. Teammates should only work on tasks assigned to them.TaskUpdate(taskId, owner) -
Task IDs are strings -- IDs are auto-incrementing strings ("1", "2", "3"), not integers. Always pass string values tofields.
taskId -
TeamDelete requires empty team -- All teammates must be shut down before calling. The lead (the only remaining member) is excluded from this check.
TeamDelete -
Messages are auto-delivered -- Teammate messages arrive to the lead as new conversation turns. No polling or inbox-checking is needed for inbound messages. However, if the lead is mid-turn (processing), messages queue and deliver when the turn ends.
-
Teammate prompt stored in config -- The full prompt text is stored inmembers array. Do not put secrets or sensitive data in teammate prompts.
config.json -
Members auto-removed on shutdown -- After a teammate approves shutdown and terminates, it is automatically removed from. Do not re-read config expecting to find shut-down teammates.
config.json -
shutdown_response needs request_id -- The teammate must extract thefrom the incoming shutdown request JSON and pass it back. The format is
request_id. Fabricating this ID will cause the shutdown to fail silently.shutdown-{timestamp}@{worker-name} -
Team name must be a valid slug -- Use lowercase letters, numbers, and hyphens. Derive from the task description (e.g., "fix TypeScript errors" becomes "fix-ts-errors").
-
Broadcast is expensive -- Each broadcast sends a separate message to every teammate. Use(DM) by default. Only broadcast for truly team-wide critical alerts.
message -
MCP workers are one-shot, not persistent -- Codex and Gemini CLIs have full filesystem access and CAN make code changes. However, they run as autonomous one-shot jobs -- they cannot use TaskList/TaskUpdate/SendMessage. The lead must manage their lifecycle: write prompt_file, call MCP, read output_file, mark task complete. They don't participate in team communication like Claude teammates do.
-
内部任务污染TaskList——生成协作Agent时,系统会自动创建带有的内部任务。这些任务会出现在
metadata._internal: true输出中。统计实际任务进度时需要过滤掉它们。内部任务的主题是协作Agent的名称。TaskList -
无原子认领——与SQLite swarm不同,没有事务保证。两个协作Agent可能会竞争认领同一任务。缓解措施: 负责人应在生成协作Agent前,通过
TaskUpdate预分配所有者。协作Agent应仅处理分配给他们的任务。TaskUpdate(taskId, owner) -
任务ID是字符串——ID是自动递增的字符串("1"、"2"、"3"),而非整数。始终将字符串值传递给字段。
taskId -
TeamDelete需要空团队——调用前必须关闭所有协作Agent。负责人(唯一剩余成员)不在此检查范围内。
TeamDelete -
消息自动投递——协作Agent的消息会作为新的对话轮次到达负责人。入站消息无需轮询或检查收件箱。但是,如果负责人正在处理轮次(处理中),消息会排队,在轮次结束时投递。
-
协作Agent提示存储在配置中——完整的提示文本存储在成员数组中。不要在协作Agent提示中放入机密或敏感数据。
config.json -
成员在关闭时自动移除——协作Agent批准关闭并终止后,会自动从中移除。不要重新读取配置以查找已关闭的协作Agent。
config.json -
shutdown_response需要request_id——协作Agent必须从传入的关闭请求JSON中提取并返回。格式为
request_id。编造此ID会导致关闭静默失败。shutdown-{timestamp}@{worker-name} -
团队名称必须是有效的slug——使用小写字母、数字和连字符。从任务描述派生(例如,"修复TypeScript错误"变为"fix-ts-errors")。
-
广播成本高——每次广播会向每个协作Agent发送单独的消息。默认使用(私信)。仅在真正需要团队范围的关键警报时使用广播。
message -
MCP工作者是一次性的,非持久化——Codex和Gemini CLI具有完整的文件系统访问权限,可以进行代码更改。然而,它们作为自主一次性作业运行——无法使用TaskList/TaskUpdate/SendMessage。负责人必须管理它们的生命周期:写入prompt_file、调用MCP、读取output_file、标记任务完成。它们不像Claude协作Agent那样参与团队通信。