Worktree

A worktree (git worktree) is a separate working folder of the same git project, with its own files and its own branch but a shared history. In Claude Code, the --worktree (or -w) flag creates one under .claude/worktrees/ and starts Claude inside it. This lets several Claude sessions work in parallel without their changes colliding with each other.

A second working copy of the same project, in another folder, so two Claude sessions can work in parallel without getting in each other’s way.

You’ll also find it as: worktrees, git worktree

How it shows up in Claude Code

If two Claudes work in the same folder, one can change a file the other was just reading. Worktrees solve this: each session gets its own copy of the files.

The command claude --worktree new-feature creates the folder .claude/worktrees/new-feature/ on a new branch, worktree-new-feature, which by default starts from the repository's main branch. Run the command again with another name in a second terminal and you have two isolated sessions. The repository needs at least one commit first.

When you exit, if the worktree has no changes, Claude Code removes it automatically (for unnamed sessions). If it does have changes, it asks whether to keep or remove it. Subagents can also each work in their own worktree.

Example

In the first terminal you build a new page; in the second you fix a bug:

claude -w contact-page
claude -w form-fix

If you prefer plain git commands, as in the course:

git worktree add ../project-a -b feature-a
cd ../project-a && claude

Common mistakes

  • Forgetting that a worktree is a fresh checkout: files git ignores, such as .env, aren't there. You can copy them automatically with a .worktreeinclude file, and packages need installing again.
  • Not adding .claude/worktrees/ to .gitignore. The documentation recommends it, so the folders don't show up as new files in your main checkout.
  • Removing a worktree with changes you haven't committed. They're lost.

Related terms and where you learn it

A worktree builds on git and a branch; each one has its own session. It's also handy for a subagent making large changes.

In the course: the lesson “How do you work with several Claudes in parallel? (git worktrees)” in module 11, Pro tips.

Source: Claude Code documentation: Run parallel sessions with worktrees

How it appears in the course

You can have several Claudes working in parallel, each in its own copy of the project (git worktrees).

Introduction · Module 11, Pro tips

The third is a worktree (a working copy of the project, in a separate folder, tied to a branch).

How do you work with several Claudes in parallel? (git worktrees) · Module 11, Pro tips

A worktree is a separate copy of your project where Codex works without touching your main version.

Introduction · Module 06, Cost, context and parallel work

Learn Claude Code from zero, in plain English

12 modules with 1–2 minute lessons, which you can also do on your phone. The first two modules are free.