What a worktree is
A git worktree is an extra working folder attached to a repository. Each worktree has its own branch checked out and its own files, while all of them share one .git history. Making one takes a second and copies no history.
git worktree add ../myapp-agent-2 -b agent-2/fix-login origin/main
git worktree list
git worktree remove ../myapp-agent-2
Why one branch per agent
- No collisions. An agent never sees another's half-written files, and a branch switch in one folder never moves another.
- Clean review. Each agent's work is one branch with one diff. Review it, merge it or throw it away.
- Your checkout stays yours. What agents change stays out of your folder until you merge it.
- Easy comparison. Give two agents the same task on two branches and diff the results.
The catches when you do it by hand
- Every new branch must start from a fresh default branch, not from whatever another folder has checked out.
- Each folder needs its dependencies installed, and build output adds up: a Rust
target/folder can take tens of gigabytes per worktree. - You have to remember which agent runs in which folder, and clean up when it is done.
How Cocobox does it
Open a repository as a space. Every new agent tab gets its own worktree, in ~/.local/share/cocobox/worktrees/<repo>/<name>, on a new branch of its own. If a worktree cannot be made, the tab is not opened.
- New branches start from the default branch, freshly fetched. To start from another branch, run
git config cocobox.base <branch>in the repository. - Name the branch yourself with New agent, or let Cocobox pick one.
- The branch picker in a tab's header switches, creates or renames branches. Switching moves the agent into that branch's own worktree.
- Closing a tab archives it, not deletes it, and frees its Rust build output. The disk icon in Spaces frees build output no tab is using.

From branch to pull request
Each tab's Git panel works on that tab's worktree: commit, read the graph, open a commit. Review the diff and leave line comments the agent answers. When the branch is ready, Ship drafts the pull request from the commits and pushes it. Git panel · Review changes.

Worktrees and orchestration
When an agent opens tabs of its own, each child also gets its own branch and worktree, so a team of agents can work on one repository at once. Agent orchestration · Running agents in parallel.