# Give each agent its own git worktree with Crew

> Give each coding agent its own git worktree with Crew so parallel agents never edit the same files, then check, rename and clean up those checkouts.

- Canonical URL: https://getedith.pro/docs/agents/tutorials/one-git-worktree-per-agent
- Updated: 2026-12-03

By the end of this tutorial, each of your agents will work on its own branch in a separate checkout of the same repository, so two agents never edit the same files, and you will know how to check, rename and remove those checkouts when the work is done. You need Crew running on a Mac in the Edith beta, a git repository, and an agent CLI such as Claude Code or Codex. See [Get Crew](https://getedith.pro/docs/agents/crew/get-crew).

> **Beta:** Crew is a beta extension and can change between releases.

## Know what the engine does for you

A git worktree is a second checkout of the same repository on its own branch. The agents engine creates these worktrees, starts the agent inside one, and cleans them up when you ask. Your main checkout stays on the branch you had.

## Start a thread in its own worktree

1. Open **Crew** from the sidebar and switch to **Threads**.
2. If the repository is not listed yet, press **Add project** in the Threads sidebar and choose its folder.
3. Press **New thread** (⌘N) and pick the agent.
4. In the composer, press the workspace control, **Where the agent works** (⌘⇧X), and switch it from **Current checkout** to **New worktree**.
5. Type a **Branch name**, or leave it empty and the engine names it. Under **Base**, pick the branch to start from, or keep **Default branch**.
6. Write the task and send it.

Repeat for each agent. Each thread gets its own branch and folder, so they never edit the same files. To start another thread in a worktree you already have, right-click its thread and choose **New thread in this worktree**.

### From the terminal

`--worktree` names the branch, tag or commit to start from, and `--branch` names the new branch:

```terminal
$ ed crew thread launch . --worktree main --branch fix-login --wait -- fix the failing login test
$ ed crew thread launch . --provider codex --worktree main --branch csv-export -- add CSV export to reports
```

`.` means the project that holds the current folder. `--wait` waits for the reply and prints it.

## Start a terminal agent on its own branch

**New agent** opens a terminal agent in a space, not on a new branch. To give a terminal agent its own worktree, start it from a terminal. The engine creates a worktree under `~/.edith/agents/worktrees/<repo>/<branch>` and starts the agent inside it:

```terminal
$ ed crew engine run claude --cwd ~/code/app --branch fix-login --plan
```

`--plan` starts it in plan mode. Leave it out to let the agent start working right away.

When you want the checkout first and the agent later, create the worktree by hand. It opens as an agents space, so you can then start an agent there from **New agent** (⌘N):

```terminal
$ ed crew worktrees create --branch fix-login --base main
$ ed crew worktrees create --branch fix-login --base origin/main --from-origin
```

Without `--branch`, the engine names the branch. `--path` picks the folder for the checkout, and `--label` names the space.

## Check each worktree

Open the thread and press **Diff** (⌘D) in the thread toolbar to see what changed in its worktree, turn by turn.

### From the terminal

List every checkout of the repository with its branch, and whether an agents space has it open, then look at one in detail:

```terminal
$ ed crew worktrees ls --cwd ~/code/app
$ ed crew worktrees status --cwd ~/code/app-fix
$ ed crew worktrees repos --cwd ~/code
```

`status` prints the branch, how far it is ahead of or behind its upstream and the default branch, its pull request and its changed files. `repos` lists every repository below a folder, most recently active first.

## Rename the branch before you publish

Branch names picked in a hurry rarely survive review. Renaming is a terminal step. Rename the branch, or let the engine name it from a short description:

```terminal
$ ed crew worktrees rename-branch fix-login-form
$ ed crew worktrees rename-branch --describe "fix the login form" --cwd ~/code/app-wt
```

A branch that is already on a remote is not renamed. `--only-if <name>` renames only while the branch still has that name.

## Remove a worktree when you are done

Deleting a thread keeps its worktree unless you ask. Right-click the thread in the Threads sidebar, choose **Delete…**, then **Delete with worktree**. **Delete thread** keeps the checkout.

### From the terminal

```terminal
$ ed crew worktrees rm ~/code/app-fix-login
$ ed crew thread rm th_01 --remove-worktree
```

`rm` removes a checkout the engine manages and closes its space. The branch stays. A checkout with uncommitted changes is kept unless you pass `--force`.

## Clean up in bulk

The engine can remove old agent worktrees for you. It only looks at worktrees Edith made for agents, and never removes one with an agent running in it.

1. On the Crew page, open **Filter** (⇧⌘F) and choose **Edit launch settings**.
2. Find the **Worktree cleanup** section.
3. Set the rules: **Remove after inactivity**, **Remove when the branch merges** and **Remove unused worktrees**. **Keep worktrees with** protects worktrees that still have changes.
4. Press **Preview** to see what would go, then **Clean up now**.

With rules set, the engine checks Edith's worktrees every hour and removes the ones they match.

### From the terminal

Always see what `cleanup` would do first:

```terminal
$ ed crew worktrees cleanup --dry-run --merged
$ ed crew worktrees cleanup --merged --older-than 14
```

`--merged`, `--older-than <days>` and `--unchanged` pick the rule. Without a rule the saved worktree rules apply, and when none are set nothing is removed.

## Work on another machine

When you start a thread, pick the machine in the composer before you send; the worktree is made on that machine. Every `ed crew worktrees` command takes `--machine`, with that machine's paths:

```terminal
$ ed crew worktrees ls --machine box --cwd /srv/app
```

## Next steps

- [Run Crew on a Linux server](https://getedith.pro/docs/agents/tutorials/run-crew-on-a-linux-server)
- [Undo agent changes with checkpoints](https://getedith.pro/docs/agents/tutorials/undo-agent-changes-with-checkpoints)
- [Worktrees](https://getedith.pro/docs/agents/crew/worktrees)
- [`ed crew engine`](https://getedith.pro/docs/agents/crew/cli/engine)

## Get Edith

Edith is a native Mac app for macOS 14 or later on Apple silicon with 100+ extensions, the `ed` command line and an MCP server. $35 once for one Mac, plus $7 for each additional Mac, with no subscription and a 30-day refund.

- [Buy Edith](https://getedith.pro/pricing): $35 once for one Mac, plus $7 for each additional Mac
- [Download Edith](https://getedith.pro/download): the installer, or Homebrew
