v0.3.0 Open source · MIT · runs on your machine

AI code reviews that cite the right line.

diff2ai turns your Git diff into a focused, line-numbered review prompt, runs it through the AI CLI you already use, cross-checks the findings, and posts them as inline PR comments. diff2ai itself makes no network calls.

npm i -g diff2ai
Get started
Works with claude codex gemini opencode cursor ollama:<model> your own CLI
Why diff2ai

A raw diff in a chat box isn't a code review.

diff2ai builds the prompt from your actual change — line-numbered diff, commit messages, file summary — with a strict output schema, so what comes back has severities, exact file:line references and concrete fixes.

−Reviews cite line numbers that don't exist.
+ Every diff line is prefixed with its real line number in the new file, so findings point at the right place.
−One model, one pass, confident hallucinations.
+ Several reviewer personas, a judge that validates against the diff, and a zero-token mechanical check.
−Hosted bots want your code and a per-seat subscription.
+ Runs locally through the AI CLI you already pay for — or no AI at all: just copy the prompt.
Features

Everything between git diff and a merged PR.

Use one piece or the whole flow — prompt only, an AI run, a consensus review, or a CI gate.

Any AI CLI

--run claude, codex, gemini, opencode, cursor or ollama:<model>. Add your own runner in config.

Multi-reviewer consensus

Personas review in parallel; a judge merges, dedupes and scores Consensus: k/N.

Line-accurate findings

Line-numbered diffs plus commit messages and a file summary give the model intent and exact locations.

Posts where you review

Inline review comments on GitHub PRs via gh, or a formatted MR note on GitLab via glab.

CI-ready

A GitHub Action, SARIF export for code scanning and --fail-on HIGH severity gates.

Local-first

Pure git. Nothing leaves your machine unless you run an AI or post a comment, with your own credentials.

Big diffs welcome

Token-budgeted batches that split at file and hunk boundaries, with template overhead counted.

Injection-aware

Diffs and commit messages are untrusted input: instructions hidden in a PR are reported, not followed.

--iterations 3

Several reviewers. One judge. Then a check that can't hallucinate.

One AI review can invent problems or miss real ones. Consensus mode runs independent persona passes, has a judge validate every finding against the diff, then re-checks the judge locally.

  1. Build the prompt

    Line-numbered diff, commit messages and a file summary, wrapped in a strict review schema.

    --template
  2. Pick reviewers

    Suggested from diff signals, or picked by one small AI call. You approve, and see the cost first.

    --personas auto
  3. Review in parallel

    Bug Hunter, Security Auditor, Performance, API, Test Engineer — each a full, independent pass.

    --concurrency 3
  4. Judge

    Gets the diff as ground truth plus all reviews; validates, deduplicates and scores agreement.

    Consensus: 3/3
  5. Mechanical check

    Every finding's file and lines are verified against the hunks locally. Misses are demoted.

    0 tokens
Then: --then fix --then comment diff2ai post latest diff2ai export --format sarif

Cost, honestly: every reviewer is a full model invocation over your whole diff, plus the judge. Use 2–3 targeted personas for risky PRs and plain --run for everyday changes.

Prompt in, findings out

What the AI sees, and what you get back.

Line numbers make findings verifiable even in a plain web chat. The packaged templates enforce numbered issue blocks: no preamble, no diff echo.

review_*.md · annotated diff
diff --git a/src/auth/session.ts b/src/auth/session.ts@@ -38,6 +38,9 @@ export async function getSession(req) {  38    const token = req.headers.authorization;      -  const user = await db.users.findByToken(token);  39 +  const user = await db.query(  40 +    `SELECT * FROM users WHERE token = '${token}'`  41 +  );  42    if (!user) return null;

New-file line numbers on every kept and added line; removed lines have none.

run_*/consolidated.md
## 1) Severity: CRITICAL | Type: Security
Title: Parameterize the session token query

Affected:
- src/auth/session.ts:39-41

Explanation:
The Authorization header is interpolated into raw
SQL, so any caller can inject queries. The helper
it replaced was parameterized.

Proposed fix:
~~~ts
const user = await db.query(
  'SELECT * FROM users WHERE token = $1', [token]);
~~~

Consensus: 3/3 reviewers

Severity, type, exact location, a fix and how many reviewers agreed.

--run <runner>

Bring the AI you already pay for.

In a terminal, --run opens the tool's chat seeded with the review. In scripts and CI it runs headless, read-only where the tool supports it, and saves the review as *.response.md. Large prompts never go through argv.

Runner CLI Headless mode
claude Claude Code claude -p --tools "" — no tools, no saved session
codex OpenAI Codex CLI codex exec --sandbox read-only --ephemeral -
gemini Gemini CLI prompt on stdin, --output-format text
opencode opencode opencode run --agent plan — read-only agent
cursor Cursor CLI -p --mode ask — read-only, reads the prompt file
ollama:<model> Ollama ollama run <model> — fully local
your-tool Anything with a CLI Define it under runners in .aidiff.json
GitHub Action

Review every pull request in CI.

Run any runner on each PR, post inline comments, write SARIF and fail the build on a verified severity.

  • Inline comments

    Findings on changed lines become review comments; the rest go in the review body.

  • SARIF 2.1.0

    Upload to GitHub code scanning, or export findings as JSON.

  • Severity gates

    fail-on: CRITICAL in the action, --fail-on HIGH locally or in a pre-push hook.

  • Reads the diff only

    The action never executes code from the PR.

.github/workflows/ai-review.yml
name: AI review
on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: nurettincoban/diff2ai@v1
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        with:
          runner: claude # codex, gemini, opencode, ...
          iterations: 3 # 1 = single pass
          min-severity: MEDIUM
          fail-on: CRITICAL # optional gate
Compared

Your code, your model, your bill.

diff2ai Hosted review bots Pasting a diff into a chat
Where your code goes Only to the AI CLI you choose — or nowhere, in prompt-only mode The vendor's service The chat provider
Model Claude, Codex, Gemini, OpenCode, Cursor, local Ollama, your own The vendor's choice Whatever you paste into
Cost Your existing AI subscription or API key Usually a per-seat subscription Your chat subscription
Hallucination defense Persona consensus + judge + mechanical diff check Varies None
Line references Line-numbered diff, verified against the hunks Yes Often wrong
Setup npm i -g diff2ai App install and org permissions None
Quickstart

Your first review in a minute.

Requires Node.js 22.13+ and git. Every command works from any subdirectory of the repo.

install & check
$ npm i -g diff2ai
$ diff2ai doctor      # repo state + installed AI CLIs
$ diff2ai interactive # guided wizard
review
$ diff2ai review --run claude
$ diff2ai review --run claude --iterations 3
$ diff2ai review --pr 128 --run codex
no AI CLI? copy the prompt
$ diff2ai review --copy
# paste into any chat; findings come back
# in the same structured format
share the results
$ diff2ai post latest --dry-run
$ diff2ai post latest --pr 128
$ diff2ai export latest --format sarif --out r.sarif

Review your next PR before your teammates do.

Free and open source under the MIT license. Contributions welcome.