Skip to content

feat: Multi-agent worktree support (gitWorkflow option)#153

Open
mmorris35 wants to merge 10 commits intomainfrom
feature/worktree-multi-agent
Open

feat: Multi-agent worktree support (gitWorkflow option)#153
mmorris35 wants to merge 10 commits intomainfrom
feature/worktree-multi-agent

Conversation

@mmorris35
Copy link
Owner

Summary

Adds gitWorkflow: "worktree" option to DevPlan that generates worktree-based git instructions instead of branch-checkout instructions. Enables true parallel execution where multiple Claude Code agents work simultaneously in separate directories.

What it does

When - **Git Workflow**: worktree is added to a PROJECT_BRIEF.md:

  • All git instruction blocks switch from branch-checkout to worktree-based commands
  • CLAUDE.md includes worktree layout, parallel execution guide, and conflict zone warnings
  • Executor agent gets a WORKTREE MODE ACTIVE addendum (no checkout, no merge, no lockfile edits)
  • New MCP tool devplan_setup_worktrees generates setup scripts and coordination docs

Layout

repo/                          ← main (stable, merge target)
repo-worktrees/
├── 1-1-core-module/           ← Agent A
├── 2-1-data-parser/           ← Agent B
└── 3-1-api-layer/             ← Agent C (all parallel!)

Implementation

  • models.ts: Added gitWorkflow: z.enum(["branch", "worktree"]).default("branch")
  • generators.ts: GitInstructions abstraction with branch/worktree implementations; all git instruction sites (task headers, completion notes, merge checklists, CLAUDE.md conventions, executor workflow) go through this
  • worktree.ts: Setup script generator, agent coordination instructions, CLAUDE.md section
  • index.ts: New MCP tool devplan_setup_worktrees (Tool 24)
  • docs/devplan-worktrees.md: Design document

Edge cases handled

Scenario Resolution
Shared config files Lock mechanism; modify from main only
Lock file conflicts Each worktree gets isolated deps
Port conflicts Per-task .env.local with unique port
DB migration ordering Sequential merge respects dependency graph

Tests

  • 35 new worktree-specific tests
  • 352 total tests, all passing
  • TypeScript compiles clean

Status

Prototype — ready for review. Future work:

  • Auto-detect parallelizable tasks from dependency graph
  • Setup script that reads the plan to create only needed worktrees
  • OpenClaw orchestrator integration

Radarr O'Really added 10 commits February 13, 2026 17:53
#146 - Feature grouping over-corrects (REGRESSION)
- Fixed groupRelatedFeatures to push ALL groups, not just those with items
- Features without endpoints are now preserved as separate phases

#140 - Plan scaffold generates .txt paths for Java
- Root cause: TemplateKey.language was a separate restricted type from DetectedLanguage
- Fix: TemplateKey.language now reuses DetectedLanguage type directly
- No more manual switch mapping - detected language passes through
- Adding new languages only requires updating DetectedLanguage + LANGUAGE_DEFAULTS

#143 - Endpoints as separate phases
- Fixed by #146 - endpoints now grouped with preceding feature
- Deploy to staging on push to fix/* and feat/* branches
- Deploy to staging on PRs to main
- Deploy to production only on push to main
- Add PR comment with staging URL for testing
Staging environment was being redirected to production custom domain.
Added ENVIRONMENT check to skip redirect when ENVIRONMENT=staging.
Haiku agent only sees the current context and can't reference CLAUDE.md.
Added COMPLETION_INSTRUCTION constant that gets inserted after each
subtask's Completion Notes section, telling the agent exactly how to
mark the subtask as complete.

Closes #148
- Add worktree.ts module with setup script generation, agent instructions,
  and CLAUDE.md coordination section
- New MCP tool: devplan_setup_worktrees for configuring parallel agents
- Each agent gets isolated worktree, branch, ports, deps, and database
- Advisory locking for shared resources (migrations, config)
- Edge cases: lockfile conflicts, port conflicts, DB migration ordering,
  shared config files
- 19 new tests (336 total, all passing)
- TypeScript compiles clean
- Add gitWorkflow: 'branch' | 'worktree' to ProjectBriefSchema (models.ts)
- Parse gitWorkflow from brief content in parseBrief()
- Add GitInstructions abstraction with branch/worktree implementations
- Replace hardcoded branch instructions in renderTemplatePhases()
- Replace hardcoded Git Workflow section in generatePlan()
- Append worktree addendum to executor agent when workflow=worktree
- Add design doc at docs/devplan-worktrees.md
- 13 new integration tests (349 total, all passing)

The gitWorkflow option controls all git instruction blocks:
- Task headers: 'Create branch' vs 'Work in worktree'
- Completion notes: 'feature/X' vs 'task/X (worktree)'
- Merge checklists: squash-merge vs worktree-remove
- CLAUDE.md conventions: branch strategy vs worktree layout
- Executor agent: branch checkout vs worktree awareness
- Add gitWorkflow to MinimalScaffoldConfig
- Pass git instructions through generateMinimalPhase0/1 and generateDomainSubtasks
- Replace all hardcoded branch refs in Phase 0 and Phase 1 scaffold with git helpers
- Language example snippets left as branch-mode (they're illustrative, not generated)
- 349 tests still passing, TypeScript clean
- Test generatePlan() with gitWorkflow: worktree produces worktree instructions
- Test generatePlan() defaults to branch instructions
- Test conflict zone warnings appear in worktree mode
- 352 total tests, all passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant