# Crew worktrees: one git checkout per coding agent

> Give each Crew coding agent its own branch in a separate git worktree, run setup in new worktrees, and clean up old checkouts automatically or by hand.

- Canonical URL: https://getedith.pro/docs/agents/crew/worktrees
- Updated: 2026-12-03

Agents can each work on their own branch in a separate checkout of the same repository, so two agents never edit the same files. The agents engine creates these git worktrees, opens them as spaces, and cleans them up when you are done.

## Start a thread in a new worktree

1. Start a thread: press **New agent** (⌘N) and set **Open as** to **Thread**, or press **New thread** in the Threads section.
2. In the composer, open **Where the agent works** (⌘⇧X) and choose **New worktree** instead of **Current checkout**.
3. Send your first message. The thread works in its own checkout on its own branch.

**Branch** (⌘⇧G) in the same composer switches or creates a branch.

A [schedule](https://getedith.pro/docs/agents/crew/schedules) created from the terminal with `--worktree` also starts each run in a new worktree.

## Run setup in each new worktree

A project can run a command in each new worktree, such as installing dependencies:

1. In the **Threads** sidebar, right-click the project and choose **Project settings…**.
2. Under **Actions**, press **Add action** and enter a name and a command, such as `npm install`.
3. Turn on **Run when a worktree is created**, then press **Save**.

If the project has its own settings file that lays out new worktrees, its commands run only after you approve them with **Review commands**.

## Clean up worktrees

Crew can remove worktrees for you on a schedule:

1. On the Crew page, open **Filter** (⇧⌘F) and choose **Edit launch settings**.
2. Under **Worktree cleanup**, set **Remove after inactivity**, **Remove when the branch merges** and **Remove unused worktrees**.
3. Use **Keep worktrees with** to protect worktrees that hold certain changes.
4. Press **Preview** to see what would go, then **Clean up now**, or let the engine check every hour.

Worktrees with an agent running in them always stay.

To remove one thread's worktree, right-click the thread in the Threads sidebar and choose **Delete with worktree**. Deleting a thread any other way keeps its worktree.

## From the terminal

```sh
ed crew thread launch . --worktree main --branch fix-login -- fix it
ed crew engine run claude --cwd ~/code/app --branch fix-login --plan
ed crew worktrees create --branch fix-login --base main
ed crew worktrees ls --cwd ~/code/app
ed crew worktrees status --cwd ~/code/app-fix
ed crew worktrees rename-branch --describe "fix the login form"
ed crew worktrees rm ~/code/app-fix-login
ed crew worktrees cleanup --merged --older-than 14 --dry-run
```

- `thread launch --worktree` names the branch, tag or commit to start from, and `--branch` the new branch. `engine run --branch` creates the worktree under `~/.edith/agents/worktrees/<repo>/<branch>` and starts a terminal agent in it.
- `create` makes a checkout on a new branch, opens an agents space in it and prints its path.
- `status` prints a checkout's branch, how far it is ahead of or behind, its pull request and its changed files.
- `rename-branch` renames the branch before you publish; a branch already on a remote is not renamed.
- `rm` keeps a checkout with uncommitted changes unless you pass `--force`.
- `cleanup` looks only at worktrees Edith made for agents. Without a rule it uses the **Worktree cleanup** settings. Always try `--dry-run` first.
- `cancel-setup` stops a running setup, and `clear-cache` deletes the prepared checkouts the engine keeps for fast worktrees.

Every command takes `--machine box` to work on a machine, with that machine's paths. See [`ed crew engine`](https://getedith.pro/docs/agents/crew/cli/engine) for the engine's own worktree commands.

## Where to go next

- [Checkpoints](https://getedith.pro/docs/agents/crew/checkpoints)
- [Threads](https://getedith.pro/docs/agents/crew/threads)
- [`ed crew engine`](https://getedith.pro/docs/agents/crew/cli/engine), section Worktrees

## 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
