How to Use Git Worktrees in Claude Code for Parallel Development?
Problem
I was working on multiple features in the same repository. Every time I wanted Claude to help with a different task, I had to:
- Stash or commit my current changes
- Switch branches
- Start a new Claude session
- Lose context from the previous session
This was frustrating. I wanted to run multiple Claude Code sessions at the same time, each on a different branch. But a single git working directory can only be on one branch at a time.
Environment
- Claude Code CLI (latest version)
- Git 2.17+ (for worktree support)
- macOS / Linux / Windows
What is a Git Worktree?
A git worktree lets you have multiple working directories from the same repository, each checked out to a different branch. Think of it as cloning the repo multiple times, but without duplicating the .git folder.
Main Repo (/project) │ ├── worktree 1 (main branch) │ ├── worktree 2 (feature-auth branch) │ └── worktree 3 (bugfix-api branch)Each worktree is a separate directory. You can have different files open, different branches active, and different Claude sessions running - all at the same time.
Why I Needed This
I had three parallel tasks:
- Task A: Implement authentication feature
- Task B: Fix a critical API bug
- Task C: Refactor database queries
Each task needed Claude’s help. But with one working directory, I could only work on one at a time. Switching branches meant losing Claude’s context for the previous task.
How Claude Code Supports Worktrees
I discovered that Claude Code has native support for git worktrees. There are two ways to use it:
Method 1: CLI Flag
# Start Claude in a new worktreeclaude -wThis creates a new worktree and starts a fresh Claude session inside it. Claude handles the git worktree creation automatically.
Method 2: Claude Desktop Checkbox
In Claude Desktop, there is a “Worktree” checkbox option. Enable it to start a session in an isolated worktree environment.
My First Attempt
I started with the CLI:
cd ~/my-projectclaude -wWhat happened:
✓ Created worktree at /Users/cowrie/my-project/.claude/worktrees/wt-abc123✓ Checked out new branch: claude-worktree-abc123✓ Claude session started in isolated environmentClaude automatically:
- Created a new worktree directory
- Created a new branch
- Started an isolated session
Now I had two Claude sessions running - one in the main directory, one in the worktree.
Running Multiple Sessions
I opened three terminal windows:
# Terminal 1: Main project (main branch)cd ~/my-projectclaude
# Terminal 2: Authentication featurecd ~/my-projectclaude -w
# Terminal 3: API bug fixcd ~/my-projectclaude -wEach Claude session ran independently. No conflicts. No context switching. I could ask Terminal 2’s Claude to work on authentication while Terminal 3’s Claude fixed the API bug.
Managing Worktrees Manually
Sometimes I wanted more control. Here are the git worktree commands I use:
# List all worktreesgit worktree list
# Output:# /Users/cowrie/my-project abc1234 [main]# /Users/cowrie/my-project/.claude/worktrees/wt-def567 def5678 [claude-worktree-def567]
# Create a worktree for a specific branchgit worktree add ../my-feature feature-branch
# Remove a worktree after merginggit worktree remove ../my-feature
# Clean up stale worktree referencesgit worktree pruneCommon Mistakes I Made
Mistake 1: Forgetting to Clean Up
Worktrees consume disk space. After finishing a task, I forgot to remove the worktree:
# Check how many worktrees existgit worktree list
# Remove unused onesgit worktree remove .claude/worktrees/wt-old-taskMistake 2: Not Understanding Branch Visibility
I made changes in a worktree, then checked the main directory and got confused why the changes weren’t there. Each worktree is isolated. Changes only appear in other worktrees after you push and pull.
Worktree A (auth branch) → commit → push → ↓Worktree B (main branch) ← pull ← changes visible hereMistake 3: Creating Worktrees Outside Claude
I tried creating worktrees manually with git worktree add, then running Claude there. This works, but I missed out on Claude’s automatic management. Claude’s -w flag handles cleanup and naming for you.
The Real-World Workflow
Here is how Boris Cherny, the creator of Claude Code, uses worktrees (from a Reddit discussion on March 30, 2026):
“Claude Code ships with deep support for git worktrees. Worktrees are essential for doing lots of parallel work in the same repository. I have dozens of Claudes running at all times, and this is how I do it.”
This confirms that worktrees are not just a nice feature - they are essential for parallel AI-assisted development at scale.
When to Use Worktrees
I use worktrees when:
- Working on multiple features simultaneously
- Running long Claude sessions that I don’t want to interrupt
- Testing experimental changes without affecting my main work
- Collaborating with different Claude instances on different branches
I don’t use worktrees when:
- Just doing a quick fix on one branch
- The task is sequential, not parallel
- I’m nearly done with all current work
Summary
In this post, I showed how to use git worktrees in Claude Code for parallel development. The key is using claude -w to start isolated sessions in separate working directories. Each worktree has its own branch, its own files, and its own Claude context - no more switching branches or losing context.
The main takeaway: worktrees transform Claude Code from a single-threaded assistant into a parallel development system. You can run dozens of Claude sessions simultaneously, each working on a different task, without conflicts.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments