---
name: worktree-retry-cleanup
description: Protocol for cleaning parallel-coder worktree lanes before retry. Triggered before re-dispatching any task that already has a lane (completed, denied, cancelled, or failed).
Worktree Retry Cleanup
Trigger
Before re-dispatching a coder for a task that already has a lane (any prior dispatch status).
Protocol
Check for existing lane branch:git branch --list "swarm/lane/<architect-session>/<task-id>"
Only after cleanup, proceed to declare_scope + coder dispatch
Ownership validation
Before deleting, verify the worktree is not owned by another ACTIVE session. Check .swarm/session/state.json for concurrent sessions. If another session owns it, DO NOT delete — surface the conflict.
Root cause
The provisioning code should auto-clean after coder completion/denial/cancellation (tracked in issue #1746 item 1). This playbook is the temporary protocol.
1---2name: worktree-retry-cleanup-23description: ---4---5---6name: worktree-retry-cleanup7description: Protocol for cleaning parallel-coder worktree lanes before retry. Triggered before re-dispatching any task that already has a lane (completed, denied, cancelled, or failed).8---910# Worktree Retry Cleanup1112## Trigger13Before re-dispatching a coder for a task that already has a lane (any prior dispatch status).1415## Protocol161. **Check for existing lane branch:** `git branch --list "swarm/lane/<architect-session>/<task-id>"`172. **If branch exists:**18 - Verify 0-commits-ahead: `git log --oneline HEAD..swarm/lane/<session>/<task>` — empty = safe19 - Delete: `git branch -d swarm/lane/<session>/<task>` (use `-D` only if `-d` fails AND commits confirmed unneeded)20 - Under full-auto, `-D` is deny-pattern-blocked — use `-d`213. **Check for worktree directory:** if `.swarm-worktrees/<architect-session>` exists, remove it (`Remove-Item -Recurse -Force` / `rm -rf`)224. **Prune:** `git worktree prune`235. **Verify:** `git branch --list "swarm/lane/<session>/<task>"` returns empty246. Only after cleanup, proceed to `declare_scope` + coder dispatch2526## Ownership validation27Before deleting, verify the worktree is not owned by another ACTIVE session. Check `.swarm/session/state.json` for concurrent sessions. If another session owns it, DO NOT delete — surface the conflict.2829## Root cause30The provisioning code should auto-clean after coder completion/denial/cancellation (tracked in issue #1746 item 1). This playbook is the temporary protocol.
Run npx skillmds@latest add zaxbysauce/worktree-retry-cleanup-2 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
--- It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
zaxbysauce (@zaxbysauce) published this skill. Their other Agent Skills are listed on their SkillMD profile.