# WorktreeManager

**Kind:** Class

**Source:** [`atloria-monorepo/libs/agent-core/src/tools/worktree-manager.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/libs/agent-core/src/tools/worktree-manager.ts#L49)

## Methods

| Method | Signature | Returns |
|---|---|---|
| `isGitRepo` | `isGitRepo()` | `boolean` |
| `create` | `create(name: string)` | `WorktreeInfo` |
| `remove` | `remove(name: string)` | `void` |
| `list` | `list()` | `WorktreeInfo[]` |
| `diff` | `diff(name: string)` | `string` |
| `hasChanges` | `hasChanges(name: string)` | `boolean` |
| `activeCount` | `activeCount()` | `number` |
| `pruneStale` | `pruneStale()` | `number` |

## Where it refuses work

- `WorktreeManager` stops the work with `Error` when `!this.isGitRepo()` — “WorktreeManager: not a git repository”.
- `WorktreeManager` stops the work with `Error` when `this.activeCount() >= this.maxWorktrees`.
- `WorktreeManager` stops the work with an early return when `!branch`, in 2 places.
- `WorktreeManager` stops the work with an early return when `this.branchExists(expected)`.
- `WorktreeManager` stops the work with an early return when `lines.length > 0 && lines[0]`.
- `WorktreeManager` stops the work with an early return when `this.branchExists('main')`.

## When something fails

- `WorktreeManager` handles failure in 12 places: it turns it into a return value in 6, discards it silently in 4, and logs it and continues in 2. A failure discarded silently leaves no trace for whoever debugs this later.
