Skip to content
Back to skills

1716 Worktree Guide 43d9a9da

ASecurity

When running multiple agents in parallel, each agent should use its own **git worktree** to avoid conflicts on git operations, checkpoint files, and version tracking.

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 1, 2026
ai-agentspythonbashgit

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 1, 2026

npx -y skills add tools-only/X-Skills --skill 1716-worktree-guide_43d9a9da --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1716 Worktree Guide 43d9a9da?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1716 Worktree Guide 43d9a9da
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1716-worktree-guide-43d9a9da/badge)](https://www.skillsdirectory.com/skills/tools-only-1716-worktree-guide-43d9a9da)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Parallel Agent Isolation (Git Worktrees)

When running multiple agents in parallel, each agent should use its own **git worktree** to avoid conflicts on git operations, checkpoint files, and version tracking.

## Why Worktrees?

Without isolation, parallel agents cause:
- Race conditions on `git commit`/`git push`
- Checkpoint invalidation chaos (Agent A's version invalidated by Agent B's commit)
- Silent merge conflicts when editing same files

## Worktree Workflow

```
COORDINATOR (main repo)
├── Creates worktrees for each agent
├── Each agent diagnoses/fixes independently
├── Sequential merge after completion
└── Single deployment after merge

AGENT WORKTREE
├── Own branch: claude-agent/{agent-id}
├── Own .claude/ directory (checkpoint, state)
├── Independent log collection
└── Independent version tracking
```

## Creating a Worktree

```bash
python3 ~/.claude/hooks/worktree-manager.py create <agent-id>
# Returns: /tmp/claude-worktrees/<agent-id>
```

## Merging Agent Work

```bash
python3 ~/.claude/hooks/worktree-manager.py merge <agent-id>
# If conflict (exit code 2): fall back to sequential execution
python3 ~/.claude/hooks/worktree-manager.py cleanup <agent-id>
```

## Coordinator Deploy Pattern

**ONLY the coordinator deploys. Subagents NEVER deploy.**

```
1. Create worktrees for each agent
2. Spawn Tasks (each gets worktree path in prompt)
3. Wait for all Tasks
4. Sequential merge (abort on conflict → fall back to sequential)
5. SINGLE deploy (coordinator only): git push && gh workflow run && gh run watch
6. Cleanup worktrees
```

**SUBAGENT RULES (enforced by state file):**
- If `coordinator: false`, NEVER run `gh workflow run` or `git push`
- Commit locally in worktree only
- Mark `needs_deploy: true` in checkpoint

**Coordination detection:**
- Skills set `coordinator: false`, `parallel_mode: true` in worktree `autonomous-state.json`
- `deploy-enforcer.py` blocks subagent deploy attempts

## Garbage Collection

```bash
python3 ~/.claude/hooks/worktree-manager.py gc           # Default 8-hour TTL
python3 ~/.claude/hooks/worktree-manager.py gc --dry-run # Preview cleanup
```

Files in this skill

  • README.md991 B
  • skill.md2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.