claude-mention workflow fails when @claude is used on merged/closed PRs
Problem
The claude-mention workflow fails when someone comments @claude on a PR whose branch has been deleted (typically after merge or close). The workflow unconditionally runs gh pr checkout when github.event.issue.pull_request is truthy, without checking the PR state first.
The failure occurs at step "Check out PR branch (conversation comment)":
fatal: couldn't find remote ref refs/heads/<branch-name>
Since Claude Code never runs, no session log artifact is produced and no response is posted.
Evidence
This has happened at least 3 times in recent history:
| Run ID | Date | Branch | PR |
|---|---|---|---|
| 22220010223 | Feb 20 | claude/pr-1125-20260220-0940 |
#1132 (merged) |
| 22107260356 | Feb 17 | support-local-config |
(deleted) |
| 22032566654 | Feb 15 | fix/select-screen-cleanup |
(deleted) |
Run 22220010223 was triggered by max-sixty commenting "@claude good analysis; please fix in a flup" on PR #1132, which had been merged 11 minutes earlier.
Suggested fix
Add a PR state check before attempting checkout in claude-mention.yaml:
- name: Check out PR branch (conversation comment)
if: github.event.issue.pull_request
run: |
PR_STATE=$(gh pr view ${{ github.event.issue.number }} --json state --jq '.state')
if [ "$PR_STATE" = "OPEN" ]; then
gh pr checkout ${{ github.event.issue.number }}
else
echo "PR is $PR_STATE — staying on default branch"
fi
env:
GH_TOKEN: ${{ secrets.WORKTRUNK_BOT_TOKEN }}
This lets the workflow continue on the default branch for merged/closed PRs, so Claude can at least respond to the comment (even without the PR branch context).
Found by nightly reviewer run 22251582544.
Claude finished @worktrunk-bot's task in 1m 9s —— View job • claude/issue-1140-20260221-0609 • Create PR ➔
Fixing claude-mention workflow for merged/closed PRs
- [x] Read and analyze the current
claude-mention.yamlworkflow - [x] Apply PR state check before
gh pr checkout - [x] Commit and push changes
Summary
Applied the suggested fix to .github/workflows/claude-mention.yaml. The checkout step now checks the PR state via gh pr view before attempting gh pr checkout:
- OPEN PRs: checks out the PR branch as before
- MERGED/CLOSED PRs: logs the state and stays on the default branch, allowing the workflow to continue so Claude can still respond
This prevents the fatal: couldn't find remote ref error that was causing the workflow to fail silently on merged/closed PRs.