How to run parallel Claude Code sessions without them stepping on each other
Give each session its own worktree: claude --worktree <name> creates a separate working copy on its own branch. Two sessions started in the same folder share the files and the git index, and sooner or later one commits what the other had staged. When the folder has to stay shared, three rules hold: commit by explicit path, never amend a commit you did not create, read `git status` before every step.
The problem: one git index for two sessions
Opening two terminals and starting Claude Code in each is tempting: one session builds a feature, the other fixes a bug. Edited files show up from one session to the other, but the real trap is elsewhere. The git index, the list of files staged for the next commit, is shared by both.
If session A has run git add on its files and session B runs git commit without naming paths, B takes everything that was staged, including A's work. And no agent can tell its own edits from another session's: it sees a modified folder, nothing more.
What broke for me
My pipeline records every incident in a ledger, with the date, the symptom and the cause. On ResellStats, where several sessions worked on the same branch, the same cause keeps coming back:
- August 2026. A second session committed to the branch in the middle of a run and left modified files behind. My fast check, which only runs the tests related to changed files, took its untracked test file for one of the task's files.
- October 2026. A commit from my code agent contained a plan and a ledger it had never touched. The formatter that runs on commit even reformatted the other session's table.
- 26 October 2026. The fix my agent had staged ended up in a commit from another session, which was working on the App Store listing. The agent then ran
--amendon a commit that was no longer its own. My automatic checks passed: a new commit existed, the tests were there, no AI mention. Only the final review noticed that the commit title did not match the task.
Even earlier, an --amend slipped a migration fix into an unrelated commit, because other work had moved the branch tip between the read and the amend. Recovered through the reflog. None of these is a model bug: the shared folder is what makes them possible.
The method: one worktree per session
A git worktree is a second working folder that shares the repository's history but has its own files, its own branch and its own index. Claude Code creates it for you:
claude --worktree feature-auth # terminal 1
claude --worktree fix-paywall # terminal 2Each command creates the folder .claude/worktrees/<name>/ at the repository root, on a new branch worktree-<name>. The short form is -w. On exit, Claude Code checks whether work remains in the worktree before removing it, and asks you what to do if it finds some.
- Add `.claude/worktrees/` to `.gitignore`, otherwise those folders show up as untracked files in your main checkout.
- A worktree is a fresh checkout: dependencies must be installed again. Ignored files such as
.envare not there; list them in a.worktreeincludefile at the root so they are copied on every creation. - By default, the worktree starts from the remote's default branch, not from your local work. Setting
worktree.baseRefto"head"makes it start from your currentHEAD. - For a subagent, the line
isolation: worktreein the header of its.claude/agents/file makes it always work in its own worktree.
My pipeline is ready for this mode: its cost and outcome ledger is tied to the main repository, so a run started from a worktree writes to the same place. The script's test checks it by creating a real worktree.
What the worktree does not solve
A worktree isolates files, not the machine. On a React Native app there is one simulator and one Metro server: two sessions driving them get in each other's way, worktree or not. My global instructions keep parallelism for reading, never for driving a device, as I explain in the article on CLAUDE.md. The same rule applies to subagents inside one session, see the article on parallel subagents.
Load matters too. A heavy test, in a file that passes alone in 15 seconds, went past the default 5-second timeout while other sessions pushed the machine's load to around 9. So before treating a red test as a real failure, I rerun the full check once.
And the worktree is a decision made at launch. When I open a quick session in the main folder while a run is going, the folder is shared again. So my pipeline applies these rules in every case, written into its agent and skill files:
- Commit by explicit path:
git commit -m "<message>" -- <files>. Nevergit add -A,git add .orgit commit -a. - Only `--amend` when `git rev-parse HEAD` really is the task's commit. Otherwise, a new
fix:commit. - Read `git status` before every step. A file another session is editing is not touched and not set aside with
stash: it is excluded from your tests and reported.
What is still open: my verification script checks that the commit exists and descends from the right base, not yet that its title and files match the task. That is the action recorded after the 26 October incident.
How to get started
- One task, one session, one worktree:
claude -w <name>in each terminal. .claude/worktrees/in.gitignore, and a.worktreeincludefor your.envfiles.- In your
CLAUDE.mdor agent files: commit by explicit path, never--amenda commit you did not create. - Anything that drives a single device, simulator or browser, stays in one session. My rules for that are in the article on the iOS simulator.
These rules came from incidents recorded run after run. How I turn each incident into a rule is described in the article on my postmortem and retro loop.
Article written with the help of AI, from my daily practice and my projects.
The whole notebook