Running Claude Agents in Parallel with Git Worktrees
Use git worktrees to run multiple Claude agents on separate features without conflicts
2 minute read
The Problem: Claude Code Agents Block Each Other
When you want Claude to work on multiple features simultaneously, they compete for the same working directory. One agent's changes conflict with another's. You can't run parallel development workflows in a single git directory.
The Solution: Worktrees + Multiple Claude Instances
Git worktrees let you check out multiple branches in separate directories. Combined with multiple Claude Code instances, you can run truly parallel AI-assisted development.
Setup
1. Create worktree structure:
# From your main project directory
git worktree add .worktrees/feature-a -b feature-a
git worktree add .worktrees/feature-b -b feature-b
2. Open multiple Claude Code instances:
- Open first Claude instance in main directory (for
mainbranch) - Open second Claude instance in
.worktrees/feature-a/ - Open third Claude instance in
.worktrees/feature-b/
3. Assign tasks to each instance: Each Claude agent works independently in its own directory without conflicts.
Example Workflow
# Main directory: Bug fixes on main
claude> "Fix the authentication timeout issue"
# .worktrees/feature-a: New payment flow
claude> "Implement Stripe checkout integration"
# .worktrees/feature-b: UI redesign
claude> "Update dashboard components to new design system"
All three agents work simultaneously without stepping on each other.
Benefits
- True parallelism — Multiple features progress at once
- No conflicts — Each agent has isolated workspace
- Independent testing — Run dev servers for each branch simultaneously
- Clean PRs — Each worktree creates focused, isolated PRs
- Context preservation — Return to any agent without losing state
Cleanup
When features are complete:
# Merge your branches
git checkout main
git merge feature-a
git merge feature-b
# Remove worktrees
git worktree remove .worktrees/feature-a
git worktree remove .worktrees/feature-b
# Delete branches if needed
git branch -d feature-a feature-b
Tips
- Use
.worktrees/directory to keep worktrees organized and gitignored - Name worktrees clearly (e.g.,
feature-name, notwt1,wt2) - Close Claude instances when done to avoid confusion
- Each worktree can have its own dev server on different ports
Notes
My friend Jon Fox has a cool project called devx that allows a user to "develop multiple features in parallel with instant switching and zero port conflicts." Highly recommend it for anyone who's not afraid to do some setup and looking to explore this Claude Code workflow!
Build Your Website with AI—No Code Required
Learn to create and deploy professional websites using ChatGPT and Claude. Go from complete beginner to confident website builder.
