Claude Code Worktrees: How to Run Parallel Sessions on One Repo
By Shubhranshu, creator of claudeagents · Last reviewed
To run several Claude Code sessions on one repository, start each with claude --worktree <name> (or claude -w <name>). Claude Code creates a separate folder at .claude/worktrees/<name>/ on a new branch worktree-<name>, so sessions never edit the same files. Add .claude/worktrees/ to .gitignore and merge each branch when it's done.
Two Claude Code sessions in the same folder will overwrite each other's work. A git worktree is a second checkout of the same repo in its own folder, sharing one history. Claude Code has this built in, so parallel work is one flag away.
Steps and flags below are from the Claude Code worktrees docs, checked on 4 December 2026.
How to start Claude Code in a worktree
- Add
.claude/worktrees/to your.gitignoreso the extra checkouts never get committed. - In your repo, run
claude --worktree feature-auth. Without a name, Claude picks one likebright-running-fox. - Open a second terminal and run
claude -w fix-billing-bugfor a separate task. - Work in each session as normal. Each one is on its own branch and folder.
New worktrees start from your remote's default branch. To start from your current local commit instead, set "worktree": { "baseRef": "head" } in settings. Running the same name again reopens that worktree.
To review a pull request, pass its number in quotes, claude -w "#1234", or paste the GitHub or GitLab PR URL. It opens in .claude/worktrees/pr-1234.
Copy .env and other ignored files with .worktreeinclude
A new worktree only contains files tracked by git, so your .env and local config are missing and the app won't run. Create a .worktreeinclude file at the project root. It uses gitignore syntax, and only files that are also gitignored get copied:
# .worktreeinclude (project root, gitignore syntax)
.env
.env.local
config/secrets.jsonIt applies to --worktree sessions, subagent worktrees and desktop app sessions. You still need to install dependencies (for example npm install) inside each new worktree.
Give subagents their own worktree
Subagents normally share your folder, so two of them editing at once can clash. Add isolation: worktree to the agent's frontmatter in .claude/agents/, or just ask Claude to "use worktrees for your agents":
---
name: refactor-worker
description: Large refactors that should not touch my working copy
isolation: worktree
---
You refactor code in your own worktree and report the branch name when done.Subagent worktrees don't load the worktree's root CLAUDE.md, so put anything the agent must know in its own instructions. Old subagent worktrees are swept up automatically. New to subagents? Start with how to create Claude Code subagents.
Cleaning up worktrees
| Worktree state | On exit |
|---|---|
| No changes, unnamed session | Worktree and branch removed automatically |
| No changes, named session | Claude asks whether to keep it |
| Uncommitted changes or new commits | Claude asks: keep or remove |
| Started with -p (non-interactive) | Never cleaned up; remove it yourself |
Gitignored files don't count as work, so a copied .env or build output can be deleted with the worktree.
To remove one by hand: git worktree list to see them, then git worktree remove .claude/worktrees/feature-auth (add --force if it has uncommitted changes).
Merging the work back
- In the worktree session, ask Claude to run the tests and commit.
- Push the branch and open a pull request, or merge locally with
git merge worktree-feature-authfrom your main checkout. - Review each branch on its own. Use
git cherry-pickto move individual commits between branches rather than copying code by hand. - Exit the session and let Claude remove the worktree.
Want a second opinion before merging? Our Claude Code code review guide shows how to review a branch, and GitHub Actions can review every PR automatically.
Worktrees vs subagents vs agent teams
| Approach | Separate files? | Best for |
|---|---|---|
| Worktrees | Yes, own folder and branch | Independent features you'll review and merge separately |
| Subagents | No (unless isolation: worktree) | Focused side jobs inside one task: research, tests, review |
| Agent teams | Shared folder by default | Several agents working one task together |
More on teams in Claude Code agent teams. For ready-made agents to put in each worktree, claudeagents includes 85 agents and 53 commands for coding, SEO and marketing.
Frequently asked questions
How do I run multiple Claude Code sessions at once?
Start each one in its own worktree with claude --worktree <name> (or -w). Each session gets its own folder and branch, so they don't overwrite each other's files.
Where does Claude Code create worktrees?
In .claude/worktrees/<name>/ at the repository root, on a branch called worktree-<name>. Add .claude/worktrees/ to .gitignore.
Why is my .env missing in the worktree?
Worktrees only contain tracked files. List gitignored files such as .env in a .worktreeinclude file at the project root and Claude Code copies them into new worktrees.
How do I delete a Claude Code worktree?
Exit the session and choose remove, or run git worktree remove <path>. Add --force if it has uncommitted changes.
How many parallel Claude Code sessions should I run?
Most developers manage two or three well. Every session's work still needs reviewing and merging, and all sessions share the same usage limits.
Do parallel sessions use more of my Claude plan?
Yes. Each session uses your shared 5-hour and weekly limits, so several sessions at once use them up faster.
Sources
Skip the setup: get the Coding kit
30 ready-made coding agents, 19 slash commands and 22 skills for Claude Code. $15 one-time, lifetime updates.
All 3 kits (Coding, SEO and Marketing): 85 agents for $39 instead of $45. See what's in the Coding kit
Use code for 25% off all 3 kits: pay $29.25 instead of $39
Valid until Dec 19 · enter it at checkout