Claude Worktree

Run Claude Code sessions in separate Git worktrees. Start two features, test a pull request, isolate a subagent and decide which files survive cleanup.

Published

Claude Worktree

You can leave Claude Code building a sign-in flow, open a second session to add search, and review either change while the other is still in progress. Give each session a Git worktree before it starts editing. Otherwise, a second terminal pointed at the same folder gives both sessions the same files to overwrite.

A worktree is a separate folder with its own checked-out files and branch, the line of changes you’ll review together.
It shares the original repository’s history and remote, the place you fetch from and push to.

Think of two architects taking plans from one archive. Each can mark up a copy on a separate bench. The decision about which changes belong in the final plan comes later, when the branches merge.

One shared history drawer supplies separate workbenches for the auth and search branches.
The archive is shared. Each session edits the files on its own bench.

Start two features in separate terminals

From the repository folder, start the sign-in task in its own worktree. If this is your first interactive session in the repository, run claude there once and accept the workspace trust prompt. Start the session with this command.

Bash
claude --worktree feature-auth

Ask this session to add the sign-in form. Its files live under .claude/worktrees/feature-auth/ on the new branch worktree-feature-auth. By default, a new worktree branches from the repository’s default branch. If you have an unfinished form in your main folder, plan on leaving it there.

Open another terminal in the original repository folder. Run claude --worktree feature-search and ask for the search filter. The command pattern is claude --worktree <name>. Pick a different name for each job. You can now inspect the search changes without asking the sign-in session to stop, save its place or switch branches. Add .claude/worktrees/ to your project’s .gitignore to keep these folders out of the main checkout’s list of untracked files.

Already talking through a task? Before Claude edits, ask it to “work in a worktree.” Claude creates one with its EnterWorktree tool. For the surrounding terminal workflow, see the Claude Code CLI guide.

Pick up a pull request while the feature stays open

A maintainer gets a review request halfway through testing sign-in. From the main repository, open another terminal and pass the pull request number in quotes.

Bash
claude --worktree "#1234"

Keep the quotes so the shell passes the hash through. Claude fetches the latest commit for that request from origin, your configured remote, and creates .claude/worktrees/pr-1234. Ask Claude to reproduce the reported failure there. The result tells you something about the submitted code, and the half-finished sign-in form stays exactly where you were testing it.

Give a helper, a reviewer or a release lead a workspace

A developer delegating a refactor can stay in the feature conversation and ask Claude to “use worktrees for your agents.” A subagent is a helper Claude sends to do one job. For a recurring helper, put isolation: worktree in the configuration header of its definition in .claude/agents/. A helper could rename an old test utility and run the affected tests in its checkout while you review a separate change. Give it a task it can do from the base branch. A clean helper worktree can disappear when the helper finishes. Changes, untracked files or new commits leave it available for inspection, subject to later cleanup. See how to define a Claude Code subagent.

A release lead comparing two fixes in Desktop can use + New in the Code tab for each approach. Select the Git project and turn on Worktree under the prompt box before starting each session. The switch is off by default. In the older layout, the checkbox sits beside the branch name. Now one conversation can try a narrow fix while the other tries replacing the faulty component. Run the same failing test against each before choosing which branch to keep. Desktop worktree controls

A maintainer supporting a non-Git project can give developers the same separate-folder workflow if the team supplies the checkout logic. For example, an SVN team could configure a WorktreeCreate hook, a script Claude calls to create a fresh working copy and print its path. Pair it with WorktreeRemove for cleanup. The creation hook replaces the built-in Git setup, including the copying of local configuration files. Put that copy step in the hook itself.

Fix the three collisions that show up in practice

What you seeWhat to do
The app works in your main folder, but the new checkout cannot find a dependency.Run the project’s setup inside the new worktree, or ask Claude there to install the dependencies. For local configuration such as an ignored .env, add a line containing .env to .worktreeinclude at the project root before creating the next worktree. It uses .gitignore patterns and copies files only when they’re both matched and ignored.
The second dev server reports that its port is busy.Give each running server a free port. For Desktop previews, set "autoPort": true in the server entry in .claude/launch.json and have the server read PORT. If a sign-in callback requires an exact port, stop the other server before testing that callback. Desktop preview port settings
Both branches changed the same file.Check which lines changed. Git can combine edits to different parts of a file. If both branches rewrote the same lines differently, resolve the conflict, stage the resolved file and finish the merge. Then test both behaviors together. Git’s merge-conflict walkthrough
Two benches produce competing staircase designs for one reviewer to reconcile.
Separate checkouts protect edits in progress. Someone still decides how overlapping changes fit together.

If sign-in and search both need to redesign the same navigation component, settle its interface first or assign that component to one session. Adding another checkout won’t settle a design disagreement. The guide to Claude Ultracode covers how much effort to give a task once you’ve defined it. For teams using both coding agents, the Codex CLI worktree walkthrough covers the other tool’s commands.

Decide what survives when you exit

For an interactive session in a worktree Claude created with Git, keep preserves the directory and its branch. Remove deletes both, including work held only there. Claude checks for changed and untracked files, new commits and uncommitted work in checked-out submodules.

  • Clean worktree, unnamed session: Claude removes the worktree and its branch automatically. A named session gets a prompt first. Giving the folder a name with --worktree feature-auth is a separate choice.
  • Work present or state uncertain: Claude asks whether to keep or remove the worktree. If another session is still using it, Claude keeps it. If you checked out a different branch with commits beyond the starting point, that other branch and its commits survive either choice.
  • Only an ignored file changed: Copy out anything you need before exit. Editing a local .env alone doesn’t count as work for cleanup.
  • Coming back tomorrow: From the main checkout, run claude --worktree <name> --resume <session-id> with the ID printed on exit. A non-interactive -p run has no exit prompt and leaves its worktree behind. Claude also leaves a lock on that worktree. If Git reports that the worktree is locked when you try to remove it, run git worktree unlock <path> first. For manual cleanup, use git worktree remove with the worktree path after checking what you want to keep.

Two tools worth building around the checkout

Build the setup check first. A team that runs several local services could pay for a repo-specific check that answers “Can I run this branch here?” The smallest version would run the team’s existing setup command, check for the expected local configuration and report the preview address for each worktree. Developers already look for ways to manage multiple Git branches. Before charging for it, watch a developer open a second checkout. How much work does it take to get a working preview? If adding one line to the setup script fixes it for everyone, ship that line.

A pull request test launcher could serve a maintainer who repeatedly reproduces UI bugs. Give it a request number and have it open the checkout, run the project’s prescribed test and show the result alongside the commit tested. Developers explicitly search for how to test a pull request locally, and paid Git clients already bundle pull request tools. Tower lists its individual Basic plan at $69 per user annually before promotions. That gives a buyer a price for a broader product. A launcher would need to earn its place through project-specific testing, since Claude already opens the checkout in one command. Tower’s plan details

How do I check out a Git worktree in Claude Code?

Run claude --worktree feature-auth from your repository. Claude creates the folder and branch and starts the session inside them. Use a pull request number in quotes when you want to start from a submitted change.

Does Git worktree copy all files?

A fresh checkout contains tracked files from the starting commit. Your ignored local files need a separate step. With Claude’s built-in Git setup, list the ignored files you need in the project’s .worktreeinclude. Install project dependencies in the new folder as needed.

What are the best practices for using Git worktrees?

Choose tasks you can test independently, give each checkout a descriptive name and decide who owns any shared interface. Before removing a checkout, review its changes and copy out any local configuration you edited there.

On Monday, take the next review request in its own worktree while your feature stays open. Run the failing test there. If setup takes longer than the review, you’ve found the first step to automate. For a first project, the Claude Code setup guide covers the basics. If your next decision is where to edit and review those branches, compare the best AI code editors.

Published
Category
Build
Related Articles
AgentMail: What It Is, What It Costs, and How to Start

AgentMail: What It Is, What It Costs, and How to Start

Give an AI agent its own email address. See the first inbox call in Python, the free plan’s limits, and when Gmail or SMTP fits better.Dec 2, 2026Build
Antigravity CLI in Claude Code and Codex: The Setup Google Allows

Antigravity CLI in Claude Code and Codex: The Setup Google Allows

Google's terms now let Claude Code or Codex call the Antigravity CLI as a subagent. The exact rule, what stays forbidden, and a setup built from the docs.Dec 2, 2026Build
LM Studio: What It Is and How to Run Your First Local Model

LM Studio: What It Is and How to Run Your First Local Model

Find the LM Studio desktop installer, choose a model that fits your memory, chat offline, and send your first request to its local server.Dec 2, 2026Build
Kiro Crew: What Teams Share and How to Get Started

Kiro Crew: What Teams Share and How to Get Started

How a shared Kiro Crew turns review feedback into team skills, who can join, what the crew seat costs and how to connect your first host.Dec 2, 2026Build
How to Install Claude Code on macOS, Linux and Windows

How to Install Claude Code on macOS, Linux and Windows

Install Claude Code on macOS, Linux or Windows. Choose your terminal, verify the install, sign in, fix common errors and update or uninstall it.Dec 2, 2026Build
Claude Managed Agents on Amazon Bedrock and the Claude API

Claude Managed Agents on Amazon Bedrock and the Claude API

Choose between the Claude API and Amazon Bedrock, see who runs the tools and bills usage, and create an agent with Anthropic’s documented request.Dec 1, 2026Build
Harness Tuned for One Model, Run on Another: What Google's Papers Measured

Harness Tuned for One Model, Run on Another: What Google's Papers Measured

Google's Harness² papers, read closely: what happened when a harness met a new model, what carries over, and a first-week checklist for switching models.Dec 1, 2026Build
Claude Buddy: What Happened to the Terminal Pet?

Claude Buddy: What Happened to the Terminal Pet?

Why /buddy stopped working in Claude Code, what the maintainer said, and how to tell the terminal pet from Anthropic’s Desktop Buddy hardware project.Dec 1, 2026Build
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.