worktree-fleet
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWorktree Fleet
Worktree Fleet
A skill for running N independent agents in parallel, each isolated in its own git worktree on its own branch. Independence is validated before anything spawns — if two workers declare overlapping , the skill refuses with a clear conflict message.
target_files这是一个可并行运行N个独立Agent的Skill,每个Agent都在独立的git worktree和git分支中隔离运行。在启动任何进程前会先验证独立性——如果两个工作进程声明的存在重叠,该Skill会直接拒绝执行并给出明确的冲突提示。
target_filesDecision tree — which fleet?
决策树——选择哪种集群?
You want to run multiple agents in parallel. Which fleet?
1. Are the tasks independent (no shared files, no shared state)?
YES → worktree-fleet ← YOU ARE HERE
NO → continue
2. Does the work need iteration with a reviewer making accept/iterate decisions?
YES → iterative-fleet
NO → continue
3. Is the work a one-shot DAG (each agent runs to completion, dependencies via depends_on)?
YES → dag-fleet
NO → continue
4. None of the above?
→ You're the orchestrator. Open multiple Claude Code sessions.你想要并行运行多个Agent,该选哪种集群?
1. 任务是否独立(无共享文件、无共享状态)?
是 → worktree-fleet ← 当前选择
否 → 继续
2. 工作是否需要带审核循环的迭代(审核者可决定接受/迭代)?
是 → iterative-fleet
否 → 继续
3. 工作是否是一次性的DAG顺序任务(每个Agent运行至完成,通过depends_on定义依赖)?
是 → dag-fleet
否 → 继续
4. 以上都不符合?
→ 由你自行编排,打开多个Claude Code会话即可。When to use THIS skill
何时使用本Skill
- Tasks touch non-overlapping files (different modules, different docs, etc.)
- You want merge-safe isolation — each worker on its own branch, no mid-flight conflicts possible
- The merge decision is yours — after workers complete, you choose merge order / strategy
- You want independent branches in git that you can inspect, cherry-pick, or discard
- 任务涉及互不重叠的文件(如不同模块、不同文档等)
- 你需要可安全合并的隔离环境——每个工作进程在独立分支上,不会出现运行中的冲突
- 合并决策由你掌控——工作进程完成后,你可以选择合并顺序和策略
- 你需要git中的独立分支,可自行检查、挑选或丢弃这些分支的更改
When NOT to use this skill
何时不使用本Skill
- Workers need to coordinate or read each other's output → with
dag-fleetdepends_on - Tasks overlap files (even partially) → fix the task split first, then come back
- You want headless workers + reviewer-in-loop →
iterative-fleet - Work fits in the current conversation → use Claude Code's built-in Agent tool directly
- 工作进程需要协调或读取彼此的输出 → 使用带的
depends_ondag-fleet - 任务涉及重叠文件(即使部分重叠)→ 先拆分任务,再使用本工具
- 你需要无头工作进程+审核循环 → 使用
iterative-fleet - 工作内容可在当前对话中完成 → 直接使用Claude Code内置的Agent工具
fleet.json schema
fleet.json schema
json
{
"fleet_name": "refactor-utils",
"type": "worktree",
"config": {
"max_concurrent": 4,
"model": "sonnet",
"fallback_model": "haiku"
},
"workers": [
{
"id": "rename-foo",
"task": "Rename foo() to baz() in src/utils/foo.ts and all callers",
"target_files": ["src/utils/foo.ts", "src/**/*.test.ts"],
"branch": "rename-foo-to-baz",
"type": "code-run",
"max_turns": 30,
"max_budget_usd": 2.0
}
]
}New fields vs dag-fleet:
- (required per worker) — list of file globs this worker will touch. Overlap across workers = launch refuses with exit 2.
target_files - (required per worker) — git branch name for this worker's worktree. Must not already exist.
branch
Worker type override (Claude only): Worktree workers always need Bash for . If you set to , , or , launch.sh will automatically override to with a warning. The worktree itself provides isolation — Bash restrictions are unnecessary here. This override does not apply to codex workers (codex uses sandbox modes).
git committyperead-onlywritereviewercode-runProvider support: Set at config or per-worker level to use OpenAI Codex CLI instead of Claude. Codex workers use (needed for git commit). See dag-fleet SKILL.md for full codex provider documentation (model aliases, reasoning_effort, limitations).
"provider": "codex"--sandbox workspace-writeDefault max_turns is 100 (not 50 like dag-fleet). Worktree workers typically edit, test, and commit — they need headroom.
json
{
"fleet_name": "refactor-utils",
"type": "worktree",
"config": {
"max_concurrent": 4,
"model": "sonnet",
"fallback_model": "haiku"
},
"workers": [
{
"id": "rename-foo",
"task": "Rename foo() to baz() in src/utils/foo.ts and all callers",
"target_files": ["src/utils/foo.ts", "src/**/*.test.ts"],
"branch": "rename-foo-to-baz",
"type": "code-run",
"max_turns": 30,
"max_budget_usd": 2.0
}
]
}与dag-fleet相比新增的字段:
- (每个工作进程必填)——该工作进程会修改的文件通配符列表。如果不同工作进程的此列表存在重叠,启动时会直接拒绝并以状态码2退出。
target_files - (每个工作进程必填)——该工作进程的worktree对应的git分支名称,该分支不能已存在。
branch
Worker类型覆盖(仅Claude): Worktree工作进程需要Bash来执行。如果你将设置为、或,launch.sh会自动将其覆盖为并给出警告。worktree本身已提供隔离——此处无需Bash限制。此覆盖不适用于codex工作进程(codex使用沙箱模式)。
git committyperead-onlywritereviewercode-run供应商支持: 在config或单个工作进程级别设置,即可使用OpenAI Codex CLI替代Claude。Codex工作进程使用(用于git commit)。关于codex供应商的完整文档(模型别名、推理能力、限制)请查看dag-fleet的SKILL.md。
"provider": "codex"--sandbox workspace-write默认max_turns为100(不同于dag-fleet的50)。Worktree工作进程通常需要编辑、测试和提交——需要更多的操作次数上限。
Available scripts
可用脚本
| Script | When to call | Args |
|---|---|---|
| Validate independence, create worktrees, spawn workers in tmux | |
| Per-worktree progress, cost, completion state | |
| Print merge plan (files changed, line counts) — no auto-merge | |
| Remove git worktrees, requires --force | |
| 脚本 | 调用时机 | 参数 |
|---|---|---|
| 验证独立性,创建worktree,在tmux中启动工作进程 | |
| 查看每个worktree的进度、成本、完成状态 | |
| 打印合并计划(修改的文件、行数统计)——不会自动合并 | |
| 删除git worktree,需传入--force参数 | |
Launch procedure
启动流程
- Set to an absolute path.
FLEET_ROOT - Create with the schema above.
$FLEET_ROOT/fleet.json - For each worker, create . Include:
$FLEET_ROOT/workers/{id}/prompt.mdSave ALL output to $FLEET_ROOT/workers/{id}/output/ — use absolute paths. - Run:
bash ${CLAUDE_SKILL_DIR}/scripts/launch.sh $FLEET_ROOT - validates independence without creating worktrees or spawning workers.
--dry-run - ALWAYS tell the user the exact status command so they can monitor manually:
This is mandatory after every launch. The user must be able to check status without asking you.
bash ${CLAUDE_SKILL_DIR}/scripts/status.sh <fleet-name-or-root>
IMPORTANT: Worker prompts MUST instruct the worker to commit its changes before exiting:
When you are done, commit your changes on the current branch with a descriptive message.Without this, changes stay as unstaged modifications and cannot be merged via .
git merge- 将设置为绝对路径。
FLEET_ROOT - 在下创建
$FLEET_ROOT,格式遵循上述schema。fleet.json - 为每个工作进程创建,并包含以下内容:
$FLEET_ROOT/workers/{id}/prompt.md将所有输出保存至 $FLEET_ROOT/workers/{id}/output/ —— 使用绝对路径。 - 运行:
bash ${CLAUDE_SKILL_DIR}/scripts/launch.sh $FLEET_ROOT - 参数可验证独立性,但不会创建worktree或启动工作进程。
--dry-run - 必须告知用户确切的状态查询命令,以便他们手动监控:
每次启动后都必须执行此操作,用户无需询问即可自行检查状态。
bash ${CLAUDE_SKILL_DIR}/scripts/status.sh <fleet-name-or-root>
重要提示: 工作进程的提示必须包含在退出前提交更改的指令:
完成工作后,请在当前分支上提交更改并添加描述性的提交信息。如果没有此指令,更改会保持为未暂存状态,无法通过进行合并。
git mergeAfter workers complete
工作进程完成后
- Run to see what each branch changed.
merge.sh - Decide your merge strategy (in-order, cherry-pick, etc.).
- Merge manually — the skill does NOT auto-merge.
- Run to remove worktrees.
cleanup.sh --force
- 运行查看每个分支的更改内容。
merge.sh - 决定你的合并策略(按顺序合并、挑选提交等)。
- 手动合并——本Skill不会自动合并。
- 运行删除worktree。
cleanup.sh --force
Rationalizations to reject
需拒绝的不合理请求
| Agent says | Rebuttal |
|---|---|
| "The tasks overlap slightly but I can manage" | Overlapping target_files = reject. No exceptions. Fix the task split first. If you think you can manage it, you're wrong — merge conflicts in parallel worktrees are unrecoverable. |
"I'll skip | Then dry-run will be fast. Run it. The independence validator catches things you didn't think of (glob overlap, bidirectional fnmatch). |
| "Two workers both need the config file, but in different sections" | Same file = overlap. The validator doesn't know about "sections." Split the config change into a separate sequential step, or have one worker own it. |
| "I'll auto-merge since the branches are clean" | Never auto-merge. Run |
| "I can skip cleanup — the worktrees aren't hurting anything" | Worktrees hold branch locks. Stale worktrees block future branch creation and waste disk. Run |
| Agent的说法 | 反驳理由 |
|---|---|
| "任务只是略有重叠,但我可以处理" | 只要 |
| "我已经仔细编写了fleet.json,可以跳过--dry-run吗" | Dry-run速度很快,一定要运行。独立性验证器能发现你没考虑到的问题(如通配符重叠、双向fnmatch匹配)。 |
| "两个工作进程都需要修改配置文件,但修改的是不同部分" | 同一文件即视为重叠。验证器无法识别“不同部分”。将配置文件的修改拆分为单独的顺序步骤,或由一个工作进程负责全部修改。 |
| "分支很干净,我可以自动合并" | 绝对不要自动合并。运行 |
| "我可以不清理worktree——它们不会有什么影响" | Worktree会持有分支锁。残留的worktree会阻止未来创建分支,还会浪费磁盘空间。完成工作后务必运行 |
STRICT RULES
严格规则
- Never skip validation for new fleet configurations.
--dry-run - Never merge without reviewing output first.
merge.sh - requires
cleanup.sh— no accidental removals.--force - Worktrees persist until you explicitly clean them up. They will not auto-remove.
$ARGUMENTS
- 对于新的集群配置,绝对不能跳过验证。
--dry-run - 绝对不能在未查看输出的情况下进行合并。
merge.sh - 必须传入
cleanup.sh参数——防止误删除。--force - Worktree会一直保留,直到你显式清理,不会自动删除。
$ARGUMENTS