Skip to content

unaaa-yu/code_review_cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code-review-cli

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

Features

  • One command — paste a GitHub PR URL, get a Markdown report
  • Claude-powered — uses claude-sonnet-4-5 with 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

Architecture

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]
Loading

Module responsibilities

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

Installation

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

Usage

Review a PR

codereview run https://github.com/owner/repo/pull/42

Options:

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

Check auth

codereview auth

Output format

# 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"  # ← flagged

Suggestion: Load from environment variable: os.environ["SECRET_KEY"]

🟡 MEDIUM — auth/login.py line 34

...


---

## Development

```bash
pip install -e ".[dev]"
pytest tests/ -v

Tech stack

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages