Worktree Component
Automatically provision git worktrees and ensure all nested agent components operate within isolated directory contexts. Enables parallel execution on different branches, safe experimentation, and clean phase isolation.API
Usage
Basic Branch Isolation
Parallel Branch Execution
Safe Experimentation
With Nested Smithers
Explicit Path
Props
Branch name for the worktree.Behavior:
- If branch exists: Checkout branch in worktree
- If branch missing: Create from
baseref (default HEAD)
"feature-auth"- Descriptive feature name"hotfix-security"- Hotfix branch"experiment-${Date.now()}"- Unique experimental branch
Base ref to create branch from when branch doesn’t exist.Examples:
"main"- Branch from main"develop"- Branch from develop"v1.2.3"- Branch from tag"abc123"- Branch from specific commit
Explicit worktree directory path.Default: Relative paths: Resolved relative to repo rootPath normalization: Uses
.worktrees/${branch} (relative to repo root)Absolute paths:path.resolve() for consistent comparison.Automatically remove worktree on unmount.Safety: Only removes if this component created the worktree.Use case: Temporary worktrees for experimentation or CI runs.Failure handling: Logs warning if cleanup fails, doesn’t throw.Default
false to preserve worktrees across runs.Components to execute in worktree context.Context propagation: All nested components receive worktree cwd automatically:
- Claude components
- Smithers components
- Command components
- Custom components using
useWorktree()hook
Callback when worktree setup completes.Receives absolute path to worktree directory.
Callback when worktree setup fails.Common errors:
- Branch already checked out elsewhere
- Invalid branch name
- Insufficient permissions
- Path conflicts
Design Rationale
Context Propagation Pattern
Lifecycle States
Ralph Iteration Behavior
Design decision: Worktrees persist across Ralph iterations.- Worktree creation expensive (git operations, disk I/O)
- Most use cases want iteration on changes in same worktree
- For per-iteration worktrees, use dynamic branch names:
Priority Override
Examples of Use Cases
Use Case 1: Parallel Feature Development
Use Case 2: Review Different Approaches
Use Case 3: Clean Test Environment
Use Case 4: Nested Worktrees (Advanced)
Related
Claude Component
Automatically respects worktree context for cwd
Command Component
Executes commands in worktree directory when nested
Parallel Component
Run multiple worktrees concurrently for parallel development
Alternatives Considered
- Manual cwd prop threading: Verbose, error-prone, breaks abstraction
- Temporary directories without git: Loses git history, no branch switching
- Git stash/unstash: Complex lifecycle, state conflicts
- Cloning repository: Expensive, duplicates entire repo