# AI PR Reviewer (Claude) (`tjgarcia0427/pr-reviewer`) Actor

Reviews any GitHub pull request and returns a structured Markdown review with risks, suggestions, and a confidence score. Free heuristic mode. Optional Claude polish.

- **URL**: https://apify.com/tjgarcia0427/pr-reviewer.md
- **Developed by:** [Tristan Garcia](https://apify.com/tjgarcia0427) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $100.00 / 1,000 review completeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## AI PR Reviewer

Reviews any public GitHub pull request and returns a structured Markdown
review with **summary, risks, suggestions, and a confidence score**.
Cites file:line for every finding. Optional one-click "post the review
as a PR comment" mode (idempotent — same bot comment is edited on
re-runs, never spammed).

### What it does in one run

1. Takes a GitHub PR URL as input
2. Fetches the PR metadata + full diff (paginated)
3. Runs deterministic heuristics against each added line:
   - 🚨 hardcoded secrets (AWS / OpenAI / GitHub token literals)
   - ⚠️ unsafe patterns (`eval()`, `shell=True`, `dangerouslySetInnerHTML`, `DROP TABLE`, `DELETE FROM` without `WHERE`)
   - 🟡 size / testing (huge diffs, source changes without test changes)
   - 🔵 debug leftovers (`console.log`, `print()`, `debugger`)
   - ℹ️ TODO/FIXME markers, empty PR descriptions
4. (Optional) Hands the heuristic findings + diff to Claude for a
   polished narrative summary
5. Computes a principled confidence score (size penalty + critical/high
   deductions + empty-description penalty)
6. Pushes a structured record to the default dataset
7. (Optional) Upserts the rendered Markdown as a single bot comment on
   the PR — same comment edited in place on every re-run, no comment
   spam

### Input

```jsonc
{
  "prUrl": "https://github.com/owner/repo/pull/123",     // required
  "mode": "hybrid",                                       // hybrid | heuristic | llm
  "anthropicApiKey": "sk-ant-...",                        // optional, required for hybrid/llm
  "model": "claude-sonnet-4-20250514",                    // sonnet | opus | haiku
  "githubToken": "ghp_...",                               // optional, raises rate limits and enables postComment
  "postComment": false                                    // upsert review as a PR comment
}
````

**Mode comparison:**

| Mode | API key needed | Cost | Output style |
|---|---|---|---|
| `heuristic` | None | Free (Apify compute only) | Deterministic, file:line cited findings, principled confidence |
| `hybrid` (default) | Anthropic | Cheap (prompt-cached system prompt) | Heuristic findings + LLM narrative summary |
| `llm` | Anthropic | Slightly higher | Pure LLM (skip heuristics) |

If you pick `hybrid` without an API key the Actor falls back to
`heuristic` automatically — never fails.

### Output

Dataset record:

```json
{
  "pr": "https://github.com/owner/repo/pull/123",
  "title": "...",
  "author": "...",
  "stats": { "files": 4, "additions": 666, "deletions": 0 },
  "mode": "hybrid",
  "confidence": { "score": 0.65, "label": "Medium" },
  "findings": [
    { "severity": "critical", "category": "security", "message": "...", "file": "src/x.ts", "line": 42 }
  ],
  "markdown": "<!-- claude-review-bot:do-not-remove -->\n### AI PR Review — ..."
}
```

The `markdown` field is the rendered review you'd paste into Slack /
Discord / wherever. Use `postComment: true` to skip the copy-paste.

### Try it free first

The default input (`https://github.com/psf/requests/pull/7401`) is a
small, real merged PR. Click **Run** with default settings and the
heuristic-mode review completes in <10 seconds and is free
(Apify compute is included in your free tier).

### Pricing

This Actor uses **Pay-Per-Event** pricing — you pay only when a review
completes. Specifics are listed on the Actor's detail page on the Apify
Store.

(For the developer of this Actor: the SDK fires
`Actor.charge('review-completed')` exactly once per completed review.
Configure the unit price for the `review-completed` event in
Console → Actor → Publication → Pricing.)

### Bring your own API keys

Both the GitHub token and the Anthropic key are passed via the input,
**not stored** by the Actor. They live only in the run logs and are
masked in the UI. For long-term automation, use the Actor's
"Schedule" feature and set the keys once as Actor secrets so they don't
appear in every run config.

### Common questions

**Does this train on my code?** No. The Anthropic API call is made from
your run only, with no logging beyond Apify's standard run output.
Toggle `mode: heuristic` to avoid any LLM call.

**Will it work on private PRs?** Yes if you supply a `githubToken` with
`repo` scope on the host repository.

**Can I run it on a schedule?** Yes. Use Apify's Schedules feature and
point it at a PR URL pattern, or run it from a webhook trigger when
PRs open.

**What languages does the heuristic mode cover?** Python, TypeScript,
JavaScript, Go, Rust, Java, Ruby, PHP, C## for source/test detection.
Regex patterns (secrets, SQL, dangerous calls) are language-agnostic.

### Roadmap

Open to feedback — message me via the Apify Store contact. Likely next
additions:

- GitLab / Bitbucket support
- Custom rule packs (your team's "we don't do X" rules as YAML)
- Inline GitHub review comments (line-by-line) instead of a single
  summary comment
- OpenAI / Mistral backends as alternatives to Claude

# Actor input Schema

## `prUrl` (type: `string`):

Full URL of the public GitHub PR to review (e.g. https://github.com/owner/repo/pull/123).

## `mode` (type: `string`):

hybrid uses heuristics + LLM polish (recommended). heuristic is deterministic, no API key needed. llm skips heuristics and uses pure LLM.

## `anthropicApiKey` (type: `string`):

Required for hybrid and llm modes. Get one at console.anthropic.com. Leave blank to force heuristic-only mode.

## `model` (type: `string`):

Anthropic model ID to use when an API key is set.

## `githubToken` (type: `string`):

Optional GitHub PAT for higher rate limits or private PRs. Public PRs work without one.

## `postComment` (type: `boolean`):

If true, the review is upserted as a single bot comment on the PR (idempotent — same comment is edited on re-runs). Requires a GitHub token with write access.

## Actor input object example

```json
{
  "prUrl": "https://github.com/psf/requests/pull/7401",
  "mode": "hybrid",
  "model": "claude-sonnet-4-20250514",
  "postComment": false
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "prUrl": "https://github.com/psf/requests/pull/7401"
};

// Run the Actor and wait for it to finish
const run = await client.actor("tjgarcia0427/pr-reviewer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "prUrl": "https://github.com/psf/requests/pull/7401" }

# Run the Actor and wait for it to finish
run = client.actor("tjgarcia0427/pr-reviewer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "prUrl": "https://github.com/psf/requests/pull/7401"
}' |
apify call tjgarcia0427/pr-reviewer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=tjgarcia0427/pr-reviewer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "AI PR Reviewer (Claude)",
        "description": "Reviews any GitHub pull request and returns a structured Markdown review with risks, suggestions, and a confidence score. Free heuristic mode. Optional Claude polish.",
        "version": "0.1",
        "x-build-id": "tU0smHcYSaenfSonN"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/tjgarcia0427~pr-reviewer/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-tjgarcia0427-pr-reviewer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/tjgarcia0427~pr-reviewer/runs": {
            "post": {
                "operationId": "runs-sync-tjgarcia0427-pr-reviewer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/tjgarcia0427~pr-reviewer/run-sync": {
            "post": {
                "operationId": "run-sync-tjgarcia0427-pr-reviewer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "prUrl"
                ],
                "properties": {
                    "prUrl": {
                        "title": "Pull Request URL",
                        "pattern": "^https?://github\\.com/[^/]+/[^/]+/pull/\\d+/?$",
                        "type": "string",
                        "description": "Full URL of the public GitHub PR to review (e.g. https://github.com/owner/repo/pull/123)."
                    },
                    "mode": {
                        "title": "Review mode",
                        "enum": [
                            "hybrid",
                            "heuristic",
                            "llm"
                        ],
                        "type": "string",
                        "description": "hybrid uses heuristics + LLM polish (recommended). heuristic is deterministic, no API key needed. llm skips heuristics and uses pure LLM.",
                        "default": "hybrid"
                    },
                    "anthropicApiKey": {
                        "title": "Anthropic API key (optional)",
                        "type": "string",
                        "description": "Required for hybrid and llm modes. Get one at console.anthropic.com. Leave blank to force heuristic-only mode."
                    },
                    "model": {
                        "title": "Claude model",
                        "enum": [
                            "claude-sonnet-4-20250514",
                            "claude-opus-4-20250514",
                            "claude-haiku-4-5-20251001"
                        ],
                        "type": "string",
                        "description": "Anthropic model ID to use when an API key is set.",
                        "default": "claude-sonnet-4-20250514"
                    },
                    "githubToken": {
                        "title": "GitHub token (optional)",
                        "type": "string",
                        "description": "Optional GitHub PAT for higher rate limits or private PRs. Public PRs work without one."
                    },
                    "postComment": {
                        "title": "Post review as a PR comment",
                        "type": "boolean",
                        "description": "If true, the review is upserted as a single bot comment on the PR (idempotent — same comment is edited on re-runs). Requires a GitHub token with write access.",
                        "default": false
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
