GuidesHosting choices

Claude Code worktrees: parallel sessions on one repository

Run Claude Code sessions in parallel with claude --worktree: where worktrees go, .worktreeinclude for .env, subagent isolation, git worktree add, and cleanup.

November 23, 2026The Everpod team
The short answer

Start each session with claude --worktree <name> (or -w). Claude Code creates a git worktree at .claude/worktrees/<name>/ in your repository, on a new branch called worktree-<name> cut from the remote’s default branch, and starts the session there. Run the same command with another name in a second terminal and the two sessions edit separate copies of the files. There is no /worktree slash command: inside a running session you ask Claude to “work in a worktree”, and a subagent gets its own with isolation: worktree. Each worktree is a fresh checkout, so install dependencies in it, list your .env files in a .worktreeinclude file so they are copied in, and give each one’s dev server its own port. On exit Claude removes a clean worktree and asks about one with work in it; anything left over goes with git worktree remove and git worktree prune.

Starting sessions with --worktree

From anywhere in the repository, as Anthropic’s worktrees page describes it in November 2026, when 2.1.331 is the newest release:

claude --worktree feature-auth     # .claude/worktrees/feature-auth, branch worktree-feature-auth
claude -w bugfix-123               # in a second terminal: a second, separate checkout
claude -w                          # no name: Claude picks one, such as bright-running-fox
claude -w feature-auth --tmux      # the same, opened in its own tmux session
claude --worktree "#1234"          # branch from pull request 1234: .claude/worktrees/pr-1234
Copied

On a remote machine, --tmux is the short way to get a session that survives a dropped SSH connection; what tmux does explains the attach and detach. One catch from the docs: Claude Code isolates a session started with --worktree but not --tmux, or one Claude moves with EnterWorktree, so a --tmux session does not get the checks described next.

Inside a session: no /worktree command

The command list in Claude Code’s docs has no /worktree. In a session already running, say “work in a worktree” and Claude calls its EnterWorktree tool, which creates one under .claude/worktrees/ and moves the session’s working directory there; it can switch to another worktree the same way, leaving the old one on disk. Entering a path outside .claude/worktrees/ asks you first, whatever your permission rules say; only bypassPermissions mode skips the question. If Claude says it has no such tool, look for permissions.blockWritesOutsideWorkingDirectories in your settings: with it on, Claude Code removes both worktree tools, and claude --worktree at launch is the way in.

Once a session is isolated, Claude Code refuses its edits to files in the main checkout, commands whose working directory is the main checkout, and git pointed back at it with git -C, --git-dir, GIT_DIR or GIT_WORK_TREE. The docs are plain about the gap: the checks read paths and command text, so a cp or a shell redirect into the main checkout is not refused by them. Hooks also keep pointing at the original project: inside a worktree, ${CLAUDE_PROJECT_DIR} is still the main checkout, and a hook that needs the worktree reads the cwd field of its input.

In the desktop app the same thing is a Worktree switch under the prompt box, off by default, storing worktrees in the same folder unless you set Worktree location in its settings.

What a new worktree does not have

Git checks out tracked files and nothing else. Everything your .gitignore keeps out of the repository is missing from a new worktree, and that is usually what stops the second session from running anything:

MissingWhat to do
Dependencies (node_modules, a virtualenv, build output)
Run the project’s install in the worktree, or ask Claude to. To share one copy instead, worktree.symlinkDirectories symlinks listed directories from the main checkout into each new worktree. A symlinked directory is one directory, so an install run in any worktree changes it for all of them.
.env and other secrets files
List them in .worktreeinclude at the repository root (below). Only files that match a pattern and are gitignored are copied.
A free port
Two dev servers cannot listen on the same port. Give each worktree’s server its own, for example by changing the port in that worktree’s copy of .env if your project reads it from there.
Git LFS files
If LFS was set up with git lfs install --local, worktrees Claude Code creates hold pointer files. Run git lfs pull inside the worktree.
The whole tree, in a large monorepo
Not missing, but slow: worktree.sparsePaths checks out only the listed directories plus root-level files. Include .claude so the project’s settings come along.
# .worktreeinclude, at the repository root (.gitignore syntax)
.env
.env.local
config/secrets.json
Copied

And in .claude/settings.json:

{
  "worktree": {
    "baseRef": "head",
    "symlinkDirectories": ["node_modules"]
  }
}
Copied

Claude Code reads .worktreeinclude when it creates a worktree with git: from --worktree, from EnterWorktree, for subagents and in the desktop app. A worktree you make with git worktree add is not one of those, so copy the files into it yourself. Some things are shared rather than copied: the repository’s .git directory (and so its config and branches), plugins installed at project scope, and permission approvals. Choosing “Yes, and don’t ask again” for a command in a worktree saves the rule to the main checkout’s .claude/settings.local.json, where it applies to every worktree and outlives the one you were in (on Windows it stays with that worktree).

Subagents, background sessions and agent teams

For several long-running sessions that one of them directs, running many agents from one puts worktrees together with tmux and messages between sessions.

The plain git route

git worktree add is the way to put a worktree outside the repository, start from a branch that already exists, or use a branch name of your own. Claude Code then runs in it like any other folder:

cd ~/code/app
git worktree add ../app-feature-a -b feature-a   # new branch from HEAD
git worktree add ../app-bugfix fix-issue-456     # existing branch
cd ../app-feature-a && claude
Copied

Git will not check out one branch in two worktrees: per the git-worktree manual, add refuses a branch “already checked out by another worktree” unless you pass --force, and -b refuses a branch name that exists. Two things change on this route: nothing copies your .worktreeinclude files in, and Claude Code’s periodic sweep never removes a worktree you created, so cleaning up is yours. Resuming works from either place: given a session ID, claude --resume searches the current project and its git worktrees first.

Cleaning up

What Claude Code does when you leave an interactive worktree session:

State of the worktreeOn exit
Clean, session not named
Removed, with its branch
Clean, session named
Asks whether to keep it
Changes, untracked files or new commits
Asks: keep (directory and branch stay; it prints the claude --worktree <name> --resume command to come back) or remove (deletes the work)
Another Claude Code session working in it
Kept, even if you chose removal, with a Worktree kept at message
State cannot be checked
Asks, naming what it could not check
Started with -p
Nothing: no prompt, no cleanup, and its lock stays until a later sweep

The case of another session still working in the worktree was a bug until 2.1.330, which “Fixed ExitWorktree and the worktree exit dialog deleting a worktree that another running Claude Code session was working in”; run claude update if you share worktrees between sessions. Worktrees made for subagents and background sessions are swept once they are older than cleanupPeriodDays (30 by default), except those still holding changes or unpushed commits.

Everything else is git’s own commands:

git worktree list                                  # every worktree, with "locked" or "prunable"
git worktree remove .claude/worktrees/feature-auth   # only if clean
git worktree remove --force <path>                 # discards uncommitted changes and untracked files
git worktree unlock <path>                         # if remove refuses a locked worktree
git worktree prune                                 # forget worktrees whose folders were deleted by hand
git branch -d worktree-feature-auth                # the branch stays until you delete it
Copied

remove refuses a worktree with untracked files or modified tracked files until you add --force, and a locked one until you unlock it or give --force twice. Claude Code holds a lock on a worktree while an agent or background session runs in it, so a refusal there usually means something is still working. If you deleted a worktree’s folder with rm, prune clears the record git keeps of it, which otherwise lingers until garbage collection.

Run Claude Code on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.