Run parallel sessions with worktrees changedworktrees
Nearest release: v2.1.332, published 3 hours after upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 24 Nov 2026 18:30 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 24 Nov 2026 18:37 UTC.
Upstream edited
Recorded here
Lines+10added
Lines−6removed
From line
68
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits48to this page, all time
### Resume without `--worktree` ### Transcript location
The whole hunk
from line 68, old and new numbered
/
from line 68
6868
6969* **Claude Code finds another session in the worktree**: the worktree and branch stay even if you choose removal. Follow the `Worktree kept at` message
7070* **The worktree is clean**: for an unnamed session, Claude removes the worktree and its branch automatically. A [named](https://code.claude.com/docs/en/sessions.md#name-your-sessions) session prompts you first so you can keep the worktree for later
71* **The worktree has work in it**: Claude prompts you to keep or remove the worktree. Keeping preserves the directory and branch. To return later, run the `claude --worktree <name> --resume` command that Claude Code prints on exit. Removing deletes the worktree directory and its branch, along with all the work in them
71* **The worktree has work in it**: Claude prompts you to keep or remove the worktree. Keeping preserves the directory and branch so you can [return later](#resume-a-worktree-session). Removing deletes the worktree directory and its branch, along with all the work in them
7272* **Another branch is checked out**: if the worktree is on a branch other than its own that has commits past the worktree's starting commit, Claude prompts you to keep or remove the worktree. Either answer keeps that other branch and its commits. Removing deletes the worktree directory and the worktree's own branch, the one Claude created with it
7373* **The worktree's state can't be verified**: when Claude Code can't count the worktree's changes or can't inspect its submodule checkouts, it prompts you rather than removing the worktree automatically. The prompt names what it couldn't check
7474
from line 78
7878
7979## Resume a worktree session
8080
81To return to a worktree you kept, run `claude --worktree <name> --resume <session-id>` from the main checkout, using the session ID printed on exit. For `<name>`, type the folder name under `.claude/worktrees/` with `/` in place of any `+`.
82
83### Resume without `--worktree`
84
8185When you resume a session that ended [isolated](#how-claude-code-enforces-isolation) in its worktree without [exiting it](#clean-up-worktrees), Claude Code returns the session there and keeps it isolated. This holds for interactive resumes, for `--continue` and `--resume` in [non-interactive mode](https://code.claude.com/docs/en/headless.md) with `-p`, and for the Agent SDK. Back inside the worktree, Claude can leave with the [`ExitWorktree`](https://code.claude.com/docs/en/tools-reference) tool [when the session has that tool](#claude-has-no-enterworktree-tool).
8286
8387Before returning the session to its worktree, Claude Code verifies that the worktree is still a checkout separate from the main one, and declines to re-enter a worktree that fails the check. For a git worktree, the check reads its git metadata. A worktree without git metadata, such as one a [`WorktreeCreate` hook](#non-git-version-control) created, can pass the check; the cases Claude Code still refuses are listed with their recoveries under [Claude Code refuses to use a worktree](#claude-code-refuses-to-use-a-worktree). For the messages and how to recover from each, see [The session resumes outside its worktree](#the-session-resumes-outside-its-worktree).
from line 97
9397>
9498> Before v2.1.212, a non-interactive resume stayed in the starting directory and `ExitWorktree` reported that there was no active worktree session to exit.
9599
100### Transcript location
101
96102When Claude enters or exits a worktree that Claude Code created with git, the transcript follows. Claude Code records the session under the session's new working directory, the same way [`/cd`](https://code.claude.com/docs/en/commands) does, so `/desktop` and `--resume` find it there. Exiting moves it back the same way. A worktree created by a [`WorktreeCreate` hook](#non-git-version-control) keeps its transcript at the launch directory.
97103
98104## How Claude Code enforces isolation
from line 153
147153* A checked-out submodule in the worktree holds changed or untracked files, or Claude Code can't inspect the worktree's submodules. This check requires Claude Code v2.1.274 or later.
148154* One of the [four cases that also block worktree creation](#git-lfs-content-is-missing-from-a-worktree-claude-code-created) applies: Claude Code can't determine which filter drivers the repository config defines, or finds a setting there it can't switch off.
149155* The worktree belongs to a `--worktree` session you haven't backgrounded, whatever its age.
150* You created the worktree yourself with `git worktree add`, even if you then ran a `--worktree <name>` session in it and backgrounded that session.
156* You created the worktree with `git worktree add` outside `.claude/worktrees/`.
151157
152Claude Code writes a marker into the git metadata of every worktree it creates with git, and the sweep keeps any worktree without one, including a worktree a [`WorktreeCreate` hook](#non-git-version-control) created.
153
154158#### Worktree locks and manual removal
155159
156160While an agent is running, Claude Code holds a `git worktree lock` on its worktree so that concurrent cleanup can't remove it, and releases the lock when the agent finishes. Claude Code holds the same lock on the worktree it created for a backgrounded session while the session runs, so the sweep leaves the worktree in place and `git worktree remove` refuses to remove it.
from line 200
196200claude --worktree "#1234"
197201```
198202
199Claude Code reads only the number from the URL. It always fetches from your repository's `origin` remote, and picks the fetch path by `origin`'s host:
203Claude Code ignores the host and repository in a URL you pass, and picks the fetch path by `origin`'s host:
200204
201205* **github.com**: fetches `pull/<number>/head`
202206* **gitlab.com**: fetches `merge-requests/<number>/head`
203* **GitHub Enterprise, self-managed GitLab, or any other host**: tries `pull/<number>/head` first, then `merge-requests/<number>/head`
207* **GitHub Enterprise, self-managed GitLab, or any other host**: uses `pull/` for a pull request URL, `merge-requests/` for a merge request URL, and whichever exists for a `#` number. If both exist at different commits, follow the `Cannot use PR/MR #<number>` message.
204208
205209This fetch never waits for input in your terminal. If git or ssh would ask for a password, a key passphrase, or confirmation of a new SSH host, the fetch fails instead and Claude Code exits with an `Error creating worktree: Failed to fetch PR/MR #<number>` message. A key that `ssh-agent` holds still works, so load your key there and run `git fetch` once by hand to record a new host before you start.
206210
No line in this hunk matches that.