Skip to content

feat: Worktree creation and lifecycle missing from coordinator/spawn flow #525

Closed

Description

@joniba

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/dev

Agent 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 prune

Decision logic:

  • Single agent -> git checkout -b (current behavior, fine)
  • Multiple agents in parallel -> git worktree add per agent (new)
  • Ralph batch work -> worktrees (new)

Files to change:

  1. packages/squad-sdk/src/platform/ralph-commands.ts — add createWorktree / removeWorktree commands
  2. .squad-templates/squad.agent.md — update spawn flow to create worktrees for parallel work, add WORKTREE_PATH to spawn prompts
  3. Create .squad-templates/issue-lifecycle.md — the missing template, with worktree-aware lifecycle
  4. .copilot/skills/git-workflow/SKILL.md — make worktree the default for parallel work, not a separate section
  5. test/ — add tests for worktree creation/cleanup lifecycle

Additional context

  • The git-workflow skill already documents the correct git worktree add commands (L82-84) and cleanup (L120-130) — the knowledge exists, it just isn't wired into the coordinator flow.
  • The merge=union .gitattributes strategy 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

  1. bradygaster commented on Mar 22, 2026

    @bradygaster
    Collaborator

    Sub-Issues Created

    Decomposition approved and filed as sub-issues:

    # Issue Owner Scope
    1 #527 — Create missing issue-lifecycle.md skill document Procedures Quick-win docs
    2 #528 — Add worktree branch creation variant to ralph-commands.ts EECOM Runtime
    3 #529 — Add worktree creation to coordinator spawn flow Procedures + EECOM Prompt + Runtime
    4 #530 — Implement post-merge worktree cleanup lifecycle EECOM Runtime
    5 #531 — Architecture decision: worktree vs checkout heuristic Flight Architecture

    Recommended order: #531 (arch decision) → #527 (docs quick-win, parallel) → #528 (ralph-commands) → #529 (coordinator spawn) → #530 (cleanup lifecycle)

    — Flight 🚀

  2. added a commit that references this issue on Mar 26, 2026
    9d2e81d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions