# A worktree per agent

> Give each nsq agent its own git branch and checkout with --worktree, see its diff, and remove it when you are done.

Source: https://docs.neurosquad.ai/en/cli/worktrees

Two agents editing the same checkout get in each other's way. `--worktree` gives an agent its own
[git worktree](https://git-scm.com/docs/git-worktree): a separate checkout of the same repository,
on its own branch.

```sh
cd ~/code/shop
nsq run claude "fix the flaky checkout test" --worktree --name checkout-fix
nsq run codex "update the API docs" --worktree --name api-docs
```

- The branch is `nsq/<agent name>` — `nsq/checkout-fix` above.
- The checkout lives in `~/.neurosquad-cli/worktrees/`, not inside your repository.
- `nsq ls` shows each agent's branch; `nsq diff <agent>` shows what it changed.
- In the dashboard, the start dialog (`c`) has a worktree switch.

Review and merge the branch the way you always do — it is an ordinary git branch.

## Removing it

```sh
nsq rm checkout-fix               # removes the agent, keeps the worktree and the branch
nsq rm checkout-fix --worktree    # also deletes the worktree folder
```

`--worktree` deletes the folder **including changes that were not committed** — commit what you want
to keep first.

Without `--worktree`, nsq tells you where the worktree is and keeps it, so no work is lost by
accident. The branch itself stays in your repository either way; delete it with git when you no
longer need it.
