Repository navigation
Description
Summary
Squad has full worktree detection (reading .squad/ state from worktrees) but the coordinator and spawn flow never creates worktrees for parallel agent work. Every branch-creation path hardcodes git checkout -b, which breaks parallel multi-agent execution — agents clobber each other's working directory.
What exists (worktree reading — works correctly)
| Component | File | What it does |
|---|---|---|
| SDK resolution | packages/squad-sdk/src/resolution.ts L61-82 |
resolveSquad() detects .git as file (worktree pointer), stops at boundary correctly |
| Coordinator session start | .squad-templates/squad.agent.md L100 |
Resolves team root via git rev-parse --show-toplevel, passes TEAM_ROOT to agents |
| Worktree Awareness section | .squad-templates/squad.agent.md L569-601 |
Documents two strategies (worktree-local vs main-checkout), TEAM_ROOT passing |
| Agent charters | packages/squad-sdk/src/roles/index.ts L193 |
All agents told to git rev-parse --show-toplevel — never assume CWD |
| Merge safety | .gitattributes |
merge=union on append-only .squad/ files |
| Consult mode | packages/squad-sdk/src/sharing/consult.ts L320-367 |
resolveGitExcludePath() uses git rev-parse to handle worktrees/submodules |
| Tests | test/resolution.test.ts L51-63 |
Two tests: .git worktree file boundary detection + .squad/ found in worktree |
What's missing (worktree creation/lifecycle — the gap)
| What exists | What's missing |
|---|---|
| Worktree detection (can I read state?) | Worktree creation (do I create one per agent?) |
Worktree state resolution (where is .squad/?) |
Worktree lifecycle (create before spawn, cleanup after merge) |
merge=union for clean merges |
Spawn template saying "work in your worktree, don't checkout -b" |
git-workflow skill documents git worktree add |
Nothing in the coordinator flow invokes it |
Specific locations that need changes
1. ralph-commands.ts — all 3 platform adapters hardcode checkout -b
File: packages/squad-sdk/src/platform/ralph-commands.ts
All three adapters (GitHub L71, ADO L92, Planner L50) have:
createBranch: 'git checkout main && git pull && git checkout -b {branchName}',No worktree variant exists. When Ralph spawns parallel agents, they all run checkout -b in the same working directory, clobbering each other.
2. issue-lifecycle.md — referenced but doesn't exist
File: .squad-templates/squad.agent.md L1097 and L1103
See `.squad/templates/issue-lifecycle.md` for the full spawn prompt ISSUE CONTEXT block...
This template is referenced twice but does not exist anywhere in the repo. The coordinator has no template for the issue-to-branch-to-PR flow, so it falls back to git checkout -b from the git-workflow skill's default single-issue workflow (L33).
3. git-workflow skill defaults to checkout -b
File: .copilot/skills/git-workflow/SKILL.md L29-34
The default "Workflow for Issue Work" uses git checkout -b. The worktree path (L62-130) is documented as a separate "Parallel Multi-Issue Work" section, but nothing in the coordinator flow triggers it — the coordinator reads the default workflow.
4. No WORKTREE_PATH in spawn prompts
File: .squad-templates/squad.agent.md L592-595
TEAM_ROOT is passed to agents (for reading .squad/ state), but there's no WORKTREE_PATH mechanism to tell an agent "you are in worktree X, stay there, don't switch branches."
5. No worktree lifecycle management
Nothing in the codebase:
- Creates worktrees before spawning parallel agents
- Passes the worktree path to the spawned agent
- Cleans up worktrees after PR merge
- Decides when to use worktrees vs
checkout -b(single agent = checkout, multiple = worktrees)
Proposed fix
Coordinator pre-spawn (parallel work):
# Create a worktree per agent/issue
git worktree add ./worktrees/squad-{issue} -b squad/{issue}-{slug} origin/devAgent spawn prompt addition:
WORKTREE_PATH: ./worktrees/squad-{issue}
"You are already on branch squad/{issue}-{slug}. Work only in {WORKTREE_PATH}."
Post-merge cleanup:
git worktree remove ./worktrees/squad-{issue}
git worktree pruneDecision logic:
- Single agent ->
git checkout -b(current behavior, fine) - Multiple agents in parallel ->
git worktree addper agent (new) - Ralph batch work -> worktrees (new)
Files to change:
packages/squad-sdk/src/platform/ralph-commands.ts— addcreateWorktree/removeWorktreecommands.squad-templates/squad.agent.md— update spawn flow to create worktrees for parallel work, addWORKTREE_PATHto spawn prompts- Create
.squad-templates/issue-lifecycle.md— the missing template, with worktree-aware lifecycle .copilot/skills/git-workflow/SKILL.md— make worktree the default for parallel work, not a separate sectiontest/— add tests for worktree creation/cleanup lifecycle
Additional context
- The git-workflow skill already documents the correct
git worktree addcommands (L82-84) and cleanup (L120-130) — the knowledge exists, it just isn't wired into the coordinator flow. - The
merge=union.gitattributesstrategy already handles the merge side correctly. - The SDK
resolution.ts+ tests already handle the read side correctly. - This is purely a coordinator/orchestration gap, not an SDK gap.
Activity
feat: add worktree creation/lifecycle to coordinator spawn flow (gith…
bradygaster commentedon Mar 22, 2026
Sub-Issues Created
Decomposition approved and filed as sub-issues:
issue-lifecycle.mdskill documentralph-commands.tsRecommended order: #531 (arch decision) → #527 (docs quick-win, parallel) → #528 (ralph-commands) → #529 (coordinator spawn) → #530 (cleanup lifecycle)
— Flight 🚀
chore(.squad): triage #525, backlog prioritization
chore(.squad): merge decisions, log #508/#525 fan-out
chore(.squad): merge decisions, log #508/#525 fan-out
docs(decisions): architecture decision for worktree heuristic (#531) (#…
feat(sdk): post-merge worktree cleanup lifecycle (#530) (#540)
docs(audit): VCS removal Phase 1 prep (#498) (#542)
chore(.squad): log session completion — #508/#525/#498 all done
docs(.squad): log mega-session — #508 complete, #525 complete, #498 a…
feat: consolidated CLI help, shell, and docs improvements (github#546)