HOW-TO · DEV

How to use Claude Code to review a pull request from the command line

intermediate15 minBy Eruo Fredoline
Target environment
Ubuntu 24.04 · Claude Code 1.xmacOS 14.x · Claude Code 1.x
PREREQUISITES

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

  1. Navigate to the local copy of the repository in a terminal window using cd /path/to/repo.
  2. Fetch the latest remote branches by running git fetch origin to ensure the PR branch is up to date.
  3. Start the review by running claude review pr <pr-number>, replacing <pr-number> with the actual pull request number from the platform.
  4. For repositories hosted on GitHub, use claude review pr --repo owner/repo --pr 42 to specify the repository and PR number directly.
  5. Claude Code connects to the remote, retrieves the diff, and begins analyzing the code changes.
  6. Review the generated report, which is organized by file and highlights findings in categories such as bugs, security issues, performance concerns, and style violations.
  7. Request deeper analysis on a specific finding by referencing its identifier, for example "Explain finding B-7 in more detail".
  8. 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.
  9. Mark individual findings as resolved or dismissed using the claude review resolve <finding-id> command.
  10. 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

  1. 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 store and perform a manual fetch once to cache the credentials.

  2. 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.

  3. 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_proxy and https_proxy before running the command.

  4. Repository is a shallow clone — A shallow clone may not contain the full commit history needed for contextual review. Run git fetch --unshallow to 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