# Use Claude Code worktrees to run parallel sessions without edit collisions

Canonical: https://cwyn.com/pages/claude-code-guide-worktrees.html
Last updated: 2026-11-26T23:08:43-05:00

Claude Code workflow guide

Run `claude --worktree <name>` from the repository root, choosing a different name in each terminal. Each session gets its own branch and edits its own copy of the files in `.claude/worktrees/<name>/`. Add the worktrees directory to `.gitignore`. To copy an ignored file such as `.env` into each checkout, list it in `.worktreeinclude`.

Last updated November 26, 2026 · Published November 23, 2026

By CWYN · Published Nov 23, 2026 · Checked against docs, not run · [Anthropic’s guide to `claude --worktree <name>`](https://code.claude.com/docs/en/worktrees) (as of Nov 26, 2026)

## 1. Quick start for two parallel sessions

1. Trust the repository once. Run `claude` in the repository root, accept the workspace trust dialog, then exit to the shell.
2. Give each task a named worktree. From the repository root, run `claude --worktree feature-auth` in one terminal and `claude --worktree fix-login` in another. One session can build the feature while the other fixes the bug, even when both tasks touch the same file.
3. Install dependencies in each checkout. Run your project’s install command in `.claude/worktrees/feature-auth/`, then in `.claude/worktrees/fix-login/`. Each worktree starts as a fresh checkout.
4. Decide what to keep on exit. Choose Keep to save the worktree directory and branch. Save the resume command Claude prints. Choose Remove to delete the directory, its branch and the work in them.

Already in a session? Ask Claude to “work in a worktree.” Claude uses `EnterWorktree` to move the session into a separate checkout.

## 2. Choose your worktree settings

| Option | What it does | When to use it |
| --- | --- | --- |
| `--worktree` or `-w` | Creates a checkout on a new `worktree-<name>` branch. Omit the name and Claude generates one. | Name a task you plan to return to, or let Claude name a short experiment. |
| `worktree.baseRef` | `fresh` , the default, branches from the remote default branch, usually `main` . `head` branches from your current local `HEAD` . | Choose `head` when the task needs commits you have yet to push. |
| `.worktreeinclude` | Copies gitignored files that match its patterns into each new worktree. | Bring a local file such as `.env` or `.env.local` into each checkout. |
| `isolation: worktree` | Gives a custom subagent its own worktree when set in its frontmatter. | Let a subagent edit its own copy of the files during your session. |
| `cleanupPeriodDays` | A periodic sweep removes worktrees Claude created for subagents and background sessions once they exceed this age. | Set how long to retain those worktrees. |
| `claude --worktree "#1234"` | Creates a worktree for the pull request at `.claude/worktrees/pr-1234` . | Start from a proposed change. Quote the PR number, or pass a GitHub PR or GitLab MR URL. |

To start worktrees at your local `HEAD`, put this object in your Claude Code settings. See [which settings.json file applies to your project](https://cwyn.com/pages/claude-code-guide-settings-json-precedence.html).

```
{
  "worktree": {
    "baseRef": "head"
  }
}
```

`worktree.baseRef` accepts only `fresh` and `head`. To start from a specific branch name, create the worktree directly with Git.

## 3. Worktree vs. branch vs. subagent

- A branch tracks a line of commits. If two terminals use the same working directory, both sessions see the same files.
- A worktree pairs a branch with its own working directory. Each session edits a separate copy of the files, and both worktrees share the repository history and remote.
- A subagent takes on part of a task inside one Claude Code session. Give the subagent a worktree when its edits need a separate checkout.

If you want to stay in the same checkout and just need room in the conversation, see [when to use /compact or /clear](https://cwyn.com/pages/claude-code-guide-compact-vs-clear.html).

## 4. Troubleshoot a worktree

### Claude exits and asks for workspace trust

Run `claude` once in the repository and accept the trust dialog. Exit and retry the named worktree command. A non-interactive `claude -p --worktree` run skips this trust check.

### The .env file is missing

Check that Git ignores the file and that the project root contains a `.worktreeinclude` pattern matching it. The file uses `.gitignore` syntax. To copy both of these ignored files, add one pattern per line before creating the worktree.

```
.env
.env.local
```

Claude copies matching ignored files when it creates a worktree. If a `WorktreeCreate` hook replaces Git, Claude skips `.worktreeinclude`.

### Claude refuses to create the directory

Check `.claude`, `.claude/worktrees` and the target worktree directory for a symlink. If one of those paths is a symlink, remove that link and retry the command.

### A worktree is still on disk after a print-mode run

A `-p` run has no exit prompt and leaves the worktree in place. Review its files and branch before cleaning it up yourself. See [how Claude Code print mode works](https://cwyn.com/pages/claude-code-guide-headless-print-mode.html).

### I kept a worktree and want to resume it

Use the `claude --worktree --resume` command Claude printed when you chose Keep. It takes you back to the directory and branch that hold your edits.

## 5. Claude Code worktree FAQ

### Where are Claude Code worktrees stored?

Look under `.claude/worktrees/<name>/` at the repository root. For a worktree named `feature-auth`, the directory is `.claude/worktrees/feature-auth/` and the branch is `worktree-feature-auth`.

### Does a worktree start from my current branch?

By default Claude starts the new branch at the remote default branch. Set `worktree.baseRef` to `head` to start at the current local commit and include your unpushed commits.

### How do I clean up a worktree?

Exit the interactive session. Claude removes a clean unnamed worktree and its branch automatically. A named worktree prompts first, even if clean. Changes, untracked files or new commits also trigger a prompt. Choose Keep to preserve the directory and branch or Remove to delete both and their work.

### Can subagents use worktrees?

Yes. Ask Claude to “use worktrees for your agents.” For a custom subagent, add `isolation: worktree` to its frontmatter so it gets its own checkout.

## Next steps

- [All 34 Claude Code guides](https://cwyn.com/guides/claude-code/)
- [Claude Code setup walkthrough](https://cwyn.com/setup/claude-code/)
- [Free setup file checker](https://cwyn.com/score/setup-file-checker/)

Plan for parallel Claude Code sessions

[Free AI cost calculator](https://cwyn.com/score/ai-cost-calculator/?tool=claude)

Count sessions across your worktrees and enter the tokens per session to estimate their combined monthly API cost.

[Claude Code Complete Setup Pack ($12.95)](https://cwyn.com/pages/pack-claude-code-complete-setup-pack.html)

Use the starter CLAUDE.md to record the test command every worktree should run before its branch is merged.

### Check the instructions your sessions use

[Check your CLAUDE.md with the free setup file checker](https://cwyn.com/score/setup-file-checker/)

## Email me the CLAUDE.md + settings starter

Get the editable CLAUDE.md template and a project setting you can merge into .claude/settings.json.

Email address

Email me this file. Also send up to 4 short follow-up emails with tips and one related CWYN product. Unsubscribe any time. [Privacy policy](https://cwyn.com/pages/privacy.html)

### Set up a Claude Code project

Use the project instructions in the [Claude Code Complete Setup Pack ($12.95)](https://cwyn.com/pages/pack-claude-code-complete-setup-pack.html) to record which tests to run in each worktree before merging its branch.

Claude Code Complete Setup Pack $12.95

Set up project instructions, permission rules, hooks, a reviewer skill and subagent, and MCP connections for Claude Code.
