A command-line tool that pulls a GitHub PR diff and generates a structured code review using Claude.
$ codereview run https://github.com/owner/repo/pull/42
✔ Fetched diff (12 files, 847 lines)
✔ Review complete
📄 Report saved to review_pr42_20260526.md
- One command — paste a GitHub PR URL, get a Markdown report
- Claude-powered — uses
claude-sonnet-4-5with a structured prompt - Multi-file — reviews every changed file in the PR
- Validated output — Pydantic ensures Claude returns structured findings
- Portable — pure CLI, no database, no server, no Docker
graph LR
A[User: PR URL] --> B[cli.py\nClick entry point]
B --> C[github_client.py\nFetch diff via httpx]
C --> D[reviewer.py\nChunk + call Claude]
D --> E[prompt.py\nBuild prompt]
D --> F[validator.py\nParse + validate response]
F --> G[formatter.py\nRender Markdown]
G --> H[report.md]
| Module | Responsibility | Status |
|---|---|---|
cli.py |
Click commands, env var loading, orchestration | ✅ Implemented |
github_client.py |
GitHub REST API, fetch PR metadata + unified diff | ✅ Implemented |
reviewer.py |
Chunk diff by file, call Claude, collect results | ✅ Implemented |
prompt.py |
Build system/user prompt from diff chunk | 📝 In Progress |
validator.py |
Pydantic models, parse Claude JSON response | 📝 In Progress |
formatter.py |
Render ReviewResult → Markdown report |
✅ Implemented |
git clone https://github.com/yourname/code-review-cli
cd code-review-cli
pip install -e .Set your API keys:
export GITHUB_TOKEN=ghp_...
export ANTHROPIC_API_KEY=sk-ant-...Or create a .env file:
GITHUB_TOKEN=ghp_...
ANTHROPIC_API_KEY=sk-ant-...
codereview run https://github.com/owner/repo/pull/42Options:
--output FILE Save report to this path (default: review_pr{N}_{date}.md)
--top-k INT Max files to review (default: 20)
--no-save Print to stdout instead of saving
codereview auth# Code Review — PR #42: Fix authentication bug
**Repository:** owner/repo
**Author:** octocat
**Files reviewed:** 4 of 4
**Generated:** 2026-05-26
---
## Summary
The PR addresses a session token bug. Overall quality is good with two
issues that should be fixed before merging.
---
## Issues
### 🔴 HIGH — `auth/session.py` line 87
**Hardcoded secret key will be exposed in version control.**
```python
SECRET_KEY = "mysecretkey123" # ← flaggedSuggestion: Load from environment variable: os.environ["SECRET_KEY"]
...
---
## Development
```bash
pip install -e ".[dev]"
pytest tests/ -v
| Tool | Why |
|---|---|
| Click | Composable CLI with --help auto-generation and type coercion |
| httpx | Async-capable HTTP with better ergonomics than requests |
| Anthropic SDK | Official client; handles retries and rate limits |
| Pydantic v2 | Validates Claude's JSON output — catches hallucinations early |
| python-dotenv | Loads .env without shell exports |
See ARCHITECTURE.md for design decisions.