Clean up the current worktree: $ARGUMENTS
Preconditions
- Current
$PWDmust be inside a worktree (not the main checkout). Verify withgit rev-parse --git-dir != --git-common-dir. - The worktree's branch must be safely removable: merged into the default branch, or its upstream is
goneandgit rev-list "$BRANCH" --not --remotesprints nothing, or the user explicitly passes--force. A gone upstream alone does not prove the commits landed. - Ignored files under the worktree's
.claude/state/are deleted with it. Copy any the main checkout lacks into the main checkout's.claude/state/first.
If the branch is not safe to remove, stop and explain what's still pending (unpushed commits, open PR, etc.). Never auto-delete unmerged work.
Steps
-
Capture worktree path and branch name:
bashWORKTREE=$(git rev-parse --show-toplevel) BRANCH=$(git rev-parse --abbrev-ref HEAD) -
Move out of the worktree to the main checkout (
cd "$(git rev-parse --git-common-dir)/.."). -
Remove the worktree:
git worktree remove "$WORKTREE". If it has uncommitted changes and--forcewas passed, usegit worktree remove --force "$WORKTREE". -
Delete the local branch:
git branch -d "$BRANCH"(or-Dwith--force). -
Report what was cleaned up.
After cleanup
If the user has more work, suggest /worktree <new-slug> for the next task rather than mutating the main checkout.
Merging parallel lanes
When several lane-mode teammates finish, merge their branches into the integration branch one at a time:
- Review each teammate's diff for correctness.
- Merge one branch. Resolve any conflict with
/resolve-conflictsbefore merging the next. - After the last merge, run the full test suite, typecheck, and lint.
- Prune the worktrees:
~/.agents/scripts/worktree-prune.sh --apply. It removes only unlocked worktrees whose branch is merged, squash-merged, or upstream-gone with nothing unpushed, which is the post-merge state. Lane worktrees stay locked while their teammate runs, so they survive until it finishes.


