fix: pcl should checkout main before cleanup (#1433)

The /pcl skill was deleting branches without first ensuring we're on main,
which could cause errors if the current branch is about to be deleted.

## Changes:
- Add Step 1: Checkout main and pull latest
- Add Step 8: Verify final state is on main branch
- Renumber all subsequent steps

## Behavior:
**Before:** Could fail if currently on a branch being deleted
**After:** Always starts from and ends on main branch

This ensures the cleanup process is safe and leaves the repo in a clean,
predictable state (on main with all stale branches removed).

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
L 2026-02-18 02:08:14 -05:00 committed by GitHub
parent e459c9438c
commit e43279d25c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,13 +17,24 @@ Delete local and remote git branches that no longer have an open PR, and prune s
## Procedure
### Step 1: Fetch and prune remote refs
### Step 1: Checkout main branch
Switch to main and update to latest:
```bash
git checkout main
git pull --rebase origin main
```
**Critical:** This ensures we're not on a branch that's about to be deleted, and that we're working from the latest main.
### Step 2: Fetch and prune remote refs
```bash
git fetch --prune origin
```
### Step 2: Identify stale remote branches
### Step 3: Identify stale remote branches
List all remote branches except `main` and `HEAD`:
@ -31,7 +42,7 @@ List all remote branches except `main` and `HEAD`:
git branch -r --format='%(refname:short) %(committerdate:relative)' | grep -v 'origin/main\|origin/HEAD\|^origin '
```
### Step 3: Get branches with open PRs (protected)
### Step 4: Get branches with open PRs (protected)
```bash
gh pr list --repo OpenRouterTeam/spawn --state open --json headRefName --jq '.[].headRefName'
@ -39,7 +50,7 @@ gh pr list --repo OpenRouterTeam/spawn --state open --json headRefName --jq '.[]
Any branch with an open PR MUST be skipped. Never delete a branch that has an open PR.
### Step 4: Delete stale remote branches
### Step 5: Delete stale remote branches
For each remote branch that is NOT in the open PR list:
@ -49,7 +60,7 @@ git push origin --delete BRANCH_NAME
If `--dry-run` was passed, print `[dry-run] would delete origin/BRANCH_NAME` instead.
### Step 5: Delete stale local branches
### Step 6: Delete stale local branches
List local branches (excluding the current branch and `main`):
@ -65,7 +76,7 @@ git branch -d BRANCH_NAME 2>/dev/null || git branch -D BRANCH_NAME
If `--dry-run`, print `[dry-run] would delete local BRANCH_NAME` instead.
### Step 6: Prune worktrees
### Step 7: Prune worktrees
```bash
git worktree prune
@ -77,7 +88,17 @@ Remove any leftover worktree directories:
rm -rf /tmp/spawn-worktrees 2>/dev/null || true
```
### Step 7: Summary
### Step 8: Verify final state
Ensure we're on main branch:
```bash
git branch --show-current
```
Should output: `main`
### Step 9: Summary
Print a summary:
- Number of remote branches deleted