PR Review Assistant
Get instant AI-powered code reviews. Identify bugs, security issues, and improvement suggestions for any GitHub pull request.
What it does
- Fetches PR metadata (title, description) from GitHub
- Retrieves the full diff of changes
- Sends both to Claude for comprehensive code review
- Returns structured feedback with actionable suggestions
Prerequisites
cli4ai add github- Install the GitHub packagecli4ai secrets set GITHUB_TOKEN- Configure your GitHub tokenclaudeCLI installed and authenticated
Usage
# Review a specific PR
cli4ai routines run pr-review --var repo=owner/repo --var pr=123
# Preview the review request
cli4ai routines run pr-review --var repo=owner/repo --var pr=123 --dry-run Variables
| Variable | Required | Description |
|---|---|---|
repo | Yes | Repository in owner/repo format |
pr | Yes | Pull request number |
JSON Version
Save as ~/.cli4ai/routines/pr-review.routine.json
{
"version": 1,
"name": "pr-review",
"description": "Generate AI-powered code review suggestions for GitHub PRs",
"vars": {
"repo": { "required": true },
"pr": { "required": true }
},
"steps": [
{
"id": "pr-info",
"type": "cli4ai",
"package": "github",
"command": "pr",
"args": ["{{vars.repo}}", "{{vars.pr}}"],
"capture": "json"
},
{
"id": "diff",
"type": "cli4ai",
"package": "github",
"command": "diff",
"args": ["{{vars.repo}}", "{{vars.pr}}"],
"capture": "text"
},
{
"id": "review",
"type": "exec",
"cmd": "bash",
"args": ["-c", "echo \"Review this pull request. Identify bugs, security issues, and suggest improvements.\n\nTitle: $TITLE\nDescription: $DESCRIPTION\n\nDiff:\n$DIFF\" | claude --print"],
"env": {
"TITLE": "{{steps.pr-info.json.title}}",
"DESCRIPTION": "{{steps.pr-info.json.body}}",
"DIFF": "{{steps.diff.stdout}}"
},
"capture": "text",
"timeout": 120000
}
],
"result": "{{steps.review.stdout}}"
} Bash Version
Save as ~/.cli4ai/routines/pr-review.routine.sh
#!/usr/bin/env bash
set -euo pipefail
# pr-review.routine.sh
# Usage: cli4ai routines run pr-review --var repo=owner/repo --var pr=123
REPO="${CLI4AI_VAR_REPO:?repo is required}"
PR="${CLI4AI_VAR_PR:?pr number is required}"
echo "🔍 Fetching PR #$PR from $REPO..." >&2
# Get PR info
PR_INFO=$(cli4ai run github pr "$REPO" "$PR")
TITLE=$(echo "$PR_INFO" | jq -r '.title')
DESCRIPTION=$(echo "$PR_INFO" | jq -r '.body // "No description"')
# Get diff
echo "📝 Fetching diff..." >&2
DIFF=$(cli4ai run github diff "$REPO" "$PR")
# Generate review
echo "🤖 Generating review..." >&2
echo -e "Review this pull request. Identify bugs, security issues, and suggest improvements.
Title: $TITLE
Description: $DESCRIPTION
Diff:
$DIFF" | claude --print Tips
- Customize the prompt to focus on your team's coding standards
- Add a step to post the review as a GitHub comment
- Chain with Slack to notify the PR author of the review