@@ -47,24 +47,29 @@ review cleaner.
4747
4848## Step 2 — Prepare the Branch
4949
50- Sync main and create a working branch before any implementation begins.
50+ Sync main before any implementation begins.
5151
5252``` bash
5353git checkout main
5454git pull origin main --tags
55+ ```
56+
57+ ** If NOT using worktree isolation** (orchestrator implements directly or dispatches
58+ a single non-isolated agent), create a working branch:
59+
60+ ``` bash
5561git checkout -b < branch-name>
5662```
5763
58- ** Branch naming:**
64+ ** If using worktree isolation** , skip branch creation — each worktree agent gets
65+ its own isolated branch automatically. See Worktree Isolation below.
66+
67+ ** Branch naming** (for manually created branches):
5968- ` feat/<short-description> ` — feature-implementation items
6069- ` fix/<short-description> ` — bug-fix items
6170- ` fix/<grouped-description> ` — batch of related bug fixes
6271- ` chore/<short-description> ` — tech debt, refactoring, observations
6372
64- For autonomous batch work with unrelated items, create separate branches. Use
65- worktree isolation (` isolation: "worktree" ` on the Agent tool) when dispatching
66- multiple implementation agents in parallel to prevent file conflicts.
67-
6873---
6974
7075## Step 3 — Queue Phase: Planning
@@ -117,7 +122,26 @@ UUID inclusion). The key decisions at this step are:
117122- ** Multiple child tasks, dependent:** dispatch sequentially — wait for each agent
118123 to return before dispatching the next.
119124
120- ** After implementation completes:**
125+ ** After implementation agents return:**
126+
127+ If agents used worktree isolation, the Agent tool result includes the ** worktree
128+ path** and ** branch name** . Capture both — they are needed for review and PR
129+ creation. Record them alongside the MCP item ID:
130+
131+ ```
132+ | Item UUID | Worktree Path | Branch | Changed Files |
133+ |-----------|---------------|--------|---------------|
134+ | <uuid> | <path> | <branch> | <file list> |
135+ ```
136+
137+ To get the changed files list for a worktree, run:
138+ ``` bash
139+ git -C < worktree-path> diff main --name-only
140+ ```
141+
142+ ** Post-implementation steps** (run in the worktree if isolated, or on the working
143+ branch if not):
144+
1211451 . Run the ` /simplify ` skill on the changed code to check for reuse, quality, and
122146 efficiency — this is a cleanup pass before review, not a review itself
1231472 . ** If ` /simplify ` made changes** , write or update tests to cover them. The simplify
@@ -138,11 +162,24 @@ UUID inclusion). The key decisions at this step are:
138162Dispatch a ** separate** review agent. The agent that implemented the code must not
139163review its own work.
140164
165+ ** If the implementation used worktree isolation** , the review agent must operate
166+ in the same worktree so it reads the correct files and runs tests against the
167+ actual changes. Include in the review agent prompt:
168+
169+ - The ** worktree path** (from the implementation agent's return)
170+ - The ** branch name** in the worktree
171+ - The ** changed files list** (from ` git -C <worktree-path> diff main --name-only ` )
172+ - Instruction: "Run all commands and read all files from within the worktree at
173+ ` <worktree-path> ` . Do NOT read files from the main working directory."
174+
175+ ** If NOT using worktree isolation** , the review agent reads from the current
176+ working branch as normal.
177+
141178The review agent:
1421791 . Reads the review-quality skill
1431802 . Uses ` get_context(itemId=...) ` to load the item's notes and review-phase requirements
144- 3 . Reads the changed files directly
145- 4 . Runs the test suite
181+ 3 . Reads the changed files (from the worktree path if isolated, or the working branch)
182+ 4 . Runs the test suite (from the worktree if isolated)
1461835 . Evaluates plan alignment, test quality, and simplification
1471846 . Fills the review-phase notes per ` guidancePointer ` with a verdict
148185
@@ -163,6 +200,15 @@ from. Automatically retrying hides these signals.
163200
164201After review passes, commit the changes and create a PR.
165202
203+ ** If using worktree isolation** , all commands in this step run from the worktree:
204+ ``` bash
205+ git -C < worktree-path> add < specific-files>
206+ git -C < worktree-path> commit ...
207+ git -C < worktree-path> push origin < worktree-branch>
208+ ```
209+
210+ ** If NOT using worktree isolation** , run from the working branch as normal.
211+
166212### Commit
167213
168214Stage only the files related to the implementation. Do not stage unrelated changes
@@ -236,8 +282,11 @@ When processing multiple items autonomously:
236282 need separate branches
2372832 . ** Parallel execution** — use worktree isolation for independent work streams.
238284 Sequential execution for items with dependency edges between them.
239- 3 . ** Per-group pipeline** — each group goes through Steps 2-6 independently
240- 4 . ** Report at the end** — summarize all PRs created, any items that couldn't be
285+ 3 . ** Per-item pipeline** — each worktree goes through Steps 4-6 independently:
286+ implementation → capture worktree metadata → simplify → review (in worktree) → PR
287+ 4 . ** Track all worktrees** — maintain a table mapping item UUID → worktree path →
288+ branch → status (implementing / reviewing / PR created / failed)
289+ 5 . ** Report at the end** — summarize all PRs created, any items that couldn't be
241290 processed, and any review failures that need user attention
242291
243292If any item in the batch hits a review failure, continue processing other items
@@ -247,11 +296,23 @@ and report all failures together at the end.
247296
248297## Worktree Isolation
249298
250- When dispatching multiple implementation agents in parallel, use ` isolation: "worktree" `
251- on the Agent tool. Each agent gets an isolated copy of the repository, preventing file
252- conflicts, accidental cross-cutting changes, and test baseline contamination.
299+ Use ` isolation: "worktree" ` on the Agent tool to give each agent an isolated copy
300+ of the repository. This prevents file conflicts, cross-cutting changes, test
301+ baseline contamination, and — critically — ensures changes are committed to a
302+ real branch that survives the agent's lifecycle.
303+
304+ ** When to use worktrees:**
305+ - Parallel dispatch of multiple implementation agents (prevents file conflicts)
306+ - Any implementation dispatch where you need the changes on a reviewable branch
307+ - When you want the implementation agent to commit and push independently
308+
309+ ** When NOT to use worktrees:**
310+ - Tasks that depend on each other's file changes (use sequential dispatch instead)
311+ - Pure MCP operations with no file modifications (e.g., materialization subagents)
312+ - Orchestrator implementing directly (already on a working branch)
313+
314+ ### Dispatch pattern
253315
254- ** Dispatch pattern:**
255316```
256317Agent(
257318 prompt="...",
@@ -261,26 +322,54 @@ Agent(
261322)
262323```
263324
264- ** Scoping rules — include in every parallel subagent prompt:**
325+ ** Scoping rules — include in every worktree subagent prompt:**
265326- "Only modify files directly related to your task"
266327- "Do not bump versions, modify shared config, or edit files outside your scope"
328+ - "Commit your changes before returning"
267329- Cross-cutting changes (version bumps, shared config) are handled by the
268330 orchestrator after all agents return
269331
270- ** Validation after agents return:**
271- 1 . Review each worktree's changes — the Agent tool returns the worktree path and
272- branch when changes are made
273- 2 . Spot-check at least 2 diffs for insertion errors, scope violations, or unintended
274- modifications
275- 3 . Merge worktree branches sequentially into the working branch, resolving any conflicts
276- 4 . Run the full test suite once after all merges to catch integration issues
277- 5 . Worktrees with no changes are automatically cleaned up; merged worktrees should be
278- removed after successful integration
332+ ### Worktree lifecycle
279333
280- ** When NOT to use worktrees:**
281- - Single-agent dispatch (no isolation needed)
282- - Tasks that depend on each other's file changes (use sequential dispatch instead)
283- - Pure MCP operations with no file modifications (e.g., materialization subagents)
334+ The worktree branch is the PR branch. Review and PR creation happen on that
335+ branch — do NOT merge worktree branches back before review.
336+
337+ ```
338+ 1. Orchestrator dispatches agent with isolation: "worktree"
339+ 2. Agent works in isolated worktree, commits to worktree branch
340+ 3. Agent returns → result includes worktree path and branch name
341+ 4. Orchestrator captures worktree metadata (path, branch, changed files)
342+ 5. Orchestrator spot-checks diffs: git -C <worktree-path> diff main --stat
343+ 6. Orchestrator runs /simplify in the worktree (or dispatches agent to do so)
344+ 7. Review agent dispatched INTO the worktree (reads files and runs tests there)
345+ 8. PR created from the worktree branch
346+ 9. Worktrees with no changes are automatically cleaned up
347+ ```
348+
349+ ### Capturing worktree metadata
350+
351+ When an agent returns from worktree isolation, the Agent tool result includes:
352+ - ** Worktree path** — the directory where the isolated copy lives
353+ - ** Branch name** — the git branch the agent committed to
354+
355+ Record these alongside the MCP item ID. You need them for:
356+ - Running ` git -C <path> diff main --name-only ` to get the changed files list
357+ - Pointing the review agent at the correct directory
358+ - Pushing the branch and creating the PR
359+
360+ ### Parallel worktree validation
361+
362+ When multiple agents return from parallel worktrees:
363+
364+ 1 . Capture each agent's worktree path and branch from the return metadata
365+ 2 . Spot-check at least 2 diffs for insertion errors, scope violations, or
366+ unintended modifications
367+ 3 . Run each worktree's test suite independently (or delegate to review agents)
368+ 4 . Each worktree branch gets its own PR — do not merge them together unless
369+ the items were intentionally grouped
370+
371+ If items were grouped into a single working branch (Step 2), merge reviewed
372+ worktree branches into that branch sequentially AFTER review passes for each.
284373
285374---
286375
0 commit comments