Skip to content

Add a review-pr command#8126

Merged
andrewlock merged 4 commits intomasterfrom
andrew/add-review-command
Feb 4, 2026
Merged

Add a review-pr command#8126
andrewlock merged 4 commits intomasterfrom
andrew/add-review-command

Conversation

@andrewlock
Copy link
Member

Summary of changes

Adds a claude command for leaving comments on a PR

Reason for change

I had this locally, and was asked to add it centrally

Implementation details

Copied my version to here

Test coverage

I've run it locally, we can iterate

Other details

There's an existing /review command, but I find it doesn't work quite like I would like 😄

@andrewlock andrewlock requested a review from a team as a code owner February 2, 2026 13:18
@andrewlock andrewlock added the area:builds project files, build scripts, pipelines, versioning, releases, packages label Feb 2, 2026
@pr-commenter
Copy link

pr-commenter bot commented Feb 2, 2026

Benchmarks

Benchmark execution time: 2026-02-02 17:04:42

Comparing candidate commit 716b436 in PR branch andrew/add-review-command with baseline commit c9cca03 in branch master.

Found 4 performance improvements and 7 performance regressions! Performance is the same for 166 metrics, 15 unstable metrics.

scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild net6.0

  • 🟥 throughput [-8222.248op/s; -7481.853op/s] or [-6.510%; -5.924%]

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟥 execution_time [+79.602ms; +79.696ms] or [+65.809%; +65.887%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟩 execution_time [-26.329ms; -21.734ms] or [-11.981%; -9.890%]

scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0

  • 🟥 execution_time [+21.090ms; +21.878ms] or [+11.814%; +12.255%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+12.340ms; +17.700ms] or [+6.284%; +9.014%]
  • 🟩 throughput [+136.821op/s; +166.399op/s] or [+12.911%; +15.702%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0

  • 🟩 execution_time [-171.018µs; -166.689µs] or [-10.907%; -10.631%]
  • 🟩 throughput [+75.939op/s; +78.001op/s] or [+11.907%; +12.230%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice netcoreapp3.1

  • 🟥 throughput [-165.983op/s; -122.028op/s] or [-33.236%; -24.435%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net472

  • 🟥 throughput [-69601.365op/s; -66203.458op/s] or [-9.806%; -9.327%]

scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin netcoreapp3.1

  • 🟥 execution_time [+11.933ms; +17.448ms] or [+6.129%; +8.962%]

- Every issue must have a file path and line number
- Use line numbers from the diff, not absolute line numbers
- Post inline comments using the `gh api` call
- Keep the summary brief; put details in inline comments No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing newline at end of file. This is a common coding standard.

🤖 Claude Code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are an expert code reviewer


**Part A: Inline File Comments**
- For each specific issue you found, create a GitHub API call
- Use the format: `gh api -X POST -H "Accept: application/vnd.github+json" "repos/{owner}/{repo}/pulls/{pull_number}/comments" -f body="Your file-level comment" -f path="path/to/file" -f position=<line_number>`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gh api command format shown here uses position which is deprecated/unreliable for the PR comments API. The GitHub API now requires line, side, and commit_id parameters for reliable comment positioning.

Suggested fix:

gh api -X POST -H "Accept: application/vnd.github+json" "repos/{owner}/{repo}/pulls/{pull_number}/comments"   -f body="Your comment"   -f path="path/to/file"   -F line=<line_number>   -f side="RIGHT"   -f commit_id="<commit_sha>"

Note: Use -F (not -f) for numeric values like line.

🤖 Claude Code

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it didn't work the first time, but it seemed to fix itself, but I'm unsure if that is why each comment is its own review?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, it attempted to post, got the error message and resolved it all on its own

To perform the review, follow these steps:

1. Extract the PR number from the URL or use it directly if a number is provided
2. Use Bash("gh pr view <number>") to get PR details
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the --repo flag to the gh commands (e.g., gh pr view <number> --repo {owner}/{repo}). Without it, these commands will only work when the user's current working directory is in a clone of the target repository. Adding the flag makes the command work from any directory.

🤖 Claude Code

@bouwkast
Copy link
Collaborator

bouwkast commented Feb 2, 2026

PR Review Summary

This PR adds a useful Claude command for automated PR reviews. The overall structure and approach are sound. I found a few issues that should be addressed:

  1. API format issue: The documented gh api command uses position which doesn't work reliably with the current GitHub API. It requires line, side, and commit_id parameters instead (I discovered this while using the command itself).
  2. Missing --repo flag: The gh commands should include --repo to work when reviewing PRs from repositories other than the current working directory.
  3. Missing trailing newline: Minor style issue at end of file.

Review by 🤖 Claude Code

@bouwkast
Copy link
Collaborator

bouwkast commented Feb 2, 2026

This was the error Claude gave me

  ⎿  Error: Exit code 1
     gh: Invalid request.

     No subschema in "oneOf" matched.
     "positioning" wasn't supplied.
     For 'properties/position', "50" is not an integer.
     "in_reply_to" wasn't supplied.
     "position" is not a permitted key.
     "line" wasn't supplied.
     "position" is not a permitted key.
     … +3 lines (ctrl+o to see all)

@andrewlock
Copy link
Member Author

PR Review Summary

This PR adds a useful Claude command for automated PR reviews. The implementation is well-structured and the recent fixes (adding --repo flags, fixing the API format with -F line, adding trailing newline) have addressed the critical issues.

I found three areas for improvement: (1) the argument hint could better reflect that PR numbers are accepted, not just URLs, (2) the instructions don't explain where to get the commit_id parameter, which is required for the API call, and (3) the guidance about line numbers is potentially confusing and could lead to using diff positions instead of actual file line numbers.

Review by 🤖 Claude Code


**Part A: Inline File Comments**
- For each specific issue you found, create a GitHub API call
- Use the format: `gh api -X POST -H "Accept: application/vnd.github+json" "repos/{owner}/{repo}/pulls/{pull_number}/comments" -f body="Your file-level comment" -f path="path/to/file" -F line=<line_number> -f side="RIGHT" -f commit_id="<commit_sha>"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gh API command format may fail if the comment body contains quotes, newlines, or special characters. The -f body="..." flag doesn't properly escape multi-line content or quotes within the comment text.

Consider using a heredoc or temp file approach for the body content:

gh api ... -f body="$(cat <<'EOF'
Your comment here
EOF
)"

This is especially important since review comments often include code snippets with quotes.

🤖 Claude Code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, I'm sure you can figure it out


**Part A: Inline File Comments**
- For each specific issue you found, create a GitHub API call
- Use the format: `gh api -X POST -H "Accept: application/vnd.github+json" "repos/{owner}/{repo}/pulls/{pull_number}/comments" -f body="Your file-level comment" -f path="path/to/file" -F line=<line_number> -f side="RIGHT" -f commit_id="<commit_sha>"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no error handling guidance for the gh API calls. If a comment fails to post (e.g., due to invalid line number, file not in diff, or API rate limits), the command will continue posting other comments without notifying the user of partial failures.

Consider adding guidance to:

  1. Check the exit code of each gh api call
  2. Aggregate any errors and report them to the user
  3. Handle the case where a line number doesn't exist in the PR diff (GitHub will reject the comment)

🤖 Claude Code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pfft, you do that by default

@lucaspimentel
Copy link
Member

There's an existing /review command, but I find it doesn't work quite like I would like

fwiw, there are also PR review plugins in the official marketplace:
https://github.com/anthropics/claude-plugins-official/tree/main/plugins/code-review
(I think they are migrating some of the built-in / commands into plugins and skills)

Copy link
Member

@lucaspimentel lucaspimentel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it and iterate, go go go

@andrewlock andrewlock merged commit 723078c into master Feb 4, 2026
98 of 101 checks passed
@andrewlock andrewlock deleted the andrew/add-review-command branch February 4, 2026 08:58
@github-actions github-actions bot added this to the vNext-v3 milestone Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:builds project files, build scripts, pipelines, versioning, releases, packages area:docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants