What this thread does
Do first: Use a git repository with at least one commit, then run claude --worktree feature-auth in one terminal and a different name in the next.
Short answer
As of November 2026, --worktree (-w) isolates checkout files and branches, while git history remains shared. Install project dependencies inside each fresh checkout.
What to do
| Choice | Value / behavior |
|---|---|
| Create session | claude --worktree feature-auth; another terminal uses another name |
| Default location / branch | .claude/worktrees/<name>/ / worktree-<name> |
| Omitted name | Claude generates a name |
| Base setting | worktree.baseRef: "fresh" default = remote default branch; "head" = current local HEAD; arbitrary branch names are not accepted |
| Fresh-base fetch | Refresh after 24 hours without a fetch, capped at five seconds; failed fetch uses cached ref; absent remote/cached ref falls back to local HEAD |
| Interactive trust | Run claude once in an untrusted directory to accept workspace trust before using the worktree flag |
| Non-interactive | claude -p --worktree skips the trust check; -p does not clean up on exit |
| Resume retained work | claude --worktree <name> --resume |
| List / remove / unlock | git worktree list; git worktree remove; git worktree unlock if locked |
| Ignore checkouts | Add .claude/worktrees/ to .gitignore |
| Carry ignored files | Root .worktreeinclude uses .gitignore syntax; copies only matching gitignored files, never tracked files |
On interactive exit, a clean unnamed session removes its worktree and branch; a named session prompts first. Changed or untracked files, new commits or uncertain state produce a keep/remove prompt. Keep preserves the directory and branch; removal discards work there. An alternative checked-out branch with later commits is preserved either way.
Reusing a name opens its existing checkout. With "fresh", it resets only when sandbox writes are unrestricted, the checkout is clean, it remains on its created branch, and it has no own commits or its merged remote branch was deleted. Otherwise it stays at its old tip; "head" also keeps that tip. With sandboxing and a fresh base, run git fetch origin and use a new name to pick up the latest default branch.
For subagent isolation use isolation: worktree in a definition under .claude/agents/. WorktreeCreate / WorktreeRemove hooks replace git creation and cleanup for another VCS; .worktreeinclude is then not processed.
Limits and open questions
Worktrees share git metadata, project-scope plugins and remembered Bash approvals. File-edit and git-directory checks do not track every shell write, so filesystem sandboxing still matters. No universal port isolation is stated. The pages give no minimum release for the basic two-terminal recipe.
Not for: Claude Code Desktop worktree setup.
Sources
- Worktree guide, Anthropic.
- Common workflows: parallel sessions, Anthropic.
Checked
2026-11-16; read Worktree guide; Common workflows: parallel sessions; no command was run.
Started from a post by @Anthropic, packaged by the editor. Original post