How to run Claude Code sessions in parallel

Run several Claude Code sessions at once with git worktrees: the commands, the cleanup, what a worktree does not isolate, and how Kangentic handles all of it from a board.

One Claude Code session at a time is fine until you notice how much of the day goes to waiting on it. The obvious fix is a second terminal and a second claude, and that works for about ten minutes. Then both sessions edit the same files, one of them switches the branch out from under the other, and you’re untangling a diff that two agents wrote at once.

The answer is git worktrees, and you don’t need anything beyond git to set them up. This post covers the commands, the cleanup, and the three things a worktree does not isolate, which are the parts that actually bite. At the end I’ll show how Kangentic runs every one of these steps for you when you drag a card.

One checkout per session

A git worktree is a second working copy of the same repository. Each one has its own folder, its own checked-out branch, and its own HEAD and index, and they all share one history. Commit in one worktree and the commit is there in the others. There’s no second clone and nothing to push between them.

So the rule is one worktree per session. Each agent gets a folder nobody else is editing and a branch nobody else has checked out.

Two worktrees, two sessions

Let’s say you have two tasks: extracting the auth middleware, and adding rate limiting. From the root of the repository:

Terminal window
git worktree add ../myapp-auth -b auth-middleware
git worktree add ../myapp-rate-limit -b rate-limit

Each line creates a new branch from where you are and checks it out in a new folder next to your repository. The repository needs at least one commit first. Then start a session in each folder, one terminal per folder:

Terminal window
cd ../myapp-auth
claude
Terminal window
cd ../myapp-rate-limit
claude

git worktree list shows every worktree with its folder, commit and branch. Your main checkout stays on whatever branch it was on, so you can keep working there yourself.

Git also won’t check out one branch in two worktrees. If you try, git worktree add refuses. I think of that as a feature, because two sessions can never end up committing to the same branch by accident.

Let Claude Code make the worktree

Claude Code can do the setup itself:

Terminal window
claude --worktree feature-auth

That creates .claude/worktrees/feature-auth/ at the root of the repository, on a new branch named worktree-feature-auth, and starts the session there. The branch is cut from the repository’s default branch on the remote, usually main. Leave off the name and Claude Code makes one up, such as bright-running-fox. Add .claude/worktrees/ to your .gitignore so the worktrees don’t show up as untracked files in your main checkout.

When the session ends, Claude Code cleans up after itself. A clean worktree from an unnamed session goes away with its branch. When the worktree has work in it, or you named the session, Claude asks whether to keep it. There’s one catch. Gitignored files don’t count as work, so an edited .env in a worktree can disappear at exit. A .worktreeinclude file at the root of the repository copies gitignored files such as .env into each worktree Claude creates.

Cleaning up

Worktrees you made with git worktree add are yours to remove. Once the branch is merged:

Terminal window
git worktree remove ../myapp-auth
git branch -d auth-middleware

git worktree remove only removes a clean worktree, one with no untracked files and no changes to tracked files. Add --force when you’re sure the leftovers can go. If you deleted a worktree’s folder by hand, git worktree prune drops git’s record of it. And git branch -d refuses to delete a branch that isn’t merged, which is the safety you want here.

What a worktree does not isolate

So what’s still shared? A worktree gives each session its own files and its own branch. Everything outside the repository is the same for both of them.

Ports

Both worktrees run the same dev server config, so both servers want port 3000. The second one either fails or moves to another port you then have to go find. Give each worktree its own port. Most dev servers read a PORT variable or take a --port flag:

Terminal window
PORT=3001 npm run dev

Databases

Both worktrees usually point at the same local database, because they read the same connection string. A migration in one session changes the schema under the other. If two tasks touch the schema, give each worktree its own database, or run those two tasks one after the other.

Dependencies and untracked files

A new worktree holds only the files git tracks. There’s no node_modules, no build output and no .env. Claude Code’s own docs say to set up your environment in every new worktree, so install dependencies in each one and copy over the untracked files the app needs:

Terminal window
cd ../myapp-auth
npm install
cp ../myapp/.env .

This is also where a parallel setup gets slow, because every worktree pays for its own install.

Codex works the same way

None of this is specific to Claude Code. With the Codex CLI, make the worktree with git and run codex in it:

Terminal window
git worktree add ../myapp-search -b search-filters
cd ../myapp-search
codex

There’s one difference to watch. Codex loads a project’s .codex/ config, hooks and rules only in a project you trust. Check that a new worktree is trusted before you start, or your project’s config won’t load there.

If you use Codex in the ChatGPT desktop app, it manages worktrees for you. It creates them under $CODEX_HOME/worktrees, gives each chat its own, and keeps the 15 most recent. Archiving a chat deletes its worktree after saving a snapshot you can restore. That cleanup never touches worktrees you made yourself with git.

The same thing from a board

Everything above is a checklist you run by hand for every session, and the more sessions you run, the more of it gets skipped. Kangentic runs the whole checklist each time you drag a card, including the steps people skip.

A task is a card on a board. Drag the card into a column with an agent, and Kangentic creates a branch, cuts a worktree for it under .kangentic/worktrees/, named after the task’s number, and starts the column’s agent there. Your own checkout, the one open in your editor, is never touched.

Two cards in Executing are two agents in two worktrees, and you can tile their windows to watch both. Here Claude Code is extracting the auth middleware on the left, while the session on the right asks to run a typecheck for the API client types.

Two task windows tiled side by side over the board: Claude Code working on Extract auth middleware on the left, and on the right asking to run a PowerShell typecheck for Generate API client types, each with a context bar of model, context use, and cost. v0.69.0 The real app on a sample install. The projects and terminals are recordings, connected to nothing, so click anything.

A task that starts in seconds

Kangentic writes a new worktree’s files in one checkout pass instead of two on git 2.35 or newer, which makes creating one about three times faster on Windows. Put your install in the Post-worktree script, and it runs in every new worktree. Kangentic also keeps one spare worktree with the script already run, and the next new task on the default base starts in it. On a pnpm workspace, that took a task’s start from a 25 to 30 second install to about 5 seconds.

Claude Code doesn’t wait for the install either. It starts while the script runs and gets its first prompt once the script succeeds.

A base that’s never stale

A new worktree is cut from your base branch as origin has it, fetched just before, not from wherever your local copy was at your last pull. Kangentic fetches in the background when a project opens and again five minutes after the last fetch, so the “behind” counts on your cards stay current. Picking up a card warms that fetch, so when you drop a card on Done, the check for work that exists nowhere else finds the fetch already finished or in flight.

Untracked files, ports and trust

Copy files brings .env and anything else git ignores into each worktree before the agent starts, and skips a file whose size and modified time already match. Link folders shares a heavy folder, such as a build cache, through a link instead of a copy. Removing a worktree takes its links out first, so it never deletes what a link points at.

Before an agent starts a dev server, it can ask Kangentic for ports with kangentic_reserve_dev_ports. Every port it gets back has been probed as free, not just unclaimed, from a range that sits clear of the common framework defaults. The task keeps its ports across restarts.

Trust is the easiest one to miss. Codex, Gemini, Qwen Code, Grok Build and Antigravity each keep folder trust per path, so a new worktree can start out untrusted. Kangentic trusts each worktree for its agent before the agent starts, so you never get a prompt per task. When the worktree goes, Kangentic removes the entry again, so those trust files don’t collect one dead entry per task.

Cleanup that checks before it deletes

Moving a card to Done removes its worktree in the background and keeps the branch, so dragging the card back recreates the worktree in the same folder and resumes the conversation where it stopped. The move also stops the dev servers its agent left running, and only those. A process has to carry the task’s own tag, and a server another task is still connected to stays up. When a move would lose uncommitted files or commits that exist nowhere else, Kangentic asks first and names exactly what would be lost. The worktree lifecycle lists what each move does.

Databases are still the gap. Kangentic doesn’t give each task its own database, so if two tasks change the schema, the advice above still applies.

The board doesn’t care which agent is on the card, either. Each column picks its own, so Claude Code can build in one column while Codex CLI reviews in the next. Agent orchestration lists the agents it runs.

If you want to try it on your own repository, npx kangentic starts it, and Installation covers the rest.