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

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.

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.
claude --worktree feature-authAsk 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.
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

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-authis 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
.envalone 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-prun 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, rungit worktree unlock <path>first. For manual cleanup, usegit worktree removewith 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







