Submit a PR Review
Invocation: Start only when the user explicitly requests this workflow.
Run gh pr --help on demand if you need flag details.
Close the loop after reviewing someone else’s pull request: turn your findings into a formal GitHub review with the right event, a summary body, and inline comments anchored to the lines they concern.
For the other side - resolving comments left on your own PR - use /gh-resolve-pr-comments.
1. Identify the PR and repo
gh pr view <pr> --json number,url,headRefName,baseRefName,author
gh repo view --json nameWithOwner -q '.nameWithOwner'
Pass an explicit PR number or URL when reviewing a branch you have not checked out. Parse nameWithOwner into {owner} and {repo} for the API calls below.
2. Choose the event
Every review carries exactly one event. Pick it by the strongest finding, not the average:
| Event | Flag | When |
|---|---|---|
| Approve | --approve | The change is correct and meets the bar. Only nits remain, and you are happy to leave them to the author’s discretion. |
| Request changes | --request-changes | At least one blocking issue - a bug, security hole, spec miss, data-loss risk, or convention violation - must change before merge. |
| Comment | --comment | Feedback worth recording but nothing blocking, open questions, or you lack the ownership/context to gate the merge on an area you do not own. |
Etiquette: one blocking finding is enough to request changes - do not soften it to a comment. Conversely, do not request changes over pure style preferences; leave those as comment-level nits and approve.
3. Draft the body and inline comments
Before posting, apply these rules to the review summary and every inline comment. Follow /gh-pr-comments for the full checklist when it is installed.
- Attribution: When
gh api user -q '.login, .type'shows a human account, start the summary body and each inline comment with the> [!NOTE]callout> 🤖 **<model> on behalf of <user>**; skip it on bot or automation accounts. - Preflight scan: Scan the full outgoing payload, including quoted code and command output, for secrets and private details before posting.
- Summary body: Lead with the verdict and its reason. For request-changes, list the blocking items up front with concrete
file:line, behavior, or check citations so the author sees them without scrolling. - Inline comments: Anchor each specific finding to its file and line rather than describing locations in prose. Use
RIGHTfor the new version of the diff,LEFTfor the old. The line must appear in the PR diff or the API rejects the comment.
4. Submit
Before posting a formal APPROVE or REQUEST_CHANGES review, show the chosen verdict, summary body, and inline findings and confirm with the user unless they have already approved the drafted review and verdict.
Write scratch files to a temp directory outside the working tree so they never land in a commit:
scratch="$(mktemp -d)"
Build a single JSON payload in "$scratch/review.json" and post it to the reviews endpoint so the event, body, and any inline comments land as one review and return html_url directly:
{
"event": "REQUEST_CHANGES",
"body": "Summary of the review verdict and reasoning.",
"comments": [
{
"path": "src/auth.ts",
"line": 42,
"side": "RIGHT",
"body": "This dereferences `user` before the null check on line 39."
},
{
"path": "src/auth.ts",
"start_line": 60,
"line": 64,
"side": "RIGHT",
"body": "This whole block duplicates `validateSession`."
}
]
}
For a summary-only review (no inline comments), omit the comments field from "$scratch/review.json" and submit through the same REST call:
gh api "repos/{owner}/{repo}/pulls/<pr>/reviews" --input "$scratch/review.json" --jq '.html_url'
event must be APPROVE, REQUEST_CHANGES, or COMMENT. Omit event to leave the review PENDING (a draft only you can see) when you want to eyeball it on GitHub before publishing. Use start_line with line for a multi-line comment. (If you instead use gh pr review for a summary-only review, note that it does not print a URL; fetch the created review’s html_url from gh api "repos/{owner}/{repo}/pulls/<pr>/reviews" --jq '.[-1].html_url' afterward.)
5. Confirm
Verify that GitHub returned the published review URL (html_url from the REST response). Remove the scratch directory with rm -rf "$scratch". Report the submitted event, the verified review URL, the summary, the count of inline comments, and the PR URL. Done when the published review URL is confirmed and every intended inline comment is attached.
Adapted from t3dotgg/tstack (MIT).