Git Worktree Runner
Use isolated worktrees to execute multiple tickets in parallel from the same repository.
Input
- Ticket id and short slug.
- Repo root path.
- Base branch (typically
main). - Constraint: Branch names must use
codex/<ticket-id>-<slug>.
Output
- Dedicated worktree folder per ticket.
- Isolated branch context for each agent.
- Clean teardown steps after merge.
Process
Phase 1: Provision Worktree
- Fetch latest remote state.
- Create branch:
codex/<ticket-id>-<slug>. - Create worktree path (for example:
../wt-<ticket-id>).
Phase 2: Work in Isolation
- Run implementation and tests inside the worktree path.
- Before starting significant new work, fetch the latest state of the target branch and rebase your worktree branch. If the rebase introduces conflicts, resolve them before continuing.
- Commit only files related to the ticket.
- Push branch and open PR.
Phase 3: Teardown
- After merge, remove worktree directory.
- Delete local branch if no longer needed.
- Prune stale worktree metadata.
Useful Commands
git fetch --all --prune
git worktree add ../wt-35 -b codex/35-b5-auto-unarchive main
cd ../wt-35
# ... work, commit, push, PR ...
cd -
git worktree remove ../wt-35
git branch -d codex/35-b5-auto-unarchive
git worktree prune
Completeness Checklist
- □ Worktree path maps one-to-one with one ticket.
- □ Branch naming matches convention.
- □ Worktree is removed after merge.
Rules
- ALWAYS keep one ticket per worktree.
- ALWAYS run commands from the intended worktree directory.
- NEVER mix unrelated ticket commits in one worktree branch.
- NEVER leave stale worktrees after ticket merge.