How-to guide
Start an agent in a new worktree
A worktree gives an agent its own branch and its own copy of the files, so several agents can work on one project without touching your branch or each other's.
A new worktree starts on a new branch of the same name. Its folder name stays the same if the branch changes later.
Start a session in a new worktree
- Press ⌘⇧N, or click the + on the project's row in the sidebar. The new session page opens with Worktree picked.
- Check the project chip and the agent.
- To start from a branch other than the default, click the branch chip and pick a branch. Branches only on the remote show as
origin/<name>. - Type the prompt and press Return.
Zoes shows its progress under Creating worktree: Fetching latest changes, Creating git worktree, Copying configuration, Setting up, and Starting agent. Then the session opens in the new worktree, which the sidebar lists under the project.
The new worktree gets a generated name. To start every new session in a worktree, set Settings › Agents › New sessions › Runs in to Worktree.
Worktree or LocalOn the new session page, the checkout chip offers Worktree and Local. A worktree has its own branch and copy of the files. A Local is a new place over the project's checkout, so it shares the files and the branch. Pick Local when you want the agent to work on your current branch.
Check out an existing branch
To work on a branch that already exists instead of a new one, open the branch chip, hover over the branch, and click Open worktree.
Start from a pull request
Click the pull request button next to the branch chip and enter 123, #123, or a pull request URL. Press Return to link it. The page shows based off PR #123, and the session starts in a new worktree based on that pull request.
From the command line
zoes session create --new-worktree --base main --prompt "Fix the flaky login test"
See session create.
Run setup commands in new worktrees
A new worktree has the committed files only. Setup commands install dependencies or build what the agent needs before it starts. Zoes takes the first setup it finds, in this order:
- The commands in the project's settings. Open the project's menu in the sidebar, click Project settings…, and fill in When one is created under Worktrees.
- The
setuplist in.zoes/config.json. Zoes reads the file from the new worktree first, then from the project's own checkout. - The script
.zoes/setup.sh, run withbash. Zoes looks in the new worktree first, then in the project's own checkout. Zoes never runs this script on Windows.
To commit setup commands with the repository, add .zoes/config.json:
{
"setup": ["pnpm install", "cp .env.example .env"]
}
The commands run as one script, one line each. If the file isn't valid JSON, Zoes skips it.
Zoes reads .zoes/ first. A project that only has .anywhere/config.json, .anywhere/setup.sh or .anywhere/teardown.sh keeps working, and Zoes keeps editing it there.
Or add a script at .zoes/setup.sh. The script can be in .gitignore. Then new worktrees lack it, and the copy in the project's own checkout runs.
How setup runs
- Setup runs in the session's own terminal, in the new worktree, in your login shell, before the agent starts. Anything it exports reaches the agent.
- Setup gets three environment variables.
ZOES_ROOT_PATHis the path of the project's own checkout.ZOES_WORKSPACE_PATHis the path of the new worktree.ZOES_WORKSPACE_NAMEis the worktree's folder name. Zoes also sets them asANYWHERE_ROOT_PATH,ANYWHERE_WORKSPACE_PATHandANYWHERE_WORKSPACE_NAME, so older scripts keep working. - Setup runs only when Zoes creates a worktree. It doesn't run for a Local or an existing worktree.
- To watch the output, click View output on the progress page.
If a setup command fails, the agent doesn't start. Zoes shows Couldn't start the session with Setup exited and the exit code, and the terminal stays open so you can read it. The worktree stays.
Copy files into new worktrees
Before setup, Zoes copies the project's root .env* files into the new worktree. To copy other untracked files, list their paths, one per line, in a .worktreeinclude file at the project's root. Lines that start with # are comments.
Run commands when a worktree is deleted
Teardown works like setup and runs before Zoes removes a worktree. Zoes takes the first it finds: When one is deleted in the project's settings, the teardown list in .zoes/config.json, or .zoes/teardown.sh.
Choose where worktrees go
New worktrees go in ~/.zoes/worktrees/<project>/<name>. To use another folder:
- Open Settings with ⌘, and select Projects.
- Under Locations, find Worktree folder and click Choose….
- Pick the folder.
The setting applies to every project on this machine. To go back, click Use default. Projects on another machine always use that machine's ~/.zoes/worktrees.
Delete a worktree
- Right-click the worktree in the sidebar, or open its ··· menu.
- Click Delete worktree….
- To delete its branch too, select Also delete branch.
- Click Delete.
WarningDeleting a worktree closes its terminals and removes its folder. Uncommitted files and commits that are on no other branch are lost. The branch stays unless you select Also delete branch.
You can't delete a project's main worktree.
Add worktrees you made outside Zoes
If git has worktrees of the project that the sidebar doesn't list, the project's menu shows Import 1 worktree or Import n worktrees. Click it to add them to the sidebar.