How to use Claude Code to review a pull request from the command line
Claude Code CLI installed and authenticated, git repository with an open pull request, network access to the remote repository
What this does
Claude Code can fetch pull request details from a git remote, analyze the diff, and produce a structured review report covering code quality, potential bugs, security concerns, and style inconsistencies. This streamlines the review process by automating the initial pass and highlighting areas that warrant human attention.
Steps
- Navigate to the local copy of the repository in a terminal window using
cd /path/to/repo. - Fetch the latest remote branches by running
git fetch originto ensure the PR branch is up to date. - Start the review by running
claude review pr <pr-number>, replacing<pr-number>with the actual pull request number from the platform. - For repositories hosted on GitHub, use
claude review pr --repo owner/repo --pr 42to specify the repository and PR number directly. - Claude Code connects to the remote, retrieves the diff, and begins analyzing the code changes.
- Review the generated report, which is organized by file and highlights findings in categories such as bugs, security issues, performance concerns, and style violations.
- Request deeper analysis on a specific finding by referencing its identifier, for example "Explain finding B-7 in more detail".
- Export the review as a comment on the PR by running
claude review pr --comment --pr <pr-number>which posts the findings as a review comment on the remote platform. - Mark individual findings as resolved or dismissed using the
claude review resolve <finding-id>command. - Close the review session with
/exit.
Verification
claude review pr 42
Expected output:
Pull Request #42: Add user authentication module
Files changed: 4
Findings: 7 total (2 bugs, 1 security, 4 style)
Review saved to: .claude-reviews/review-pr-42-2026-05-29.md
Common failures
Authentication credentials not configured for the remote — The CLI cannot fetch PR details from private repositories without valid git credentials. Run
git config --global credential.helper storeand perform a manual fetch once to cache the credentials.Pull request number does not exist on the remote — The review command fails if the PR has been closed, merged, or the number is incorrect. Confirm the PR exists on the platform and is in an open state before retrying.
Network connectivity issue — The CLI must reach the git remote host to fetch diff data. If behind a corporate firewall, configure the proxy environment variables
http_proxyandhttps_proxybefore running the command.Repository is a shallow clone — A shallow clone may not contain the full commit history needed for contextual review. Run
git fetch --unshallowto download the complete history before initiating the review.
Related guides
- Navigate and edit files using Claude Code's interactive mode
- Configure Claude Code's forbidden tool restrictions for safe usage