Skip to content

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:

  1. Stash or commit my current changes
  2. Switch branches
  3. Start a new Claude session
  4. 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.

worktree-structure.txt
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

claude-w-flag.sh
# Start Claude in a new worktree
claude -w

This 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:

start-worktree.sh
cd ~/my-project
claude -w

What happened:

output.txt
✓ Created worktree at /Users/cowrie/my-project/.claude/worktrees/wt-abc123
✓ Checked out new branch: claude-worktree-abc123
✓ Claude session started in isolated environment

Claude automatically:

  1. Created a new worktree directory
  2. Created a new branch
  3. 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:

multiple-sessions.sh
# Terminal 1: Main project (main branch)
cd ~/my-project
claude
# Terminal 2: Authentication feature
cd ~/my-project
claude -w
# Terminal 3: API bug fix
cd ~/my-project
claude -w

Each 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:

worktree-commands.sh
# List all worktrees
git 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 branch
git worktree add ../my-feature feature-branch
# Remove a worktree after merging
git worktree remove ../my-feature
# Clean up stale worktree references
git worktree prune

Common Mistakes I Made

Mistake 1: Forgetting to Clean Up

Worktrees consume disk space. After finishing a task, I forgot to remove the worktree:

cleanup-worktrees.sh
# Check how many worktrees exist
git worktree list
# Remove unused ones
git worktree remove .claude/worktrees/wt-old-task

Mistake 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.

branch-visibility.txt
Worktree A (auth branch) → commit → push →
Worktree B (main branch) ← pull ← changes visible here

Mistake 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