⭐️ If you find diff2ai useful, please give it a star on GitHub — it helps a lot!
Quick links: Installation • Quickstart • CLI • Demos • Configuration
Turn your Git diffs into beautiful, high-signal AI code review prompts — fast, local, and repo-safe.
- ⚡️ Zero network by default (pure git)
- 🧠 Strict, opinionated default template that drives high‑quality AI feedback
- 🧩 Smart chunking for large diffs with merge guidance
- 🛡️ Safety preflight checks; no destructive actions without consent
- 🖼️ Pretty CLI output in TTY; stays script‑friendly for CI
Most AI reviews are noisy. diff2ai generates a focused prompt from your actual diff, with a strict schema that forces actionable feedback (severity, file/line ranges, proposed fix). Paste it into your favorite AI coding agent and get a concise, useful review.
Requirements
- Node.js >= 18
Global install (recommended)
npm i -g diff2ai
diff2ai --version # verify (e.g., 0.0.3)Use without installing (npx)
npx diff2ai --helpUpgrade to latest
npm i -g diff2ai@latest# Generate AI-ready prompt for your MR against main
git fetch origin main
diff2ai review feature/my-branch --target main --copy
# Optional: let diff2ai switch to the branch for you (repo will remain on it)
diff2ai review feature/my-branch --target main --copy --switch --fetch
# Paste the generated prompt from your clipboard into Claude, Cursor, or Copilotreview <ref>: end‑to‑end — generate a diff from a branch/ref and immediately produce an AI prompt (default template). Add--copyto place the prompt on your clipboard. Use--save-diffif you also want the raw.difffile written.- Flags:
--switchSwitch to<ref>before running (refuses if dirty/untracked unless--yes)--fetchFetchorigin/<target>andorigin/<ref>before running
- Flags:
prompt <diff>: render an AI prompt from an existing.difffile.- Flags:
--template <nameOrPath>Use a template by name (project./templates/or packaged) or a direct.mdfile path (absolute or relative)--templates-dir <dir>Directory to resolve named templates from (defaults to project./templates/)
- Flags:
templates: list available templates (project and packaged)diff [--staged]: write a.difffrom your working tree (or staged changes).show <sha>: write a.difffor a specific commit.chunk <diff>: split a large.diffintobatch_*.mdfiles + index.
Global flags (MVP):
--no-interactiveDisable prompts (for CI/non‑TTY)--yesAuto‑confirm safe prompts
Show demos
Review a branch (auto‑prompt + copy to clipboard):
diff2ai review feature/payments --copy
# writes:
# - review_YYYY-MM-DD_HH-mm-ss-SSS.md (default template)
# - copies prompt content to your clipboard
# - add --save-diff to also write review_YYYY-MM-DD_HH-mm-ss-SSS.diff
# Recommended for AI agents (Cursor/Claude):
# Ensure the tool is on the branch being reviewed and fetch refs
diff2ai review feature/payments --target main --copy --switch --fetchPick a template explicitly:
diff2ai review feature/api --template default
# or a minimal one
diff2ai review feature/api --template basic
# or your own project template (./templates/my-template.md)
diff2ai review feature/api --template my-template
# or via direct file path
diff2ai review feature/api --template ./templates/my-template.md
# specify a custom templates directory
diff2ai review feature/api --templates-dir ./my-templates --template code-review
# use packaged templates by name (no copying needed)
diff2ai review feature/api --template security
diff2ai review feature/api --template api-best-practices
diff2ai review feature/api --template reliability
diff2ai review feature/api --template event-drivenWork from an existing diff:
diff2ai diff --staged # produce staged_*.diff
diff2ai prompt staged_*.diff # produce staged_*.md (uses default template)
# with a custom template
diff2ai prompt staged_*.diff --template my-template
# To save the AI response yourself, use native OS commands, e.g. on macOS:
# pbpaste > reviews/review_response.mdHandle big diffs:
diff2ai chunk huge.diff --profile generic-medium
# writes batch_*.md and review_index.md (merge instructions included)The default template enforces a clean, repeatable review structure. AI reviewers must output only numbered issue blocks — no preambles, no conclusions, no diff echo.
Issue block schema:
## <n>) Severity: CRITICAL|HIGH|MEDIUM|LOW|INFO | Type: Implementation|Bug|Security|Test|Performance|Style|Doc|Maintainability
Title: <short imperative>
Affected:
- path/to/file.ext:lineStart-lineEnd
Explanation:
<what is wrong, why it matters, how to fix>
Proposed fix:
~~~<lang>
<minimal snippet or steps>
~~~
For chunked reviews: “Do not assume context outside this chunk; if cross‑file risks are suspected, note briefly.”
Templates available:
default(strict, recommended)basic(lightweight)
## 1) Severity: HIGH | Type: Implementation
Title: Avoid mutation of request body in middleware
Affected:
- src/middleware/auth.ts:42-57
Explanation:
Mutating the incoming request object can introduce side effects across downstream handlers. Use a cloned object or limit changes to a derived value.
Proposed fix:
~~~ts
const sanitized = { ...req.body, password: undefined };
next();
~~~
-
Default output location: current working directory.
-
Recommended: use a dedicated
reviews/directory and add it to.gitignore. -
*.mdAI‑ready prompt (paste into your AI coding agent) -
*.diffunified diff (optional forreviewvia--save-diff; always produced bydiff/show) -
batch_*.mdchunked prompts for large diffs -
review_index.mdguidance for merging batch results into a single review
diff2ai review feature/api --target main --save-diff
# writes reviews/*.md and reviews/*.diff (with --save-diff)Paste the generated *.md into the MR/PR description or as a top comment.
Use the prompt with your AI reviewer. Save the AI’s response locally with diff2ai pasteback and commit or share as needed.
- Preflight checks warn about dirty/untracked files, stash, and divergence.
- Interactive prompts guide target selection; non‑interactive mode stays quiet.
- No destructive actions are taken without explicit confirmation.
--switchwill refuse to change branches if the working tree is dirty or has untracked files unless you pass--yes. The repository remains on<ref>after completion.
Create .aidiff.json (JSON5 supported):
{
target: 'main', // default target branch
profile: 'generic-medium', // default chunking profile
include: ['src/**', 'apps/**'],
exclude: ['**/*.lock', 'dist/**', '**/*.min.*'],
// Optional: default template config
// Use a name (resolved from project ./templates by default) or a file path
template: 'my-template',
// Optional: where to resolve named templates from (defaults to ./templates)
templatesDir: './templates',
}Ignore paths in .aidiffignore (minimatch):
**/*.lock
**/dist/**
**/*.min.*
Profiles (token budgets):
claude-large≈ 150k tokensgeneric-large≈ 100k tokensgeneric-medium≈ 30k tokens
-
Templates directory not found
- Fixed in >= 0.0.2. Update to latest:
npm i -g diff2ai@latest. - If developing locally, ensure
npm run buildcopiedtemplates/intodist/templates/. - Project-local
templates/in your CWD are also supported.
- Fixed in >= 0.0.2. Update to latest:
-
Custom template not found
- When using a name (e.g.,
--template my-template), diff2ai looks for./templates/my-template.mdby default, or under--templates-dir/templatesDirif provided. - You can also pass a direct path:
--template ./my-templates/review.md. - Packaged templates can be used by name without copying (e.g.,
--template security).
- When using a name (e.g.,
-
"Missing required placeholder {diff_content}"
- Your custom template must include
{diff_content}where you want the unified diff injected.
- Your custom template must include
We welcome contributions! Ways to help:
- Improve templates and review schema
- Enhance chunking heuristics and performance
- Add tests and fixtures for edge cases
- Polish CLI UX and docs
Dev setup:
npm install
npm run build
npm test
npm run lint
npm run formatConventional flow:
- Fork & branch (small, focused changes)
- Add tests when adding features/fixing bugs
- Keep files < 300 lines where practical
- Ensure
npm testandnpm run lintpass - Open a PR with a clear description and screenshots/terminal output when relevant
-
“Why did
chunkproduce only one file?”- Your diff likely fits within the selected profile’s token budget; that’s expected.
-
“Where do I put the AI’s response?”
- Wherever you prefer: PR comments, a
review.mdfile, or your internal tools.
- Wherever you prefer: PR comments, a
-
“Can I script this in CI?”
- Yes. Use
--no-interactive(and--yesif needed).
- Yes. Use
-
“Does this upload my code anywhere?”
- No. It runs 100% locally and writes to your filesystem. You decide what to paste into an AI.
-
“How do I handle huge MRs?”
- Use
diff2ai chunk <diff> --profile <name>, paste eachbatch_*.mdto your AI, then merge the results guided byreview_index.md.
- Use
-
“Can I use this on GitLab MRs?”
- Yes. Checkout the MR branch locally (or fetch the refs), then run
diff2ai review <branch> --target <base>.
- Yes. Checkout the MR branch locally (or fetch the refs), then run
MIT