branch-cleanuplisted
Install: claude install-skill stealth-engine/skills
# Branch cleanup
Authors GitHub Actions workflows that delete stale branches. **This skill installs
workflows; it never deletes anything itself.** At runtime there is no agent and no model
call — deterministic bash + `gh` only.
Verified GitHub behaviour (the `delete` event, ruleset errors, `gh` footguns, base-branch
semantics) lives in [`reference/github-facts.md`](./reference/github-facts.md). Read it
before changing any deletion logic.
## The one rule that must never be relaxed
**Before deleting ANY branch, check for open PRs that target it as base:**
```bash
gh pr list --base <branch> --state open --json number --limit 1000
```
GitHub documents it plainly: *"If the branch is associated with at least one open pull
request, deleting the branch closes the pull requests."* That is often **unrecoverable** —
you cannot retarget a closed PR, nor reopen it while its base is missing.
Two traps that make this worse than it looks:
- **`gh pr list --limit` defaults to 30.** A stack deeper than 30 silently under-reports
and the guard passes when it shouldn't. Always pass an explicit high limit.
- **Auto-retargeting will not save you.** It only applies to a *head* branch whose PR is
*already merged*, and it appears to live in the **web** deletion path — community
reports (one confirmed by GitHub staff as a bug) say deleting a ref via API or
`git push --delete` **closes** dependent PRs instead. A bot must assume the close path.
All of this runs **inside `delete_branch()`