claude-code - 💡(How to fix) Fix claude.ai/code: head branch not deleted after MCP-driven PR merge despite agent instructions

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…

Root Cause

Without the workaround, every Claude Code mobile session that creates and merges a PR leaves an orphan branch behind. Over a few weeks of mobile use, users accumulate dozens of stale claude/* branches that they have to clean up manually.

Fix Action

Workaround

Enable "Automatically delete head branches" at the repo level: gh repo edit OWNER/REPO --delete-branch-on-merge. This delegates the cleanup to GitHub itself, which fires on every merge regardless of source.

RAW_BUFFERClick to expand / collapse

What happens

When Claude Code on web/mobile (claude.ai/code) merges a PR via the GitHub MCP, it does not delete the head branch afterward, even when the session's instructions explicitly tell it to.

Repro

  1. Connect a GitHub repo to a claude.ai/code environment
  2. Authorize the GitHub MCP (one-time OAuth)
  3. In a session, give an explicit instruction like: "When done, open a PR, merge it, then delete the branch"
  4. Have the agent make some change
  5. Trigger the merge
  6. Observe: PR merges successfully, but the head branch remains on origin

Also confirmed when the delete-branch instruction lives in a SKILL.local.md override file in the cloned repo.

Workaround

Enable "Automatically delete head branches" at the repo level: gh repo edit OWNER/REPO --delete-branch-on-merge. This delegates the cleanup to GitHub itself, which fires on every merge regardless of source.

Why this matters

Without the workaround, every Claude Code mobile session that creates and merges a PR leaves an orphan branch behind. Over a few weeks of mobile use, users accumulate dozens of stale claude/* branches that they have to clean up manually.

Environment

  • Claude Code on claude.ai/code (web/mobile sandbox)
  • GitHub MCP connected via Anthropic's OAuth
  • Model: claude-sonnet-4-6

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.ai/code: head branch not deleted after MCP-driven PR merge despite agent instructions