Run claude --worktree <name> (or -w) to create an isolated worktree and start Claude in it. As of August 2026 the worktree lands under .claude/worktrees/<name>/ at the repository root, on a new branch called worktree-<name>, branched from your default branch. Add .claude/worktrees/ to .gitignore, and list any gitignored config in a .worktreeinclude file so it is copied in. While the session is in a worktree, Claude Code blocks edits, command working directories, and git redirects that would reach the main checkout. On exit it offers to remove the worktree, and keeps it if there is work in it.
claude --worktree feature-authis the whole setup.-wis the short form.- Default location is
.claude/worktrees/<name>/, branchworktree-<name>. - Put
.claude/worktrees/in.gitignorebefore you start. .worktreeincludecarries.envand friends into every new worktree.- Isolation is enforced at the tool layer, not left to the model.
- Exiting an interactive session offers cleanup.
-pruns clean up nothing. - Subagents get their own worktrees with
isolation: worktreein frontmatter.
The one-flag version
# one isolated session
claude --worktree feature-auth
# short form, second terminal, second task, no collision
claude -w search-index
# no name: Claude generates one, such as bright-running-fox
claude -w
That creates a worktree at .claude/worktrees/feature-auth/ in the repository root, on a new branch named worktree-feature-auth, and starts the session inside it. Run it again in another terminal with a different name and you have two sessions that cannot touch each other's files.
What the flag does that you would otherwise do by hand.
| Step | By hand | With --worktree |
|---|---|---|
| Create the worktree | git worktree add -b … | Automatic |
| Pick a branch name | Your convention | worktree-<name> |
| Pick a base | Whatever HEAD is | Default branch, or HEAD if configured |
Copy .env | A cp in your script | .worktreeinclude |
| Keep the agent out of main | Hope | Enforced per tool call |
| Clean up afterwards | git worktree remove | Prompted on exit |
What the flag actually creates
app/ <- main checkout, your branch
.git/
.gitignore <- contains .claude/worktrees/
.worktreeinclude <- committed; lists .env and friends
.claude/
worktrees/
feature-auth/ <- branch worktree-feature-auth
search-index/ <- branch worktree-search-index
src/
Which commit it branches from
By default a new worktree branches from the repository's default branch on the remote, not from wherever you happen to be standing. The setting is worktree.baseRef, and it takes two values.
worktree.baseRef | Branches from | Use when |
|---|---|---|
"fresh" (default) | The remote default branch, usually main | You want a clean tree matching the remote |
"head" | Your current local HEAD | The agent needs your unpushed, in-progress work |
{
"worktree": {
"baseRef": "head"
}
}
Branching from a pull request
claude --worktree "#1234"
Claude Code fetches pull/1234/head from origin and puts the worktree at .claude/worktrees/pr-1234. A full GitHub pull request URL works too. This is the fastest route to "review this PR without touching what I am doing", which was the original human use for worktrees long before agents existed.
Reusing a name
Passing a name whose directory already exists opens that worktree rather than creating a new one. With the default "fresh" base it also resets to the default branch, but only when the worktree is clean, still on the branch Claude Code made for it, and either has no commits of its own or has had its pull request merged and its remote branch deleted. Anything else, including any reuse under "head", reopens at the old tip. The conservative direction is the correct one: a reset that discards commits should require every condition, not most of them.
Carrying the gitignored files across
A worktree is a fresh checkout, so .env, node_modules, and build output are not there. The config half is solved by a committed file; the dependency half is a normal install.
.env
.env.local
config/secrets.json
Only files that match a pattern and are gitignored are copied, so tracked files are never duplicated. It applies to every worktree Claude Code creates with git: --worktree sessions, subagent worktrees, and desktop parallel sessions alike.
For dependencies, run the install in the worktree, or ask Claude to. If you run several worktrees regularly, move the project to a package manager with a content-addressed store so the second install costs almost nothing.
cd .claude/worktrees/feature-auth
pnpm install --prefer-offline
The isolation is enforced, not requested
This is the part that makes the built-in flag different from a shell script that runs git worktree add and then claude. While a session is isolated in a worktree, Claude Code blocks tool calls that would reach the main checkout. The same checks cover every subagent that session spawns, interactive or background.
Three checks, applied per tool call.
| Check | Blocks |
|---|---|
| File edits | An Edit, Write, or NotebookEdit targeting a path in the main checkout |
| Command working directory | A Bash or PowerShell command whose cwd resolves to the main checkout, or that cannot be verified as staying outside it |
| Git redirects | A command redirecting git into the main checkout via git -C, --git-dir, GIT_DIR, GIT_WORK_TREE, or a cd before the git call |
What a worktree still shares with the main checkout
| Shared | Consequence |
|---|---|
The repository .git directory | git commit works from inside a worktree even with the sandbox on |
| Project-scope plugins | Installed once in the main checkout, loaded in every worktree |
| Saved permission approvals | "Yes, do not ask again" writes to the main checkout's .claude/settings.local.json |
| History, branches, remotes, tags | A commit made in one worktree is immediately visible in all |
The approvals row is the useful one in practice: an approval granted inside a throwaway worktree now applies everywhere and survives that worktree being removed, so you are not re-approving the same test command in every session.
Cleanup, and what happens if you skip it
When you exit an interactive worktree session, Claude Code inspects the worktree for anything removal would destroy: changed files, untracked files, and new commits.
| State on exit | What happens |
|---|---|
| Clean, unnamed session | Worktree and branch removed automatically |
| Clean, named session | You are prompted, so you can keep it for later |
| Has changes or commits | You are prompted to keep or remove |
Non-interactive (-p) | Nothing. There is no exit prompt |
git worktree list
git worktree remove .claude/worktrees/feature-auth
# if it has uncommitted work you have decided to discard
git worktree remove --force .claude/worktrees/feature-auth
# after deleting a directory by hand
git worktree prune -n -v && git worktree prune
Subagents get their own worktrees too
A single session can fan out. Ask Claude to "use worktrees for your agents", or make it permanent for a custom subagent with one line of frontmatter.
---
name: refactorer
description: Applies mechanical refactors across many files
isolation: worktree
---
Apply the requested refactor across every affected file, then run the tests
and report the results.
Each such subagent gets a temporary worktree, using the same base branch rule as --worktree. Claude Code removes it automatically when the subagent finishes with no changes; one that produced changes stays on disk.
When to create the worktree with git instead
The flag covers new work from a clean base. Two cases still want git directly: checking out a branch that already exists, and putting the worktree somewhere other than .claude/worktrees/.
# an existing branch, as a sibling of the repository
git worktree add ../app-bugfix fix-issue-456
cd ../app-bugfix && claude
# a new branch from a specific base
git worktree add -b feature/x ../app-x origin/release-2
cd ../app-x && claude
# read-only look at a tag, no branch involved
git worktree add --detach ../app-v1 v1.0.0
Which route for which job.
| You want | Use |
|---|---|
| A fresh branch for a new task | claude -w <name> |
| To work on a pull request | claude -w "#1234" |
| An existing branch | git worktree add, then claude |
| A path outside the repository | git worktree add, then claude |
| A non-git VCS | A WorktreeCreate hook |
| A tmux pane per session | claude -w <name> --tmux |
Getting the work back, and where this stops scaling
Review the branch diff, not the conversation
cd .claude/worktrees/feature-auth
git diff main...HEAD
One worktree means one clean diff, with nothing from another task mixed into it. Read the diff. The transcript tells you what the agent believes it did.
Open a pull request as usual
git push -u origin worktree-feature-auth
gh pr create --fill
The point of a branch per session is that the result rejoins your normal process instead of needing a special one.
Let the exit prompt clean up
Exit the session and accept the removal. If you left it running with -p, remove it yourself with git worktree remove and delete the branch once it is merged.
- Attention. Past three or four sessions, terminal tabs stop being a usable index of what is running and which one is waiting on you.
- Quota. Consumption scales with sessions, not with your patience. Four agents drain a plan roughly four times as fast, and the failure mode is discovering it mid-task.
- Review. The ceiling that actually binds. Four agents produce more diff than one person reads carefully, and unreviewed agent output is a liability rather than an asset.
Questions people ask
Run claude --worktree <name>, or -w for short, from inside the repository. Claude Code creates a worktree at .claude/worktrees/<name>/ on a new branch called worktree-<name> and starts the session there. Run it again with a different name in another terminal for a second isolated session.
Under .claude/worktrees/<name>/ at the repository root by default. Add .claude/worktrees/ to your .gitignore so they do not appear as untracked files. A WorktreeCreate hook can place them somewhere else entirely.
You can start them, but they will overwrite each other with no error and no warning, and you will not be able to reconstruct which agent did what. Give each one its own worktree.
Add a .worktreeinclude file to the project root listing the paths, using gitignore syntax. Only files that both match a pattern and are gitignored are copied. It is not processed when a WorktreeCreate hook replaces the default logic.
The repository default branch on the remote, which is the "fresh" value of the worktree.baseRef setting. Set it to "head" to branch from your current local HEAD instead, which is what you want when the agent needs your unpushed work.
On exit from an interactive session, yes, with a prompt. A clean unnamed session is removed automatically; anything with changes or commits asks first. Non-interactive runs with -p have no exit prompt and clean up nothing, so remove those with git worktree remove.
Yes. Add isolation: worktree to a custom subagent frontmatter, or ask Claude to use worktrees for its agents. A periodic sweep removes the leftovers, skipping any that still hold changes or unpushed commits.
Three or four before terminal tabs stop being a usable index and before review becomes the bottleneck. Quota is the other constraint: parallel sessions consume the allowance in parallel too.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.