Skip to content

Delete a Merged Feature Branch Through a pr_review.py cleanup Subcommand So Auto Mode Completes It #2967

Closed

Description

@ptr727

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-pr step 4 and merge-and-release step 8 prescribe git push origin --delete -- "<branch>", which gh-write-guard requirement 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, its headRepository.nameWithOwner equals --repo, and its head branch is neither develop, 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's headRefOid. 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.py refuses 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 develop merges. 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

  1. added
    enhancement
    skills
    script
    on Oct 14, 2026
  2. added a commit that references this issue on Oct 14, 2026
    4537d02
  3. added a commit that references this issue on Oct 14, 2026
    68a2296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementscriptskills

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions