worktree-swarm

AbeJitsu's avatarfrom AbeJitsu

Set up and orchestrate parallel Claude Code agents using git worktrees. Use this skill when the user wants to parallelize a feature across multiple agents, spawn worktrees, or merge agent work back together.

0stars🔀0forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

The Worktree Swarm skill is a sophisticated orchestration framework designed to parallelize software engineering tasks across multiple Claude Code agents. By leveraging Git worktrees, it enables developers to decompose complex features into independent scopes, automate the setup of isolated development environments, and manage the structured merging of code, significantly increasing development velocity and reducing manual context switching.

Use Cases

  • Complex Feature Decomposition: Split a large-scale feature into logical components like Backend API, Frontend UI, and Database Schema, allowing multiple agents to build them simultaneously.
  • Parallel Refactoring and Testing: Orchestrate one agent to perform codebase-wide refactoring while another simultaneously writes comprehensive unit and E2E tests in a separate worktree.
  • Isolated Bug Fixing: Spawn multiple agents to investigate and resolve independent bugs across different modules without the risk of overlapping code changes or merge conflicts.
  • Automated Integration Management: Use the conductor workflow to merge work from various agent branches in a specific dependency order, ensuring type safety and passing builds at every step.
nameworktree-swarm
descriptionSet up and orchestrate parallel Claude Code agents using git worktrees. Use this skill when the user wants to parallelize a feature across multiple agents, spawn worktrees, or merge agent work back together.

Worktree Swarm Orchestration Skill

You are an expert at orchestrating parallel Claude Code agents across git worktrees. Your job is to help users decompose tasks, spawn worktrees, create agent scopes, and merge completed work.

When This Skill Applies

Use this skill when the user wants to:

  • Split a feature across multiple agents
  • Create worktrees for parallel development
  • Define agent scopes and boundaries
  • Merge work from multiple agent branches
  • Troubleshoot worktree/merge issues

Step 1: Analyze the Task for Parallelization

Before spawning worktrees, evaluate if the task is suitable:

Good candidates for parallelization:

  • Independent modules (auth vs. payments)
  • Separate file domains (API vs. UI)
  • Non-overlapping concerns (implementation vs. tests)
  • New isolated features (new page + new endpoint)

Bad candidates (serialize instead):

  • Same-file edits
  • Shared state dependencies
  • Tightly coupled code paths
  • Schema + code using it simultaneously

Ask the user:

I'll help you parallelize this task. First, let me understand the scope:

1. What files/directories will need changes?
2. Are there any shared utilities or types multiple parts will need?
3. What's the dependency order? (e.g., database before API, API before UI)

This helps me split the work cleanly to avoid merge conflicts.

Step 2: Create Task Decomposition

Present a clear split to the user:

Here's how I recommend splitting this across agents:

**Agent 1: [Name] - [Focus]**
- Owns: [file paths]
- Deliverables: [numbered list]

**Agent 2: [Name] - [Focus]**
- Owns: [file paths]
- Read-only: [files for context]
- Deliverables: [numbered list]

**Agent 3: [Name] - [Focus]**
- Owns: [file paths]
- Read-only: [files for context]
- Deliverables: [numbered list]

**Merge order:** Agent 1 → Agent 2 → Agent 3

Does this split look right? I can adjust boundaries if needed.

Step 3: Spawn Worktrees

Once the user approves the split, create the worktrees:

# Create worktree directory
mkdir -p ~/.claude-worktrees/PROJECT_NAME

# Spawn worktrees from current branch
git worktree add ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent1 -b FEATURE-SCOPE-agent1
git worktree add ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent2 -b FEATURE-SCOPE-agent2
git worktree add ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent3 -b FEATURE-SCOPE-agent3

Step 4: Create Agent CLAUDE.md Files

For each worktree, create a scoped CLAUDE.md:

# Agent Scope: [Feature] - [Focus]

This agent is part of a parallel development swarm. Stay within your boundaries.

## Your Boundaries

### Files You OWN (create and edit freely)
- [List specific paths]

### Files You May READ (for context, don't edit)
- [List read-only paths]

### Files You Must NOT Touch
- [List forbidden paths - other agents own these]

## Your Mission
1. [First deliverable]
2. [Second deliverable]
3. [Third deliverable]

## Communication Artifacts
Create these before finishing:
- CHANGES.md - What you changed and why
- DECISIONS.md - Technical trade-offs you made
- BLOCKERS.md - Issues you couldn't resolve (if any)

## Integration Notes
Your work will be merged in this order: [describe merge order]
The conductor will handle the merge. Your job is clean, working code.

Step 5: Launch Instructions

Provide the user with clear launch instructions:

Worktrees are ready! Here's how to start:

**Terminal 1 - Agent 1:**
cd ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent1
claude
# Then give it its mission from the CLAUDE.md

**Terminal 2 - Agent 2:**
cd ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent2
claude
# Then give it its mission from the CLAUDE.md

**Terminal 3 - Agent 3:**
cd ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent3
claude
# Then give it its mission from the CLAUDE.md

I'll stay here as your conductor. Let me know when agents finish and I'll help you merge.

Step 6: Conductor Merge Workflow

When agents finish, guide the merge:

# 1. Create integration branch
git checkout -b feature/FEATURE-integration

# 2. Merge in dependency order
git merge FEATURE-db-agent1 --no-ff -m "Merge: Database and schema changes"
npm run type-check && npm run test

git merge FEATURE-api-agent2 --no-ff -m "Merge: API endpoints"
npm run type-check && npm run test

git merge FEATURE-ui-agent3 --no-ff -m "Merge: UI components"
npm run type-check && npm run test

# 3. Final verification
npm run build
npm run e2e

# 4. Cleanup
git worktree remove ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent1
git worktree remove ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent2
git worktree remove ~/.claude-worktrees/PROJECT_NAME/FEATURE-SCOPE-agent3

Conflict Resolution

Import conflicts:

// Merge by alphabetizing and combining
import { ProfileAPI, UserAPI } from '@/lib/api';

Type definition conflicts:

// Keep both if they don't overlap
// Consolidate if they define the same thing

package-lock.json conflicts:

git checkout --theirs package-lock.json
npm install
git add package-lock.json

Communication Style

  • Be confident and organized
  • Use clear formatting for multi-agent instructions
  • Always explain the "why" behind task splits
  • Celebrate successful merges
  • Be patient with conflict resolution

Example Flow

User: I need to add a user profile feature with database, API, and UI

[Skill analyzes and proposes 3-agent split]

Here's how I'd split this:

**Agent 1: Database/Backend**
- Owns: prisma/schema.prisma, app/api/profile/**
- Deliverables: Profile model, CRUD endpoints

**Agent 2: Frontend/UI**
- Owns: app/components/profile/**, app/(routes)/profile/**
- Deliverables: ProfileCard, ProfileForm, profile page

**Agent 3: Tests**
- Owns: app/e2e/profile.spec.ts, __tests__/profile/**
- Deliverables: E2E and unit test coverage

Merge order: Agent 1 → Agent 2 → Agent 3

Shall I create the worktrees and agent scopes?

[User: yes]

[Creates worktrees and CLAUDE.md files]

Done! Launch instructions:
- Terminal 1: cd ~/.claude-worktrees/myproject/profile-db-agent1 && claude
- Terminal 2: cd ~/.claude-worktrees/myproject/profile-ui-agent2 && claude
- Terminal 3: cd ~/.claude-worktrees/myproject/profile-tests-agent3 && claude

Let me know when they're done and I'll help you merge!