# Run coding agents in parallel with git worktrees · Codara Studio

> Why parallel Claude Code and Codex sessions need git worktrees, how to set one up by hand, how Codara Studio does it, and how to merge and clean up.

- URL: https://studio.codarasolutions.com/guides/parallel-agents-git-worktrees
- Language: en

# Parallel agents, one worktree each.

Two agents in one checkout edit the same files and trip over each other's changes. A git worktree gives each task its own folder and branch from the same repository.

Updated 25 November 2026.

## Why do parallel agents need git worktrees?

An agent edits the files in the folder it runs in. Start two agents in one checkout and they share it: one agent's half-finished edit breaks the other's build or tests, both stage into the same index, and the diff no longer says whose change is whose.

`git worktree` adds working trees to one repository. Each worktree is its own folder with its own checked-out branch, index and files; they share the history, the branches and the remotes ([git documentation](https://git-scm.com/docs/git-worktree)). Git checks out a branch in one worktree at a time.

A new worktree has the tracked files and nothing else: no `.env`, no `node_modules`, no build output. That is the part to plan for.

## How do I set up a worktree by hand?

One folder and one branch per task, next to the main checkout:

```sh
# one worktree and branch per task
git worktree add ../myapp-pricing -b agent/pricing
git worktree add ../myapp-tests -b agent/tests

# copy what git does not track, then install
cp .env ../myapp-pricing/
cd ../myapp-pricing && npm ci

# start one agent in each folder
claude     # in ../myapp-pricing
codex      # in ../myapp-tests

# see them all
git worktree list
```

Claude Code can make the worktree itself: `claude --worktree pricing` creates `.claude/worktrees/pricing/` on a new branch `worktree-pricing` and starts in it, and a `.worktreeinclude` file lists the ignored files to copy in ([Claude Code docs](https://code.claude.com/docs/en/worktrees)).

## How does Codara Studio set up worktrees?

- Workspace actions → Create isolated worktree… opens an existing branch or a new one in a separate folder, and shows it under its repository in the rail.
- `.worktreeinclude` (gitignore syntax) lists the ignored files to copy from the main checkout, such as `.env`. It is the same file Claude Code reads.
- `.codara/worktree.json` adds large ignored folders to link instead of copy, a setup command and terminals to open. Studio never links a folder the setup command installs into (such as `node_modules` when setup runs `npm ci`), and runs a setup command only after you approved it for that repository.
- Agents in Studio can make their own: the `codara_worktree_create` tool gives an agent a worktree of its repository on its own branch, with the same setup.
- Start Claude Code or Codex in the worktree from the + menu. Its line in the rail says whether it is working, done or needs you.
- Not in SSH workspaces yet: there, make worktrees with the git commands above in a Studio terminal.

Both files live in the repository and are meant to be committed. This one copies the `.env` files, links a large ignored `test-data` folder that no install fills, installs `node_modules` fresh with `npm ci` and opens a dev server:

```sh
# .worktreeinclude
.env
.env.local

# .codara/worktree.json
{
  "link": ["test-data"],
  "setup": ["npm ci"],
  "terminals": [{ "name": "Dev server", "command": "npm run dev" }]
}
```

You do not have to write them by hand: Set up worktrees… finds the ignored `.env` files, the folders worth linking and an install command for your lockfile ([Studio docs](https://github.com/Codara-Solutions/codara-studio/blob/main/docs/worktree-setup.md)).

## How do I merge the work and clean up?

By hand, review and push from inside the worktree, then remove it once the branch is merged:

```sh
cd ../myapp-pricing
git diff
git commit -am "Add the pricing page"
git push -u origin agent/pricing   # then open a pull request

# after the pull request is merged
cd ../myapp
git worktree remove ../myapp-pricing
git branch -d agent/pricing
git worktree prune                 # forget worktrees whose folder is gone
```

In Studio, review the diff, commit and open the pull request from Source control. Clean up worktrees… lists every worktree across your repositories with its size, its last activity and whether its branch is merged, and removes the ones you pick. An agent's `codara_worktree_remove` removes a worktree only when it is clean and its work is merged or abandoned, and never forces.

## When is one checkout, or Claude Code alone, the better choice?

- One agent at a time: a worktree is one more folder to set up and clean up. A branch in your main checkout is enough.
- You only run Claude Code: `claude --worktree` and `.worktreeinclude` do the setup without another app.
- Setup is slow or large: every worktree pays for its own install and build. For a short task, one checkout and one agent may finish sooner.
- The tasks touch the same files: parallel branches will meet in a merge conflict. Run them one after the other instead.

## What goes wrong, and how do I fix it?

- Git will not check out a branch: another worktree has it. Make a new branch with `-b`, or remove the other worktree first.
- The app does not start in the new worktree: its `.env` and dependencies are missing. Copy them, or list them in `.worktreeinclude`.
- Two dev servers want one port: each worktree runs its own server, so give each its own port.
- A worktree folder was deleted by hand: git still lists it until `git worktree prune`.
- The disk fills up: each worktree is a full checkout, and copied dependencies add up. Link large folders that no install fills instead of copying them, and remove worktrees once merged.
- Two branches change the same lockfile or migration: worktrees keep them apart only until the merge. Merge one, then rebase the other on it.

## Questions

### How many worktrees can I have?

Git sets no fixed number; each worktree is a folder on your disk. In Codara Studio, agents together can make at most 20 per repository; the ones you make yourself do not count.

### What do worktrees share?

The repository's history, branches and remotes. Each worktree has its own files, its own index and its own checked-out branch.

### Does Claude Code support worktrees on its own?

Yes. claude --worktree NAME creates a worktree under .claude/worktrees/ on a new branch and starts Claude Code in it.

### Do I need Codara Studio for this?

No. The git commands on this page work in any terminal. Studio does the setup, the copying and the clean-up for you, and shows every agent's state in one window.

## Sources

- [Git documentation: git-worktree](https://git-scm.com/docs/git-worktree), checked 25 November 2026
- [Claude Code docs: Run parallel sessions with worktrees](https://code.claude.com/docs/en/worktrees), checked 25 November 2026
- [Codara Studio docs: Worktree setup](https://github.com/Codara-Solutions/codara-studio/blob/main/docs/worktree-setup.md), checked 25 November 2026
- [Codara Studio docs: MCP tools (with Startup flags)](https://github.com/Codara-Solutions/codara-studio/blob/main/docs/mcp-tools.md), checked 25 November 2026
- [Codara Studio README (MIT)](https://github.com/Codara-Solutions/codara-studio#readme), checked 25 November 2026

Claude Code is Anthropic's, Codex is OpenAI's, Conductor is Melty Labs'; Codara Studio is not affiliated with any of them.

Read next:

- [Claude Code GUI](https://studio.codarasolutions.com/claude-code-gui): What a desktop GUI adds to the Claude Code CLI, how Codara Studio runs it next to Codex with a git worktree per task, and how other Claude Code GUIs compare.
- [Conductor alternative](https://studio.codarasolutions.com/compare/conductor): Conductor announced in November 2026 that it is joining Meta, and runs on macOS only. How Codara Studio compares, how to move over, and when it is still better.
- [Browser MCP](https://studio.codarasolutions.com/browser-mcp): What a browser MCP server is, how Claude Code and Codex drive a browser through one, the main options compared, and what Codara Studio's browser tools reach.
- [Download Codara Studio](https://studio.codarasolutions.com/download): free and open source, for macOS and Windows.
