Skip to content
zero2vibecodelearn vibe coding
Level 4 · Parallel work 9 min Reviewed by the author · Oct 15, 2026 Verified against Claude Code v2.1.292 · Oct 15, 2026Official docs: WorktreesSomething out of date? Tell us

Parallel sessions in worktrees

claude --worktree starts a session in a separate working folder on its own branch. Two sessions each edit their own copy of the files, and the work comes back through git merge from the main folder. Prepare .gitignore, remember .worktreeinclude, and know which branch a worktree starts from.

Level 4 · 0 / 4 lessons0%
In this lesson

You want one Claude session to fix the documentation while another adds a test at the same time. Start both in the same folder and they will edit the same files and get in each other’s way. You need a second working folder.

What a worktree is

A is another working folder of the same repository, on its own . The folders share history, but each has its own files.

claude --worktree docs-pass

Claude Code creates the folder .claude/worktrees/docs-pass/ on a new branch worktree-docs-pass and starts a session in it. The short form is claude -w docs-pass. That session’s edit tools do not touch your main folder, and its commands do not run there or point git at it.

One condition: you must have run claude in this repository at least once and accepted the folder trust prompt. Otherwise claude --worktree exits with an error.

What is shared and what is not

Shared by all worktreesEach worktree has its own
commitsuncommitted edits
branchesinstalled dependencies (node_modules)
historyfiles git ignores, such as .env

Every worktree is a fresh checkout from git. So the session in a second worktree will have to install dependencies first.

Preparing the project

1. Keep the worktrees folder out of git. Otherwise their contents show up in the main folder as untracked files:

echo '.claude/worktrees/' >> .gitignore
git add .gitignore && git commit -m "Ignore Claude Code worktrees"
git push

Ignore exactly .claude/worktrees/, not the whole .claude/: that folder holds settings and skills you commit for the team.

2. Put the ignored files you need in .worktreeinclude. If the project needs .env to run, list it in a .worktreeinclude file at the repository root, and it is copied into every new worktree:

echo '.env' > .worktreeinclude

List only what is necessary: every worktree gets its own copy of every secret.

Which branch a worktree starts from

A new worktree branches off the main branch on the remote, not your local HEAD. Unpushed commits and work from your feature branch will not be in it. That is why step 1 ended with git push.

If you need to start from your local HEAD, add this to .claude/settings.local.json:

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

Without a remote, a worktree starts from your local HEAD anyway.

Bringing the work back

Each session commits on its own branch. You do the merging — from the main folder, in a separate terminal:

git worktree list
git merge worktree-docs-pass
git merge worktree-test-pass

You merge yourself: while a session is isolated in a worktree, Claude Code blocks its git commands that reach into the main folder. If both tasks changed the same lines, git stops at a conflict — resolve it, or start claude in the main folder and ask for help.

Then type /exit in each session. If the worktree’s branch has new commits, Claude Code asks whether to keep the worktree or remove it. After merging, choose remove.

Quick check

A worktree session cannot see the commit you made an hour ago. Why?

Careful

Practice in the terminal

Check your understanding

Answered 0/3
Mode:

What does claude --worktree docs-pass do?

What state does a new worktree start from by default?

In a worktree session you answered "Yes, and don't ask again" to a shell command. Where is that permission saved?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Prepare the project for parallel sessions: keep the worktrees folder out of git, ask for .env to be copied into every worktree, and start the first session in a worktree named docs-pass.

Tab complete · ↑ history · Ctrl+L clear · help commands

  • Not done: The .claude/worktrees/ folder is kept out of git
  • Not done: .env is copied into every new worktree
  • Not done: A session started in the docs-pass worktree

Lesson Q&A

What does claude --worktree docs-pass do?

Creates .claude/worktrees/docs-pass/ on a new branch worktree-docs-pass and starts a session in it — A worktree is a second working folder on its own branch with shared history. The session edits its own copy of the files, and your main folder stays untouched.

What state does a new worktree start from by default?

The main branch on the remote — your unpushed commits are not in it — That is why the .gitignore rule should be committed and pushed. If you need your local HEAD, add "worktree": {"baseRef": "head"} to .claude/settings.local.json. Without a remote, a worktree starts from your local HEAD anyway.

In a worktree session you answered "Yes, and don't ask again" to a shell command. Where is that permission saved?

In the main folder's .claude/settings.local.json — and it applies everywhere in the repository, even after the worktree is removed — In most repositories on macOS, Linux and WSL 2, the rule goes into the main folder's local settings. Only approve that way what you would allow everywhere.

A worktree session cannot see the commit you made an hour ago. Why?

Push the commit before starting the worktree, or set worktree.baseRef to head in .claude/settings.local.json.

Commands in this lesson

Terms in this lesson

Move between lessons with ← → · search with ⌘K

Written and reviewed by Mikhail Kuzmitskii