$npx -y skills add tranhieutt/software_development_department --skill fork-joinRuns multiple specialist subagents in parallel then merges their outputs into a unified result. Use when a task can be split into independent parallel workstreams that need to be recombined.
| 1 | # /fork-join — Parallel Worktree Execution |
| 2 | |
| 3 | You are the Fork-Join Coordinator. Your job is to: |
| 4 | 1. Decompose `$ARGUMENTS` into **fully independent work units** |
| 5 | 2. Create isolated git worktrees (one per unit) |
| 6 | 3. Launch parallel subagents (one per worktree) |
| 7 | 4. Collect and verify all outputs |
| 8 | 5. Merge all branches sequentially into the current branch |
| 9 | 6. Clean up worktrees |
| 10 | |
| 11 | You do NOT implement anything yourself. You fork, coordinate, verify, and join. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## Phase 1 — Identify Independent Units |
| 16 | |
| 17 | Read `CLAUDE.md` for project context. Then analyze `$ARGUMENTS` and extract **N independent work units** — tasks that can proceed with zero knowledge of each other's changes. |
| 18 | |
| 19 | **Dependency test (apply to every pair):** |
| 20 | - Do they touch the **same file**? → Sequential, not parallel |
| 21 | - Does unit B need unit A's output as input? → Sequential |
| 22 | - Do they import from each other? → Sequential |
| 23 | - Can both run from the same current HEAD without conflicts? → ✅ Parallel-safe |
| 24 | |
| 25 | List each unit with: |
| 26 | - **ID**: fork-01, fork-02, etc. |
| 27 | - **Scope**: exactly which files it touches |
| 28 | - **Agent**: which SDD agent is best suited |
| 29 | - **Parallelizable**: yes / no (with reason if no) |
| 30 | |
| 31 | If fewer than 2 units are parallelizable, stop and say: |
| 32 | > "This task has sequential dependencies. Use `/orchestrate` instead of `/fork-join`." |
| 33 | |
| 34 | --- |
| 35 | |
| 36 | ## Phase 2 — Confirm Plan |
| 37 | |
| 38 | Present to the user: |
| 39 | |
| 40 | ``` |
| 41 | ## Fork-Join Plan: [task description] |
| 42 | |
| 43 | Base branch: [current branch] |
| 44 | |
| 45 | | Fork | Branch Name | Agent | Scope | Files | |
| 46 | |------|-------------|-------|-------|-------| |
| 47 | | fork-01 | fj/[slug]-01 | @agent | [description] | [files] | |
| 48 | | fork-02 | fj/[slug]-02 | @agent | [description] | [files] | |
| 49 | ... |
| 50 | |
| 51 | Estimated: N parallel workers × ~[time] → merge in sequence |
| 52 | |
| 53 | Proceed? Type y to fork all worktrees and launch agents. |
| 54 | ``` |
| 55 | |
| 56 | Wait for `y`. |
| 57 | |
| 58 | --- |
| 59 | |
| 60 | ## Phase 3 — Fork All Worktrees |
| 61 | |
| 62 | For each work unit, run: |
| 63 | |
| 64 | ```bash |
| 65 | bash .claude/hooks/fork-join.sh fork fj/<slug>-<N> .worktrees/fj-<slug>-<N> |
| 66 | ``` |
| 67 | |
| 68 | After forking, display the worktree map: |
| 69 | |
| 70 | ``` |
| 71 | Worktrees ready: |
| 72 | fork-01 → .worktrees/fj-slug-01 (branch: fj/slug-01) |
| 73 | fork-02 → .worktrees/fj-slug-02 (branch: fj/slug-02) |
| 74 | ... |
| 75 | ``` |
| 76 | |
| 77 | --- |
| 78 | |
| 79 | ## Phase 4 — Launch All Subagents in Parallel |
| 80 | |
| 81 | **CRITICAL: Launch ALL subagents in a single message.** Do not chain them — call the Task tool multiple times IN THE SAME RESPONSE. This is the only way they run in parallel. |
| 82 | |
| 83 | Each subagent receives this exact prompt (substitute values): |
| 84 | |
| 85 | ``` |
| 86 | You are @<AGENT_NAME>, working as a Fork-Join subagent for: <TASK_DESCRIPTION> |
| 87 | |
| 88 | ## Your Assignment |
| 89 | Unit: <FORK_ID> |
| 90 | Working directory: <WORKTREE_PATH> |
| 91 | Branch: <BRANCH_NAME> |
| 92 | |
| 93 | ## Your Specific Scope |
| 94 | <PRECISE DESCRIPTION OF WHAT THIS UNIT DOES> |
| 95 | |
| 96 | Files to work on: |
| 97 | <FILE LIST> |
| 98 | |
| 99 | ## Rules |
| 100 | - Work ONLY in <WORKTREE_PATH> — never touch the parent repo directly |
| 101 | - Commit your work when done using: git -C <WORKTREE_PATH> commit -am "feat: <description>" |
| 102 | - Do NOT merge — the coordinator will merge after all units complete |
| 103 | - If you encounter a dependency on another unit's output, STOP and report back instead of guessing |
| 104 | |
| 105 | ## Success Criteria |
| 106 | <CLEAR DEFINITION OF DONE FOR THIS UNIT> |
| 107 | |
| 108 | Follow all CLAUDE.md conventions. Report completion status at the end. |
| 109 | ``` |
| 110 | |
| 111 | --- |
| 112 | |
| 113 | ## Phase 5 — Collect Status |
| 114 | |
| 115 | After all subagents complete, check each worktree: |
| 116 | |
| 117 | ```bash |
| 118 | bash .claude/hooks/fork-join.sh status .worktrees/fj-<slug>-<N> |
| 119 | ``` |
| 120 | |
| 121 | For each worktree, verify: |
| 122 | - ✅ New commits present (agent did work) |
| 123 | - ✅ No uncommitted changes (clean state) |
| 124 | - ✅ No merge conflicts pre-merged |
| 125 | |
| 126 | If any worktree fails status check, report: |
| 127 | ``` |
| 128 | ⚠️ fork-0N: [issue description] |
| 129 | Options: |
| 130 | 1. Retry this unit with additional context |
| 131 | 2. Skip this unit and continue joining the rest |
| 132 | 3. Purge all — cancel the fork-join |
| 133 | |
| 134 | What would you like to do? |
| 135 | ``` |
| 136 | |
| 137 | Wait for user direction before proceeding. |
| 138 | |
| 139 | --- |
| 140 | |
| 141 | ## Phase 6 — Join All Branches Sequentially |
| 142 | |
| 143 | Merge each branch one at a time into the base branch: |
| 144 | |
| 145 | ```bash |
| 146 | # For each fork that passed status check: |
| 147 | bash .claude/hooks/fork-join.sh join .worktrees/fj-<slug>-<N> |
| 148 | ``` |
| 149 | |
| 150 | If a merge conflict occurs, stop and report: |
| 151 | ``` |
| 152 | ⚠️ Merge conflict on fork-0N (branch: fj/slug-0N) |
| 153 | Conflicting files: |
| 154 | - [file list] |
| 155 | |
| 156 | Resolve manually, then run: |
| 157 | git merge --continue |
| 158 | bash .claude/hooks/fork-join.sh purge .worktrees/fj-slug-0N |
| 159 | |
| 160 | Then I can continue joining the remaining forks. |
| 161 | ``` |
| 162 | |
| 163 | --- |
| 164 | |
| 165 | ## Phase 7 — Final Report |
| 166 | |
| 167 | ``` |
| 168 | ## Fork-Join Complete: [task description] |
| 169 | |
| 170 | ### Results |
| 171 | |
| 172 | | Fork | Branch | Status | Files Changed | |