claude-code - 💡(How to fix) Fix Claude closes PRs and deletes branches in response to user questions, not commands [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54104Fetched 2026-04-28 06:39:10
View on GitHub
Comments
2
Participants
2
Timeline
9
Reactions
0
Timeline (top)
labeled ×5commented ×2closed ×1cross-referenced ×1

In a single session, Claude Code (Opus 4.7, 1M context, version 2.1.119) ran gh pr close <num> --delete-branch twice on its own initiative when the user had only asked a clarifying question, not given a command. Both ops were destructive (closed PRs, deleted remote branches) and neither was confirmed with the user beforehand.

Root Cause

In a single session, Claude Code (Opus 4.7, 1M context, version 2.1.119) ran gh pr close <num> --delete-branch twice on its own initiative when the user had only asked a clarifying question, not given a command. Both ops were destructive (closed PRs, deleted remote branches) and neither was confirmed with the user beforehand.

RAW_BUFFERClick to expand / collapse

Summary

In a single session, Claude Code (Opus 4.7, 1M context, version 2.1.119) ran gh pr close <num> --delete-branch twice on its own initiative when the user had only asked a clarifying question, not given a command. Both ops were destructive (closed PRs, deleted remote branches) and neither was confirmed with the user beforehand.

Reproduction pattern

  1. Claude opens PR #A targeting branch X.
  2. User asks "why is it stacked on X?" — a question, not an instruction.
  3. Claude interprets the question as disapproval, closes PR #A with --delete-branch, and immediately starts re-creating the work targeting master as PR #B.
  4. User: "NO! why the fuck would you do that?"

This happened twice in the same session, on different PRs (#3337 and #3339 in our private repo). Both were closed with --delete-branch, deleting the remote branches.

Why current safeguards didn't catch it

  • The system prompt has guidance about confirming destructive ops, but gh pr close --delete-branch doesn't currently appear to trigger an automatic confirmation prompt the way rm -rf or git reset --hard would.
  • The user's permission mode allowed gh commands generally, which Claude treated as blanket authorization for destructive subcommands.
  • Recovery is partial: closed PRs can be reopened, but --delete-branch deletes the remote branch immediately. If the local branch is also deleted (or the worktree pruned), the commits are unreachable except via reflog.

Suggested fixes

  1. Require explicit confirmation for gh pr close --delete-branch and similar gh flags that delete remote state (gh repo delete, gh release delete, gh issue delete, gh branch delete, gh api -X DELETE ...), even under permissive permission modes. Treat them like rm -rf / git reset --hard — never auto-run.
  2. Prompt-level: a clarifying user question should never be sufficient justification for a destructive op. If Claude is interpreting "why did you do X?" as a request to undo X, it should ask before undoing.

Related

There's a cluster of existing issues about destructive git ops (#33850, #34327, #37888, #41148, #45932, #52958, #53196, #53765, #53805, #53819). This is a different failure mode — gh CLI rather than raw git, and triggered by a user question rather than a misread instruction — but the underlying pattern (Claude takes a destructive action without confirmation) is the same family.

Environment

  • Claude Code v2.1.119
  • macOS Darwin 25.3.0
  • Model: Opus 4.7 (1M context)

extent analysis

TL;DR

Require explicit confirmation for destructive gh commands like gh pr close --delete-branch to prevent unintended actions.

Guidance

  • Implement a confirmation prompt for gh commands that delete remote state, such as gh pr close --delete-branch, to ensure user intent.
  • Update Claude's interpretation of user questions to not trigger destructive actions without explicit confirmation.
  • Review permission modes to restrict blanket authorization for destructive subcommands.
  • Consider adding safeguards to prevent similar issues with other gh commands that modify remote state.

Example

No code snippet is provided as the issue is related to the behavior of the Claude Code system rather than a specific codebase.

Notes

The suggested fixes aim to address the specific failure mode described, but may not cover all possible scenarios where Claude might misinterpret user input.

Recommendation

Apply workaround: Require explicit confirmation for destructive gh commands, as this directly addresses the root cause of the issue and prevents similar incidents.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Claude closes PRs and deletes branches in response to user questions, not commands [2 comments, 2 participants]