Worktree 서브에이전트 격리 패턴
워크트리중급
2026년 추가된 worktree 서브에이전트 격리 기능으로 각 Agent 호출에 임시 worktree를 자동 생성합니다. 변경 없으면 자동 정리되고, 변경이 있으면 브랜치와 경로가 반환되어 병합할 수 있습니다.
worktree서브에이전트격리병렬git
패턴 코드
# Worktree Subagent Isolation Pattern
## Basic Usage — isolation: "worktree"
```typescript
// In CLAUDE.md or custom subagent definition
// Each subagent gets its own git worktree automatically
// Parent agent launches isolated subagents
await Promise.all([
agent({
prompt: "Implement user authentication module",
isolation: "worktree", // <-- auto-creates .claude/worktrees/<random>
}),
agent({
prompt: "Implement payment processing module",
isolation: "worktree", // <-- separate worktree, no conflicts
}),
agent({
prompt: "Write integration tests for both modules",
isolation: "worktree",
}),
]);
```
## How It Works
```
Main worktree (your working directory)
├── .claude/worktrees/
│ ├── auth-abc123/ ← subagent 1's isolated copy
│ │ └── (full repo clone on separate branch)
│ ├── payment-def456/ ← subagent 2's isolated copy
│ │ └── (full repo clone on separate branch)
│ └── tests-ghi789/ ← subagent 3's isolated copy
│ └── (full repo clone on separate branch)
```
## Lifecycle
1. **Creation**: `git worktree add .claude/worktrees/<name> -b <branch>`
2. **Execution**: Subagent runs in isolated directory
3. **Completion**:
- If NO changes → worktree auto-removed (clean)
- If changes made → worktree + branch preserved
- Parent receives: { worktreePath, branch, hasChanges }
## Merge Strategy
```bash
# After subagents complete, merge results
git merge worktree/auth-abc123 --no-ff -m "feat: add auth module"
git merge worktree/payment-def456 --no-ff -m "feat: add payment module"
# Clean up merged worktrees
git worktree remove .claude/worktrees/auth-abc123
git worktree remove .claude/worktrees/payment-def456
```
## Benefits Over Manual Worktrees
- No setup scripts needed — just add `isolation: "worktree"`
- Auto-cleanup on no-change subagents (no stale worktrees)
- Branch naming handled automatically
- Works with existing git hooks and CI
- Compatible with Agent Teams for team-level isolation
이 패턴을 프로젝트 설정에 복사하여 적용하세요.
실행 미리보기
Worktree 서브에이전트 격리 패턴
Worktree 서브에이전트 격리 패턴에 대해
Claude Code 패턴은 복잡한 개발 시나리오를 효과적으로 다루기 위한 검증된 아키텍처 설계와 워크플로우 구조입니다. Worktree 서브에이전트 격리 패턴은(는) 중급 수준의 워크트리 패턴으로, 프로젝트에 맞게 응용할 수 있는 테스트된 반복 가능한 접근 방식을 제공하여 더 효율적이고 일관된 결과를 만들어 냅니다.