Skip to main content

CLI tool that reviews code diffs using LLMs

Project description

PRRev

A CLI tool that reviews code diffs using LLMs. Point it at a local repo or a GitHub PR URL. It sends the diff to Claude or GPT-4o and outputs a structured review with severity ratings, file references, and line numbers.

Install

pip install prrev

Requires Python 3.10+.

Usage

# review uncommitted changes
prrev .

# review only staged changes
prrev . --staged

# review a specific commit
prrev . --commit abc123

# review a commit range
prrev . --range abc123..def456

# review a GitHub PR
prrev https://github.com/user/repo/pull/42

# post review as inline PR comments
prrev https://github.com/user/repo/pull/42 --post

# write review to a markdown file
prrev . --output review.md

# fail in CI if there are warnings or worse
prrev . --fail-on warning

Configuration

Set API keys as environment variables:

export ANTHROPIC_API_KEY=sk-...
export OPENAI_API_KEY=sk-...
export GITHUB_TOKEN=ghp_...

Or use a config file at ~/.config/prrev/config.toml:

[llm]
provider = "anthropic"
model = "claude-sonnet-4-20250514"
anthropic_api_key = "sk-..."

[github]
token = "ghp_..."

[review]
max_items = 20

You can also put a .prrev.toml in your repo root for per-project settings. API keys are ignored in repo config for security. They only load from env vars or the global config.

Precedence: CLI flags > env vars > repo config > global config > defaults.

Providers

# use claude (default)
prrev . --provider anthropic

# use gpt-4o
prrev . --provider openai

# override the model
prrev . --provider anthropic --model claude-sonnet-4-20250514

How It Works

The diff is sent to the LLM using each provider's structured output mechanism: Anthropic's tool use and OpenAI's response_format with a JSON schema. This guarantees the response matches the expected structure at the API level without fragile JSON text parsing.

For large diffs, PRRev automatically chunks by file based on actual token counts (not character estimates) and reviews each chunk in parallel. Results are merged and truncated by severity: suggestions are dropped first, then warnings. Critical issues are never dropped.

Exit Codes

  • 0: review completed, no issues at or above --fail-on threshold
  • 1: issues found at or above --fail-on threshold
  • 2: tool error (missing API key, invalid args, network failure)

Tech Stack

  • Typer: CLI framework
  • Rich: terminal output with colored severity panels
  • GitPython: local diff extraction
  • httpx: GitHub API (fetch PR diffs, post inline comments)
  • Anthropic SDK: Claude API with tool use for structured output
  • OpenAI SDK: GPT-4o API with structured output
  • tiktoken: token counting for OpenAI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prrev-0.1.2.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prrev-0.1.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file prrev-0.1.2.tar.gz.

File metadata

  • Download URL: prrev-0.1.2.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for prrev-0.1.2.tar.gz
Algorithm Hash digest
SHA256 842ce7d767a636d107e6ed3d33061e8f68a285c4ca2afe258d6e74f730d486f8
MD5 051d6ea1f39de7c59745b43912fabe20
BLAKE2b-256 481b8f2076a58232f152417a298c70faf0f9df3eae127146849343ec5f5eadd7

See more details on using hashes here.

File details

Details for the file prrev-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: prrev-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for prrev-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e0bae6cb97044429e2eb200717b79a6aa8ecb67455da24876b26886d7f22a61
MD5 781fe0f35ae53afdea69f73f09af811b
BLAKE2b-256 72cb6e450a5f080e1f33d47f48b8f0c86e719738b99720c80a75cc46e4d5ffa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page