Claude Code worktrees, explained
Git has supported worktrees for years: git worktree add checks a branch out into a second directory, backed by the same .git data. Claude Code builds on that. With --worktree (or -w) it creates the worktree for you, starts the session inside it, blocks edits that would land in your main checkout, and offers to clean up when you exit.
Worktrees isolate files, nothing else. To split one task between workers inside a single conversation, use subagents; to compare the options, see multiple Claude Code agents.
- Default location:
.claude/worktrees/<name>/at the repository root. - Default branch name:
worktree-<name>. Leave out the name and Claude Code picks one, such asbright-running-fox. - Shared with your checkout: the
.gitdirectory (so commits and branches are visible everywhere), project-scope plugins, and "don't ask again" permission approvals. - Not shared: anything gitignored, such as
.env,node_modulesand build output. A worktree is a fresh checkout.
The worktree workflow, step by step
Ignore the worktree folder
Add
.claude/worktrees/to.gitignore, so worktree files don't show up as untracked in your main checkout. If you've never run Claude in this repository, runclaudeonce first to accept the workspace trust prompt; interactive--worktreeruns exit until you do.Start one session per task
Run
claude --worktree <name>in one terminal for each task. Running it again with an existing name reopens that worktree instead of making a new one. You can also ask Claude mid-session to "work in a worktree", and it moves itself into one with theEnterWorktreetool.# Two isolated sessions, each in its own terminal claude --worktree feature-auth claude --worktree fix-flaky-test # Branch a worktree from pull request 1234 (quote the #) claude --worktree "#1234" # Keep worktrees out of git status echo ".claude/worktrees/" >> .gitignoreBring the untracked files along
List gitignored files the project needs, such as
.envand.env.local, in a.worktreeincludefile at the repository root, using.gitignoresyntax. Claude Code copies matching files into every worktree it creates, including subagent and desktop worktrees. Then install dependencies in the worktree, or set it up in settings: this example branches from your current work, reuses onenode_modulesand checks out only the web package.{ "worktree": { "baseRef": "head", "symlinkDirectories": ["node_modules"], "sparsePaths": [".claude", "packages/web"] } }Let the sessions work
While a session is isolated, Claude Code refuses file edits that target the main checkout, commands whose working directory is the main checkout, and git commands redirected into it (
git -C,--git-dir,GIT_DIR). It doesn't track what a plain shell command such ascpwrites, so permissions and sandboxing still matter.Review and merge like any branch
Each worktree is a normal branch. Commit and push from inside it, open a pull request, and review it as you would a teammate's. Because all worktrees share
.git, the branch is visible from your main checkout straight away.Exit and clean up
When you exit, Claude Code checks the worktree. A clean one from an unnamed session is removed with its branch automatically; a named session asks first. If there are changes, untracked files or new commits, it asks whether to keep or remove the worktree, and prints a
claude --worktree <name> --resumecommand to come back later.
Source: Claude Code docs, Run parallel sessions with worktrees
Worktree settings in Claude Code
All of these go under worktree in a settings file (~/.claude/settings.json, .claude/settings.json or .claude/settings.local.json).
| Setting | What it does | Default |
|---|---|---|
worktree.baseRef | "fresh" branches from the remote default branch (origin/main); "head" branches from your local HEAD, unpushed commits included | "fresh" |
worktree.symlinkDirectories | Symlinks directories such as node_modules from the main checkout instead of duplicating them | None |
worktree.sparsePaths | Checks out only the listed directories (plus root files) with sparse-checkout; include .claude | Whole tree |
worktree.bgIsolation | "worktree" makes background sessions edit only inside a worktree; "none" lets them edit the working copy | "worktree" |
| Worktree location (desktop app) | Settings > Code sets a custom folder for local sessions; SSH connections have their own | .claude/worktrees/ |
.worktreeinclude (file, not a setting) | Copies matching gitignored files into each new worktree | None |
Claude Code worktree vs branch vs git worktree
| Switching branches | `git worktree add` + `claude` | `claude --worktree` | |
|---|---|---|---|
| Separate files on disk | No: one directory, one branch at a time | Yes | Yes |
| Several sessions at once | No: they overwrite each other | Yes | Yes |
| Where it goes | Your checkout | Anywhere you choose | .claude/worktrees/<name>/, or a hook's path |
| Starts from | The branch you switch to | Any existing or new branch | origin/<default>, your HEAD, or a PR |
Copies .env | Not needed | No | Yes, with .worktreeinclude |
| Edits blocked outside it | No | No | Yes |
| Cleanup | None | git worktree remove | Offered on exit |
Doing it by hand with git worktree
Use plain git when you want a specific existing branch or a folder outside the repository; worktree.baseRef can't name a branch. Claude Code still shares plugins and permission approvals with these worktrees.
Create the worktree, start Claude, remove it when done
Replace
feature-awith a new branch name, or drop-bto check out a branch that already exists.git worktree add ../app-feature-a -b feature-a cd ../app-feature-a && claude git worktree list git worktree remove ../app-feature-a
Subagents and background sessions in worktrees
- Ask Claude to "use worktrees for your agents", or add
isolation: worktreeto a custom subagent's frontmatter in.claude/agents/, and each subagent edits in its own temporary worktree. - A subagent worktree without changes is removed when the subagent finishes. One with changes stays until a periodic sweep can remove it without losing work, after
cleanupPeriodDays. - Background sessions (
claude --bg) edit only inside a worktree by default; start one withclaude --bg --worktreeor setworktree.bgIsolationto"none". - In the desktop app, turn on Worktree under the prompt box before you start a session.
Worktree cleanup and common problems
claude -p --worktreeruns have no exit prompt, so they leave their worktrees behind. Remove them withgit worktree remove, aftergit worktree unlockif git says it's locked.Can only use --worktree in a git repository: rungit initand make a first commit, or set up aWorktreeCreatehook for SVN, Perforce or Mercurial.- Git LFS files show up as pointer files when LFS was installed with
--local: rungit lfs pullinside the worktree. - Claude Code won't create a worktree when
.claudeor.claude/worktreesis a symlink. - Hooks keep
${CLAUDE_PROJECT_DIR}pointing at the main checkout; read thecwdfield of the hook input to get the worktree path. - A worktree with
"fresh"base and no commits of its own, or whose PR was merged, resets to the default branch when you reopen it by name.
Worktrees keep sessions apart. Crewmark keeps them busy.
Worktrees solve the collision problem, but each session still sits idle until you type. Crewmark turns a Claude Code, Codex, DeepSeek Harness or OpenCode session into an AI employee with a role, a goal and working hours, and wakes it on a heartbeat to take the next issue from a board.
One employee per worktree
Give each employee its own worktree and role, such as a programmer and a reviewer in the same repository, as in multiple Claude Code agents.
Let the heartbeat start the work
During its working hours each employee wakes every 15, 30 or 60 minutes in the same conversation; see how to make Claude Code proactive.
Assign issues and review branches
Put work on the board; each employee takes an issue, commits on its own branch and messages you when it needs a decision. Read what an AI employee is.
Claude Code worktree FAQ
What is a worktree in Claude Code?
A separate git working directory with its own files and branch that shares your repository's history. claude --worktree <name> creates one and runs the session inside it, so parallel sessions don't edit the same files.
Where does Claude Code put worktrees?
In .claude/worktrees/<name>/ at the repository root, on a branch named worktree-<name>. The desktop app lets you pick another folder in Settings, and a WorktreeCreate hook can place them anywhere.
Which branch does a Claude Code worktree start from?
The remote default branch, usually origin/main, by default. Set worktree.baseRef to "head" to branch from your local HEAD, pass "#1234" to start from a pull request, or create the worktree with git worktree add for any other branch.
Why is my .env file missing in the worktree?
A worktree is a fresh checkout, so gitignored files aren't there. List them in a .worktreeinclude file at the repository root and Claude Code copies them into every new worktree.
How do I clean up Claude Code worktrees?
Exiting a session offers to remove its worktree, and removes clean unnamed ones automatically. Worktrees from -p runs stay behind: list them with git worktree list and remove them with git worktree remove.
Worktree or branch: what's the difference?
A branch is a line of commits; a worktree is a directory where a branch is checked out. Switching branches changes the files in your one directory, while worktrees give each branch its own directory, so several sessions can run at once.
Can subagents use worktrees?
Yes. Ask Claude to use worktrees for its agents, or add isolation: worktree to a custom subagent's frontmatter. Each gets a temporary worktree that's removed if it makes no changes.
Checked against the Claude Code docs (worktrees, settings, CLI reference and desktop) on November 6, 2026.