Repository navigation
Description
Problem
The remote half of merged-branch cleanup never completes from an agent seat in auto mode, so every round hands the maintainer one paste-ready delete per branch.
drive-prstep 4 andmerge-and-releasestep 8 prescribegit push origin --delete -- "<branch>", whichgh-write-guardrequirement 6 denies from a primary checkout (Requirement 6 Denies the Remote Branch Delete That merge-and-release Step 8 Prescribes #1642).- The ref API route,
gh api -X DELETE repos/<owner>/<repo>/git/refs/heads/<branch>, is refused by Claude Code's auto-mode classifier under its built-in "Git Destructive" rule, which names deleting remote branches. It allowed this on some days and refused it on others.
#1642 says the classifier half is outside this repository's control. It is not, because the Claude Code docs settle a command matching a narrow permissions.allow rule before the classifier runs (permission modes, "How the classifier evaluates actions"). The host-safety installer already registers one such rule, Bash(python3 scripts/pr_review.py:*), in MANAGED_PERMISSIONS, for the review loop's reply and resolve.
Proposed Fix
Add a cleanup subcommand to scripts/pr_review.py that performs the existing verify-then-delete in code, so it runs under the rule already installed with no settings change.
- Input: the merged pull request number and
--repo, never a bare branch name, so the branch is read from the pull request rather than typed. - Refuse unless the pull request is merged, its base is
develop, itsheadRepository.nameWithOwnerequals--repo, and its head branch is neitherdevelop,main, nor the repository's default branch. - Refuse where any ruleset or branch protection applies to the head branch, since the guard's per-branch rule check does not see a delete made from inside the script.
- Read the remote tip with the exact-match
git ls-remote --heads --exit-code -- origin "refs/heads/<branch>"form, or the equivalent API read, and delete only where it equals the pull request'sheadRefOid. A branch already gone reports done, and a failed read stops. - Confirm the delete by reading the ref back, never by the delete's own exit status alone.
- Owner and repository bound to the registry, the same way
handoff.pyrefuses a repository under another owner.
Then point drive-pr step 4 and merge-and-release step 8 at the subcommand, and keep the report-the-commands fallback for a host without the managed rule.
Because the :* rule approves any arguments, every safety check lives in the subcommand, which is the design the rule already relies on for reply.
Out of Scope
- The classifier's "Merge Without Review" refusals on feature to
developmerges. A merge is a larger call and stays a separate question. - The repository's auto-delete-head-branches setting, which stays off fleet-wide because a promotion pull request's head is
develop. - Requirement 6 Denies the Remote Branch Delete That merge-and-release Step 8 Prescribes #1642's guard exemption for a delete-only push, which this makes unnecessary for the agent path but which still stands on its own merits for a manual run.
Activity
Delete a Merged Feature Branch Through a pr_review.py cleanup Subcomm…
Promote the pr_review.py Cleanup Subcommand and the Write-Guard Inclu…