/agent-traffic-control:gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletesfrom agent-traffic-control
Diagnose and recover from two adjacent `gh pr merge` failure modes that masquerade as merge conflicts. Use when: (1) `gh pr merge --squash` (or `--merge`) errors with "To have the pull request merged after all the requirements have been met, add the `--auto` flag" AND "Run the following to resolve the merge conflicts locally" even though you just pushed a clean resolution; (2) `gh pr view <N> --json mergeable,mergeStateStatus` returns `MERGEABLE` + `UNSTABLE` rather than `MERGEABLE` + `CLEAN`; (3) you delete the remote branch (`git push origin --delete <branch>`) immediately after `gh pr merge` returns a conflict warning thinking the merge succeeded — and discover the PR has flipped to `CLOSED` rather than `MERGED`. The actual root cause for (1)/(2) is almost always pending CI / branch-protection checks, NOT real merge conflicts; the fix is `--auto` flag so `gh` queues the merge for when checks pass. For (3) — recovery requires restoring the remote branch (`git push -u origin <branch>` from your local copy, OR — if you have NO local copy — from `refs/pull/<N>/head`) and `gh pr reopen <N>` before retrying. (4) `gh pr merge` errors `Pull Request is still a draft (mergePullRequest)` — the PR is a draft; run `gh pr ready <N>` first. A cleanup step that deletes the head branch keyed on branch-EXISTENCE (not merge-success) will delete a draft/unmerged PR's branch and close it — always gate deletes on `mergedAt != null`. Sibling to `gh-pr-merge-worktree-checkout-trap` (different failure mode — worktree holding main).
Trending skills
7-day visitors to each skill page
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
gh pr merge UNSTABLE state + branch-delete recoveryTwo adjacent failure modes that read as "merge conflicts" but aren't:
gh pr merge rejects with "conflicts" when there are noneYou push a clean resolution of merge conflicts, GitHub shows the PR as MERGEABLE, and yet:
$ gh pr merge 915 --squash
To have the pull request merged after all the requirements have been met,
add the `--auto` flag.
Run the following to resolve the merge conflicts locally:
gh pr checkout 915 && git fetch origin main && git merge origin/main
The first line is the actual hint; the second is misleading boilerplate. The real cause is
mergeStateStatus: UNSTABLE — branch protection or CI checks are pending. gh can't merge yet
because the repo's rules aren't satisfied, not because of file-level conflicts.
Common pattern: previous PR on the same branch merged cleanly with gh pr merge <N> --squash. You
then do git push origin --delete <branch> to clean up. Habit kicks in for the next PR — you run
gh pr merge (gets Failure A above), notice the "conflicts" warning, run
git push origin --delete <branch> anyway thinking the merge already landed remotely...
$ gh pr view 915 --json state
{"state":"CLOSED"} # ← not MERGED — the PR closed because the branch was deleted with the merge un-queued
GitHub treats a deleted-branch PR with no merge in progress as abandoned and closes it.
gh pr merge --squash (or --merge) returns with the "add the --auto flag" / "resolve
conflicts" stderrgh pr view <N> --json state,mergeable,mergeStateStatus shows {state: OPEN, mergeable: MERGEABLE, mergeStateStatus: UNSTABLE} — the UNSTABLE is diagnostic; it means "no real conflicts, but checks
aren't passing yet"state: CLOSED rather than state: MERGED, AND the remote
branch is missingFor Failure A: gh pr merge (without --auto) requires the PR to be fully ready to merge RIGHT
NOW. If branch-protection rules or CI checks are pending, gh reports it as a generic merge problem
with misleading conflict-resolution advice. The actual diagnostic is the
mergeStateStatus field — UNSTABLE means "pending checks", BLOCKED means "failed checks or
missing reviews", CLEAN means "ready to merge", DIRTY means "real file conflicts".
For Failure B: GitHub's UI treats "branch deleted + no merge in progress" as PR abandonment. The PR closes; the merge never happens; recovery requires restoring the branch AND reopening the PR.
Before retrying or panicking:
gh pr view <N> --json state,mergeable,mergeStateStatus,statusCheckRollup
Interpretation:
state | mergeable | mergeStateStatus | Meaning | Action |
|---|---|---|---|---|
| OPEN | MERGEABLE | CLEAN | Ready to merge | gh pr merge <N> --squash |
| OPEN | MERGEABLE | UNSTABLE | Pending CI / checks | gh pr merge <N> --squash --auto |
| OPEN | MERGEABLE | BLOCKED | Failed checks or missing required reviews | Fix the failed check or request review |
| OPEN | CONFLICTING | DIRTY | Real file conflicts | Resolve locally, push, retry |
| CLOSED | (any) | (any) | PR closed (often: branch deleted) | Restore branch + reopen (see recovery below) |
| MERGED | (any) | (any) | Already done | Nothing to do |
--autogh pr merge <N> --squash --auto
# Returns silently; merge queues for when checks pass; GitHub auto-deletes remote branch on merge
--auto tells GitHub to wait for branch-protection requirements and then merge automatically. No
polling required — GitHub handles it. The remote branch is deleted by GitHub at merge time (no need
to do it yourself).
# Your local branch still has the commits — push it back up
git push -u origin <branch-name>
# Reopen the PR (gh closed it when the branch went away)
gh pr reopen <N>
# Verify it's back
gh pr view <N> --json state,mergeable,mergeStateStatus
# Then merge with --auto
gh pr merge <N> --squash --auto
No local copy of the branch? (Common when the PR was authored in another session/worktree, or
you discarded the local branch.) The commits are still reachable via the PR's pull ref — restore the
branch from there; no git reflog or colleague clone needed:
SHA=$(gh pr view <N> --json headRefOid -q .headRefOid) # PR keeps the head SHA even after delete
git fetch origin refs/pull/<N>/head # the commits live here regardless of the branch
git push origin "$SHA:refs/heads/<branch-name>" # recreate the branch at the EXACT SHA → PR re-links
gh pr reopen <N> # delete had flipped it to CLOSED
gh pr ready <N> # also un-draft if it was a draft (Failure C)
gh pr merge <N> --squash # the re-push may re-trigger CI → wait for it
gh pr merge <N> --squash errors GraphQL: Pull Request is still a draft (mergePullRequest). The PR
is a draft; mark it ready, then merge:
gh pr ready <N> # un-draft
gh pr merge <N> --squash
The real danger is the combination: a "merge then clean up the branch" routine where the cleanup deletes the remote head ref whenever the branch still exists. On a draft PR the merge is refused but the branch still exists → the cleanup deletes it → the PR closes. Gate every branch delete on merge-success, never on branch-existence:
gh pr merge <N> --squash
if [ "$(gh pr view <N> --json mergedAt -q .mergedAt)" != "null" ]; then
# delete remote ref only now
fi
After applying --auto:
gh pr view <N> --json state should still show OPEN immediately after the commandgh pr view <N> --json state,mergedAt shows {state: MERGED, mergedAt: <timestamp>}Session ending PR #915 (a docs handoff), 2026-05-19:
$ gh pr merge 915 --squash
To have the pull request merged after all the requirements have been met, add the `--auto` flag.
Run the following to resolve the merge conflicts locally:
gh pr checkout 915 && git fetch origin main && git merge origin/main
$ gh pr view 915 --json state,mergeable,mergeStateStatus
{"mergeable":"MERGEABLE","mergeStateStatus":"UNSTABLE","state":"OPEN"}
^^^^^^^^
not DIRTY → no real conflicts; pending checks
$ gh pr merge 915 --squash --auto
# (silent success — queues for CI)
(Earlier in the same session, the same orchestrator hit Failure B on the same PR by running
git push origin --delete docs/s207-handoff immediately after gh pr merge returned the conflict
warning — the PR flipped to CLOSED. Recovered with git push -u origin docs/s207-handoff +
gh pr reopen 915 + gh pr merge 915 --squash --auto.)
PR #398 (a docs deliverable), 2026-06-08 — the Failure-C-plus-delete combo: gh pr merge 398 --squash
errored Pull Request is still a draft (mergePullRequest), but the same script's cleanup step
(if branch exists → gh api -X DELETE …) ran anyway and deleted the head branch, closing the PR.
The branch was authored in another session (no local copy). Recovered via the pull ref:
SHA=$(gh pr view 398 --json headRefOid -q .headRefOid) → git push origin "$SHA:refs/heads/<branch>"
→ gh pr reopen 398 → gh pr ready 398 → gh pr merge 398 --squash (waited for the re-triggered CI).
Fix that prevented a repeat: gate the delete on mergedAt != null, not on branch existence.
gh pr merge errors. The merge may not have
landed. Check gh pr view <N> --json state,mergedAt first; only delete if mergedAt is non-null.--auto is safe to use even when checks pass immediately. If the PR is already CLEAN, --auto
merges instantly. No downside to using it as the default.mergeStateStatus stays UNSTABLE for >5min after a push,
check gh pr checks <N> to see which check is hanging. A common cause is a paths-filter workflow
that didn't trigger because the PR touched no matching paths — that check stays "pending" forever
and blocks merge until the rule is updated.gh-pr-merge-worktree-checkout-trap — when gh pr merge --delete-branch
fails with fatal: 'main' is already used by worktree at .... That's a LOCAL-side failure of the
post-merge branch checkout; the GitHub merge itself succeeds. Different beast from the failures
documented here — verify by checking gh pr view <N> --json mergedAt.--auto is essentially mandatory — no human can merge instantly if checks aren't done. Build the
habit project-wide.gh-pr-merge-worktree-checkout-trap — in this same plugin
(source)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.