One Claude Code session per git worktree, each on its own branch. Here is how to set it up
with the built-in --worktree flag or with plain git, run the sessions side by
side, and merge the results back without stepping on anything.
You can start claude in two terminal tabs in the same folder, but both sessions then
edit the same files on the same branch. One agent's half-finished change breaks the other's test
run, a formatter rewrites a file the other agent is mid-way through, and when you finally commit
you get a single diff mixing two unrelated tasks. Nothing crashes, the work just gets tangled.
The fix is to give every session its own working directory. A
git worktree is exactly
that: a second (third, fourth...) checkout of the same repository, on its own branch, sharing
one .git history. It is cheaper than a second clone, and every branch you create is
immediately visible from all the others.
--worktree flagAs of September 2026, Claude Code can create the worktree for you (Anthropic's worktree docs). The repository needs at least one commit first. From your project root:
claude --worktree feature-auth
This creates .claude/worktrees/feature-auth/ at the repository root on a new branch
called worktree-feature-auth, and starts the session inside it. Run the same
command with a different name in a second terminal to start a second, isolated session. A few
details worth knowing:
.claude/worktrees/ to your .gitignore so the worktrees don't show up as untracked files in your main checkout.worktree.baseRef to "head" in your settings branches from your current HEAD instead..env are not copied. List them in a .worktreeinclude file at the project root (same syntax as .gitignore) and Claude Code copies them into each new worktree.--tmux option in claude --help, which opens the worktree session in its own tmux session (it requires --worktree).If you are happy with those defaults, this is the quickest route. The manual route below gives you full control over folder names, branch names and the starting point, and it works with any agent, not just Claude Code.
1. Start from a clean state. Commit or stash what you have, so every worktree starts from a known commit.
2. Add a worktree per task. Put them next to the repo rather than inside it, so tools that scan the project folder don't pick them up:
cd ~/code/myapp
git worktree add ../myapp-auth -b feature/auth
git worktree add ../myapp-billing -b fix/billing-rounding
-b creates a new branch from your current HEAD. To check out a branch
that already exists, drop -b: git worktree add ../myapp-review some-branch.
3. Set each one up. A worktree only contains tracked files. Install dependencies and copy any local config it needs:
cd ../myapp-auth
npm install # or pnpm install, uv sync, bundle install...
cp ../myapp/.env .env # untracked files don't come along
4. Start Claude Code in each worktree, one per terminal:
cd ~/code/myapp-auth && claude
cd ~/code/myapp-billing && claude
5. Check what you have at any point with git worktree list.
Terminal tabs are fine for two or three sessions. Beyond that, tmux keeps them organised and lets them survive a closed terminal window:
tmux new -s agents -c ~/code/myapp-auth # first window, first worktree
# inside tmux:
# Ctrl-b c new window (cd to the next worktree, run claude)
# Ctrl-b % split the current window side by side
# Ctrl-b n next window
# Ctrl-b d detach; everything keeps running
tmux attach -t agents # come back later
Name each tmux window after its branch (Ctrl-b ,) so you can tell at a glance
which agent is which. If you also want the sessions to keep going after you close your laptop,
see keeping Claude Code running with the lid closed.
PORT=3001 npm run dev if your framework reads PORT, and tell the agent which port it owns.node_modules, virtualenv or build folder. That costs disk space, but it means one agent upgrading a package can't break another agent's build..env and other untracked files. They exist only where you created them. Copy them in (or use .worktreeinclude with --worktree), and never commit them from a worktree by accident.git stash pop in one worktree can pop a stash made in another, so tell your agents to prefer commits over stashes.Each worktree is just a branch, so you merge it the way you merge any branch. Commit inside the worktree, then either push it and open a pull request:
cd ~/code/myapp-auth
git add -A && git commit -m "Add OAuth login"
git push -u origin feature/auth # then open a PR
or merge it locally from your main checkout:
cd ~/code/myapp
git merge feature/auth
If two agents touched the same files, merge the smaller change first and ask the other agent
to rebase onto main (git rebase main inside its worktree) and fix the
conflicts itself.
git worktree remove ../myapp-auth # refuses if there are uncommitted changes
git branch -d feature/auth # once it's merged
git worktree prune # forget worktrees whose folders you deleted by hand
git worktree remove --force discards uncommitted changes, so only use it when you
are sure. If you deleted a worktree folder with rm -rf, git keeps a stale record of it
until you run git worktree prune.
All of the above works, and it is how most people start. After a week of juggling tabs, copying
.env files and remembering which branch lives where, the bookkeeping becomes the
job. Maestro is a free desktop app that does it for you: each workspace is its own
git worktree on its own branch, with the agent's chat, a terminal and the diff side by side, and
there is no cap on how many you run.
$WORKSPACE_PORT), and a per-repo setup script such as npm install runs in every new worktree.More on how it wraps Claude Code specifically: a GUI for Claude Code. Running OpenAI's agent instead? The same workflow for Codex is in how to run multiple Codex agents in parallel.
Claude Code itself doesn't stop you from opening more. The practical limits are your plan's usage limits, your machine's memory (each session plus its dev server and dependencies), and how many diffs you can realistically review.
Separate clones work too. Worktrees are lighter (one shared history, no extra fetches), and a branch committed in one worktree is instantly visible to the others, which makes merging easier.
CLAUDE.md?
No. CLAUDE.md is a tracked file, so every worktree has its own copy of it from the
commit it started at.