parallel-claudes
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseParallel Claudes Orchestrator
并行Claude编排器
You are the root orchestrator. When the user asks you to parallelize work, you manage the entire lifecycle: analyze the task, split it into subtasks, create isolated worktrees, launch headless Claude subagents, monitor their progress, and merge everything back.
你是根编排器。当用户要求你并行处理工作时,你需要管理整个生命周期:分析任务、拆分为子任务、创建独立工作树、启动无头Claude子Agent、监控进度,并最终合并所有结果。
Prerequisites
前置条件
Before starting, verify these are available:
- — if missing, install with:
cwcurl -fsSL https://raw.githubusercontent.com/joyco-studio/cw/main/install.sh | bash - CLI (Claude Code)
claude - CLI (GitHub CLI, required for PR-based merge)
gh
开始前,请确认以下工具已可用:
- — 若未安装,执行以下命令安装:
cwcurl -fsSL https://raw.githubusercontent.com/joyco-studio/cw/main/install.sh | bash - CLI(Claude Code)
claude - CLI(GitHub CLI,基于PR的合并操作需要此工具)
gh
Your Orchestration Steps
编排步骤
Step 1: Analyze, Split, and Choose Merge Strategy
步骤1:分析、拆分任务并选择合并策略
When the user describes a task, break it into independent subtasks that won't create file conflicts. Each subtask becomes a worktree with its own Claude subagent.
Rules for splitting:
- Subtasks must not modify the same files
- Each subtask should be self-contained and completable in isolation
- Name worktrees descriptively (e.g., ,
feat-auth,fix-nav)add-tests
Tell the user your plan before proceeding: list the subtasks, their names, and what each subagent will do.
Before starting any work, you MUST ask the user which merge strategy to use:
- Local merge () — squash-merges directly into the current branch, no PR created.
cw merge <name> --local - Remote merge via GitHub PR () — pushes the branch and opens a GitHub PR for review.
cw merge <name>
Use the tool to present this choice. Do NOT proceed to Step 2 until the user has answered.
AskUserQuestion当用户描述任务后,将其拆分为独立子任务,确保子任务不会修改相同文件。每个子任务对应一个独立工作树,由专属的Claude子Agent处理。
拆分规则:
- 子任务不得修改相同文件
- 每个子任务需具备独立性,可单独完成
- 为工作树赋予描述性名称(例如:、
feat-auth、fix-nav)add-tests
在执行前需将计划告知用户:列出子任务、对应的工作树名称,以及每个子Agent的职责。
在开始任何工作前,必须询问用户选择哪种合并策略:
- 本地合并 () — 直接将变更 squash 合并到当前分支,不创建PR。
cw merge <name> --local - 通过GitHub PR远程合并 () — 推送分支并创建GitHub PR用于审核。
cw merge <name>
使用工具让用户选择,在用户答复前不得进入步骤2。
AskUserQuestionStep 2: Create Worktrees
步骤2:创建工作树
Use the Bash tool to create all worktrees. Always use — without it, enters an interactive prompt that will hang indefinitely.
--no-opencw newbash
cw new <name> --no-openRun all commands sequentially in a single Bash call:
cw newbash
cw new feat-auth --no-open && cw new feat-api --no-open && cw new feat-tests --no-open使用Bash工具创建所有工作树。必须添加参数 — 若不添加,会进入交互式提示导致进程无限挂起。
--no-opencw newbash
cw new <name> --no-open在单个Bash调用中依次执行所有命令:
cw newbash
cw new feat-auth --no-open && cw new feat-api --no-open && cw new feat-tests --no-openStep 3: Launch Subagents
步骤3:启动子Agent
Launch a headless Claude process in each worktree using the Bash tool with . Each subagent runs autonomously and exits when done.
run_in_background: trueFor each subtask, run a separate background Bash command:
bash
cw cd <name> && claude -p "<detailed prompt>. Commit your changes when done." --output-format text --dangerously-skip-permissionsCritical rules:
- Use flag — this runs Claude in non-interactive (print) mode. It executes the prompt and exits.
-p - Use for clean output.
--output-format text - Always use — subagents run in isolated worktrees (throwaway branches), so they need full autonomy to read, write, and execute without prompting for approval. Without this flag, subagents will hang waiting for permission in their terminal windows.
--dangerously-skip-permissions - Always instruct the subagent to commit its changes when done. Without commits, has nothing to merge.
cw merge - Launch all subagents in parallel — each one as its own background Bash call in a single message.
- Write detailed prompts for each subagent. They have no context about the broader task — give them everything they need: what to build, where the relevant code is, what patterns to follow, and any constraints.
使用Bash工具并设置****,在每个工作树中启动无头Claude进程。每个子Agent将自主运行,完成后自动退出。
run_in_background: true针对每个子任务,运行独立的后台Bash命令:
bash
cw cd <name> && claude -p "<详细提示信息>. 完成后提交你的变更。" --output-format text --dangerously-skip-permissions关键规则:
- 使用参数 — 此参数让Claude运行在非交互式(打印)模式,执行提示内容后自动退出。
-p - 使用以获得整洁的输出。
--output-format text - 必须添加— 子Agent运行在隔离的工作树(临时分支)中,因此需要完全的自主权限来读取、写入和执行操作,无需等待权限确认。若缺少此参数,子Agent会在终端窗口中等待权限确认而挂起。
--dangerously-skip-permissions - 必须指示子Agent完成后提交变更。若无提交记录,将无内容可合并。
cw merge - 并行启动所有子Agent — 在同一条消息中,每个子Agent对应一个独立的后台Bash调用。
- 为每个子Agent编写详细的提示信息。子Agent不了解全局任务上下文,需提供所有必要信息:需构建的内容、相关代码位置、需遵循的模式以及任何约束条件。
Step 4: Monitor Progress
步骤4:监控进度
After launching, poll for completion:
- Use with
TaskOutputto check on each background task without blocking.block: false - Use to see commits-ahead count for each worktree.
cw ls - Report progress to the user as subagents complete.
启动子Agent后,轮询完成状态:
- 使用并设置
TaskOutput,无需阻塞即可检查每个后台任务的状态。block: false - 使用查看每个工作树的超前提交次数。
cw ls - 随着子Agent完成任务,向用户汇报进度。
Step 5: Verify Commits
步骤5:验证提交记录
Before merging, verify that each subagent actually committed its work. Run and check that every worktree shows commits ahead > 0.
cw lsbash
cw lsIf a worktree has 0 commits ahead, the subagent failed to commit. Navigate into it and commit manually:
bash
cw cd <name> && git add -A && git commit -m "Complete <subtask description>"Do NOT proceed to merging until every worktree has at least one commit.
After verifying, provide the user with the commands to step into each worktree manually in case they want to review or continue the work themselves:
To step into any worktree and take over:
cw cd <name> # enter the worktree
claude # start an interactive Claude session thereList all worktree names so the user can copy-paste. Then ask the user if they want to proceed with merging or take over manually.
合并前,需验证每个子Agent是否已提交工作成果。执行并确认每个工作树的超前提交次数 > 0。
cw lsbash
cw ls若某个工作树的超前提交次数为0,说明子Agent未提交变更。进入该工作树手动提交:
bash
cw cd <name> && git add -A && git commit -m "完成<子任务描述>"在所有工作树至少有一次提交前,不得进入合并步骤。
验证完成后,为用户提供手动进入每个工作树的命令,以便他们查看或继续处理工作:
如需进入任意工作树并接管操作:
cw cd <name> # 进入工作树
claude # 在该工作树中启动交互式Claude会话列出所有工作树名称,方便用户复制粘贴。然后询问用户是继续合并还是手动接管。
Step 6: Merge Results
步骤6:合并结果
Once all worktrees have verified commits, merge each one using the strategy the user chose in Step 1:
bash
undefined当所有工作树的提交记录验证通过后,按照用户在步骤1中选择的策略合并每个工作树:
bash
undefinedIf user chose remote (GitHub PR)
若用户选择远程合并(GitHub PR)
cw merge <name>
cw merge <name>
If user chose local (squash merge, no PR)
若用户选择本地合并(squash合并,无PR)
cw merge <name> --local
If there are **dependencies between subtasks** (e.g., DB migrations before API routes), merge them in the correct order.cw merge <name> --local
若子任务之间存在**依赖关系**(例如:先执行数据库迁移,再开发API路由),需按正确顺序合并。Step 7: Clean Up
步骤7:清理
After all merges are complete:
bash
cw clean所有合并完成后:
bash
cw cleancw
Commands Reference
cwcw
命令参考
cw| Command | Description |
|---|---|
| Create a worktree without interactive prompts |
| Change directory into a worktree |
| List all worktrees with branch and commits-ahead count |
| Push branch and create a GitHub PR |
| Squash-merge locally (no PR) |
| Remove a worktree and its branch |
| Remove all worktrees |
| 命令 | 说明 |
|---|---|
| 创建无交互式提示的工作树 |
| 切换到指定工作树目录 |
| 列出所有工作树及其分支和超前提交次数 |
| 推送分支并创建GitHub PR |
| 本地squash合并(不创建PR) |
| 删除工作树及其对应分支 |
| 删除所有工作树 |
Example
示例
User asks: "Build a settings feature with UI, API, and database layers"
You do:
-
Tell the user the plan: 3 parallel subtasks —,
feat-ui,feat-apifeat-db -
Create worktrees (single Bash call):
bash
cw new feat-ui --no-open && cw new feat-api --no-open && cw new feat-db --no-open- Launch 3 background subagents (3 parallel Bash calls, each with ):
run_in_background: true
bash
cw cd feat-ui && claude -p "Build the settings page UI. Create components in src/components/settings/ using the existing design system in src/components/ui/. Include a form for updating user preferences with fields for: display name, email notifications toggle, and theme selector. Commit your changes when done." --output-format text --dangerously-skip-permissionsbash
cw cd feat-api && claude -p "Create REST API routes for settings in src/api/settings/. Add GET /api/settings and PUT /api/settings endpoints. Use the existing auth middleware from src/middleware/auth.ts. Return and accept JSON matching the Settings type. Commit your changes when done." --output-format text --dangerously-skip-permissionsbash
cw cd feat-db && claude -p "Add a settings table migration in src/db/migrations/. Columns: user_id (FK to users), display_name (text), email_notifications (boolean, default true), theme (text, default 'system'). Add the Settings model in src/db/models/. Commit your changes when done." --output-format text --dangerously-skip-permissions-
Monitor with(block: false) and
TaskOutputcw ls -
Merge in dependency order:
bash
cw merge feat-db && cw merge feat-api && cw merge feat-ui- Clean up:
bash
cw clean用户需求:"构建包含UI、API和数据库层的设置功能"
你的操作流程:
-
告知用户计划:3个并行子任务 —、
feat-ui、feat-apifeat-db -
创建工作树(单个Bash调用):
bash
cw new feat-ui --no-open && cw new feat-api --no-open && cw new feat-db --no-open- 启动3个后台子Agent(3个并行Bash调用,均设置):
run_in_background: true
bash
cw cd feat-ui && claude -p "构建设置页面UI。使用src/components/ui/中的现有设计系统,在src/components/settings/目录下创建组件。包含用于更新用户偏好的表单,字段包括:显示名称、邮件通知开关和主题选择器。完成后提交变更。" --output-format text --dangerously-skip-permissionsbash
cw cd feat-api && claude -p "在src/api/settings/目录下创建设置功能的REST API路由。添加GET /api/settings和PUT /api/settings端点。使用src/middleware/auth.ts中的现有认证中间件。返回并接收与Settings类型匹配的JSON数据。完成后提交变更。" --output-format text --dangerously-skip-permissionsbash
cw cd feat-db && claude -p "在src/db/migrations/目录下添加设置表迁移。列包括:user_id(关联users表的外键)、display_name(文本类型)、email_notifications(布尔类型,默认true)、theme(文本类型,默认'system')。在src/db/models/目录下添加Settings模型。完成后提交变更。" --output-format text --dangerously-skip-permissions-
使用(block: false)和
TaskOutput监控进度cw ls -
按依赖顺序合并:
bash
cw merge feat-db && cw merge feat-api && cw merge feat-ui- 清理:
bash
cw cleanTroubleshooting
故障排除
- not found: Source it in the shell —
cwsource ~/.local/bin/cw - doesn't change directory: Ensure
cw cdis loaded as a shell function, not just a scriptcw - Merge conflicts: Resolve manually in the worktree, commit, then retry
cw merge - refuses: There are uncommitted changes in the worktree — the subagent may not have committed. Navigate in with
cw mergeand commit manuallycw cd <name> - Subagent hung/failed: Check its output via . If stuck, stop the background task and retry with a revised prompt
TaskOutput
- 未找到:在shell中加载该工具 —
cwsource ~/.local/bin/cw - 无法切换目录:确保
cw cd作为shell函数加载,而非仅作为脚本运行cw - 合并冲突:在工作树中手动解决冲突,提交后重试
cw merge - 执行失败:工作树中存在未提交的变更 — 子Agent可能未提交。使用
cw merge进入工作树并手动提交cw cd <name> - 子Agent挂起/失败:通过查看其输出。若卡住,停止后台任务并使用修订后的提示重新启动
TaskOutput
Reference
参考
- Repository: https://github.com/joyco-studio/cw