Docs · Execution
Worktrees
Every Work item runs inside an isolated git worktree. This prevents branch contention when multiple Work items are active simultaneously.
Why per-Work worktrees
Zero uses git worktree to give each Work item its own working directory and branch. This means:
- Sessions on different Work items never share a working tree — no file conflicts.
- The main checkout stays clean while Work items are in progress.
- Multiple Work items can be in IMPLEMENTING state at the same time without interference.
Where it lives
Worktrees are created inside the Zero memory root, under a directory named after the Work item's ID:
zero-memory/worktrees/<work-id>/The branch name is generated by the /api/worktrees/branch-name endpoint before the worktree is created.
Branch naming
Call POST /api/worktrees/branch-name to generate a branch name before attaching a worktree. The name is derived from the Work item's title and ID to ensure uniqueness.
POST /api/worktrees/branch-name
Body: { "case_id": "<work-id>", "title": "auth timeout fix" }
→ { "branch": "zero/auth-timeout-fix-001a" }Stale cleanup
Worktrees become stale when a Work item is resolved or when a session exits uncleanly. Two endpoints manage cleanup:
| Endpoint | Action |
|---|---|
GET /api/worktrees/stale | List all worktrees with no active lock and no recent session activity. |
POST /api/worktrees/cleanup | Remove stale worktrees from disk. Operator-triggered — not automatic. |
Verify isolation
Before a session starts Work mode, isolation can be verified:
POST /api/worktrees/:case_id/verify-isolation
→ { "isolated": true, "branch": "zero/auth-timeout-fix-001a", "clean": true }This checks that no uncommitted changes from other sessions are present and that the worktree branch has not diverged unexpectedly.
API reference
| Method | Endpoint | Purpose |
|---|---|---|
POST | /api/worktrees | Create a new worktree for a Work item. |
POST | /api/worktrees/:case_id/attach | Attach an existing worktree to a Work item. |
DELETE | /api/cases/:id/worktree | Remove the worktree association from a Work item. |
GET | /api/worktrees/:case_id/health | Check worktree health (branch status, lock state). |
GET | /api/worktrees/:case_id/status | Current working tree status (modified files, staged). |
POST | /api/worktrees/:case_id/verify-isolation | Confirm isolation before starting Work mode. |
GET | /api/worktrees/stale | List stale worktrees. |
POST | /api/worktrees/cleanup | Remove stale worktrees. |
POST | /api/worktrees/branch-name | Generate a branch name for a new worktree. |
GET|PUT | /api/worktrees/config | Read or update worktree configuration. |
GET | /api/worktrees/:case_id/memory-root | Return the memory root path for a Work item's worktree. |