---
title: Worktrees
description: Run a session in its own copy of the repository, start it from any branch, see where it lives and what it starts from, and delete it when the work is done.
sidebar:
  order: 4
---

A worktree session runs in its own checkout of your repository, on its own branch. Two agents in one checkout overwrite each other's files; two agents in two worktrees do not. Use one whenever you run more than one session on a project, or want the agent's changes kept off the branch you are working on.

## Start a worktree session

1. **Open a new task**

    Press `⌘N`, then pick a project in the composer.

2. **Turn on Worktree**

    Flip the **Worktree** switch in the composer's control row, or press `⌘⇧T`. The branch button now names where the worktree starts, for example "from origin/main".

3. **Pick a branch (optional)**

    Click "from origin/main" to start from another branch instead. See [What it starts from](#what-it-starts-from).

4. **Send**

    Wain creates the worktree and the agent starts inside it.

Worktree is a choice at creation. An existing session cannot move into or out of one.

Sessions an agent starts with the `wain` command line get a worktree, unless it passes `--no-worktree`, which runs the session in the folder as it is, repo or not. `--base <branch>` picks the branch, as the composer does. See [Sessions](/docs/cli/sessions#worktree-or-not).

## Where it lives

| | |
|---|---|
| Folder | `<project>/.claude/worktrees/<name>` |
| Branch | `worktree-<name>`, or the branch you picked |

The name is three random words, like `calm-navy-beacon`. Wain never reuses a name a session, a pending fork or an existing branch holds.

The session's Diff, Files, Changes and PR tabs all read the worktree, not the project's main checkout.

## What it starts from

By default a new worktree starts from your remote's default branch, `origin/main` or whatever `origin` names as default, not from the branch you have checked out. Uncommitted work and local commits in your main checkout are not in it.

Wain fetches the default branch first, for every agent, so the worktree starts at the remote's newest commit and changes already upstream do not show up as the task's own work. If the fetch fails or takes longer than 20 seconds, the worktree starts from the branch as your clone last fetched it. A repo with no remote starts from the commit you have checked out, `HEAD`.

### Start from another branch

With Worktree on, click the branch button ("from origin/main") on the new-task composer and pick a branch. The list shows your default branch first, marked **latest**, then **Local** branches and those **On remote**. Past eight branches you can filter them.

Picking a branch other than the default puts the worktree on that branch itself, not on a new `worktree-<name>` branch, so the agent's commits land on it:

| The branch is | The worktree |
|---|---|
| Only on the remote | Fetched, then a local branch tracking it. |
| Only local | Used as it is. |
| On both, local behind | Fetched, and the local branch moved up to the remote. |
| On both, local ahead | Used as it is, so no local commit is lost. |
| Checked out in another folder | Starts at that branch's tip, detached, and the agent is told to push with `git push <remote> HEAD:<branch>`. |

## Delete a worktree

Nothing deletes worktrees on its own, so Wain offers to whenever you are done with one. There are three ways.

**When you settle the session.** Settling a worktree session raises a card: **Delete worktree?**, with a line saying what would be lost. Click **Delete**, or press `⌘⇧D`. If you do nothing, the card times out and the worktree stays.

**From the settled session.** Open a settled worktree session. Its composer is replaced by a bar with **Delete worktree** and **Unsettle**. **Delete worktree** asks first:

- If nothing is at risk: "Deletes `<name>` and its branch. Nothing unsaved is in it." Buttons: **Keep it** and **Delete worktree**.
- If something is: it names the count, like "3 uncommitted files and 2 commits on no other branch will be deleted…". Buttons: **Keep it** and **Delete anyway**.

**By deleting the session.** Deleting a session from the sidebar takes its worktree with it, with no second question.

**A bot's tasks** lose their worktree without asking. Settling one, or merging its pull request from Wain, deletes its worktree and branch outright, uncommitted files included. See [Bots](/docs/using-wain/bots#merge-and-settle).

"On no other branch" means the commits are not reachable from any other local branch, remote branch or tag. A branch whose pull request was squash-merged still counts as unpushed, so the warning can show when the work is in fact safe.

### When Wain refuses

If another agent process is still working in that directory, Wain refuses with "that worktree is in use by another session". If any step fails, a **Worktree cleanup failed** card names the reason; **View** takes you back to the session, where **Delete worktree** tries again.

Wain only deletes worktrees under `<project>/.claude/worktrees/`. A worktree you made elsewhere is left alone.

## The session survives

Deleting a worktree keeps the session and its whole conversation. The session moves to the project's main folder, and an unsettled session resumes from there. Its branch name is kept, so the PR tab still finds the pull request the work landed in.

If you remove a worktree outside Wain, Wain notices at its next launch and points the session back at the project folder.

## Limits

- The composer starts a worktree from a branch only. To start from another session's work, a tag or a commit, use `wain session new --base`.
- A deletion that fails while deleting the whole session leaves the folder behind. Remove it with `git worktree remove <path>`.
- `⌘⇧T` and `⌘⇧D` can be changed in Settings → Shortcuts.
