Skip to content
Latchkey

gh pr close: Close a Pull Request from CI

gh pr close closes a pull request without merging, optionally deleting the head branch.

Cleanup jobs close stale or superseded PRs and tidy up their branches with a single gh pr close call.

What it does

gh pr close closes a pull request in the not-merged state. --delete-branch removes the head branch after closing, and --comment leaves a closing comment explaining why.

Common usage

Terminal
gh pr close 123
gh pr close 123 --delete-branch
gh pr close 123 --comment "Superseded by #130"

Flags

FlagWhat it does
-d, --delete-branchDelete the head branch after closing
-c, --comment <text>Leave a comment when closing
-R, --repo <owner/repo>Target a specific repository

In CI

Set GH_TOKEN and permissions: { pull-requests: write, contents: write } if you use --delete-branch (deleting a ref needs contents write). The default GITHUB_TOKEN cannot delete a branch that is protected.

Common errors in CI

"GraphQL: Resource not accessible by integration" means the token lacks pull-requests: write. "failed to delete remote branch ...: HTTP 422" usually means the branch is protected or already gone. Closing an already-closed PR reports it is not open rather than erroring.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →