Worktree Workflows
Git worktrees let you have multiple branches checked out simultaneously in different folders. Combined with Cline CLI’s--cwd flag, this enables powerful parallel development workflows and isolated experimentation.
Quick Worktree Setup
If you haven’t used Git worktrees before, here’s the essentials:.git directory, but have independent working directories.
The --cwd Flag
The -c, --cwd <path> flag tells Cline to run in a specific directory without changing your current location:
Pattern 1: Parallel Task Execution
Run different tasks in parallel across multiple worktrees. Each task works on a separate branch in complete isolation.Example: Parallel Feature Development
& runs each command in the background, allowing all three to execute simultaneously.
When to Use Parallel Execution
Perfect for:- Multiple independent features
- Bulk refactoring across different modules
- Running tests in one worktree while developing in another
- Trying multiple approaches to the same problem
- Tasks that modify the same files (merge conflicts likely)
- Tasks that depend on each other’s results
- When you need to monitor progress closely
Pattern 2: Cross-Worktree Context Piping
Pipe output from one worktree as input to another. Use when a task in one worktree needs context from attempts in another worktree.Example: Learning from Failures
- First Cline instance runs in
worktree-a, attempts a change, tests it - If it fails, outputs just the failure summary
- That summary is piped to a second Cline instance in
worktree-b - Second instance sees the failure and tries a different approach
When to Use Context Piping
Perfect for:- A/B testing different solutions
- Learning from failed attempts
- Iterative refinement (try → analyze → try differently)
- Comparing outputs across approaches
- Simple tasks that don’t need cross-context
- When both worktrees would succeed independently
- Real-time collaboration (use parallel execution instead)
Combining with Other CLI Features
Different Models Per Worktree
Use--config to run different models in different worktrees:
Task Isolation
Keep long-running worktree sessions isolated by running each task against a different worktree path:With YOLO Mode
The-y (YOLO) flag is essential for worktree workflows:
-y to avoid blocking on user approval.
Real-World Workflow Example
Here’s a complete workflow showing how these patterns work together:Best Practices
Worktree Organization
Worktree Organization
- Use a dedicated folder: Create
~/cline-worktrees/for all worktrees - Meaningful branch names: Use
feature/,fix/,refactor/prefixes - Clean up regularly: Remove worktrees after merging branches
Task Isolation
Task Isolation
- Independent features only: Don’t parallelize tasks that touch the same files
- Test in isolation: Each worktree should have its own test run
- Separate configs: Use
.worktreeincludeto copynode_modulesand build artifacts
Resource Management
Resource Management
- Monitor disk space: Each worktree is a full checkout
- Limit parallel tasks: Running too many simultaneously can slow your system
- Use background jobs wisely: Track with
jobscommand, kill withkill %1, etc.
Error Handling
Error Handling
- Check exit codes: Use
|| echo "Task failed"to catch errors - Log outputs: Redirect to files for debugging:
> worktree-a.log 2>&1 - Graceful cleanup: Always remove worktrees after tasks complete
Troubleshooting
"Branch already checked out" error
"Branch already checked out" error
Git doesn’t allow the same branch in multiple worktrees. Solutions:
- Use different branch names for each worktree
- Remove the existing worktree first:
git worktree remove <path>
Tasks not running in parallel
Tasks not running in parallel
Make sure you’re using:
&at the end of each command to background it-yflag so Cline doesn’t wait for approval- Different worktrees (not the same path)
Pipe not working as expected
Pipe not working as expected
Verify:
- First command outputs to stdout (not stderr)
- Second command reads from stdin (use
--separator if needed) - Both commands use correct
--cwdpaths
Changes not appearing in worktree
Changes not appearing in worktree
Check:
- You’re in the right worktree:
git worktree list - Files aren’t gitignored
- You committed/staged changes if needed
Related Documentation
Worktrees Overview
Complete guide to Git worktrees, VS Code integration, and .worktreeinclude
Model Orchestration
Use different models strategically with —config and —thinking flags
CLI Reference
Complete documentation for —cwd and all other CLI flags
Three Core Flows
Learn about interactive mode, task mode, and plain text workflows

