Ravindra BagaleCourses & study guides Track your progress
AI CODING ASSISTANTS · CHAPTER 5 · WORKFLOWS

How to Do Code Review with AI

AI can read a diff and spot missing tests, rough edges and obvious bugs. It cannot replace a human who knows the product. Use it as a first pass, then review yourself.

In short: feed the diff (not secrets), ask for risks + missing tests + style issues, treat findings as questions, and never auto-merge because the bot said LGTM.

Why use AI in review

WHY

Humans get tired on large PRs. AI is steady at scanning for null checks, SQL string building, and missing assertions. Humans still judge product intent, security context and “should we build this at all?”.

What to give the reviewer AI

WHAT
  • The diff: git diff main...HEAD or the PR patch — not the whole history.
  • Intent: one sentence: “adds GST helper used by checkout”.
  • Constraints: language version, “no new deps”, security rules.
  • Ask list: bugs, missing tests, secrets, performance only if relevant.

How AI-assisted review flows

1 · Collect the diff no .env files 2 · State PR intent one sentence 3 · AI first pass risks + tests 4 · Human review product + security 5 · Reply on PR you own the comment
REVIEW PROMPT (COPY)

Review this diff for: (1) correctness bugs, (2) missing tests, (3) security (secrets, injection), (4) accidental scope creep. Repo rules: Python 3.12, pytest required for new logic. Reply as a checklist. Do not rewrite the whole PR.

How to review step by step

HOW
  1. Run the tests and linters locally or in CI before asking the AI.
  2. Paste or attach only the diff (or use Copilot / Cursor PR helpers that already see the change).
  3. Ask for a checklist, not a full rewrite.
  4. Verify each finding against the code. Discard false positives politely.
  5. Leave human comments on the PR — you are responsible for what you approve.
AI is good atYou must still check
Missing edge-case testsDoes this match the product need?
Obvious null / error handling gapsAuth, privacy, and company policy
Accidental debug prints / TODOsArchitecture and long-term ownership
Inconsistent naming in the diffWhether the feature should ship
Rule: never paste production secrets, customer data or private keys into a cloud review chat. Use a company-approved tool or redacted diffs.

Tools (real products)

  1. GitHub Copilot on GitHub.com can help with PR summaries and coding questions (features depend on your plan — check GitHub’s current docs).
  2. Claude / ChatGPT / Cursor: paste a redacted git diff and the review prompt above.
  3. IDE agent: “review the uncommitted diff; list risks only.”
  4. Settings: store the review checklist in CONTRIBUTING.md or project rules so every PR gets the same bar.

Quick quiz

1. Can AI alone approve a PR?

No. A human who understands the product must own the approve.

2. What should you paste?

The diff and intent — never secrets or full production data.

3. What is a useful AI output format?

A short checklist of risks, missing tests and scope creep.

4. What do you do with each finding?

Verify it in the code; discard false positives.

Save tokens and money

SMART AI USE

Review the diff, not five historical commits. One structured pass beats three vague “any bugs?” chats.

Save these cards

INTERVIEW CARDAI Coding

How do you use AI in code review?

Diff + intent → checklist of risks and missing tests.
Human still owns the approve; no secret pasting.
Ravindra Bagale · ravindrabagale.com/ai-coding
COMPARISON CARDAI Coding

AI pass vs human pass

AI: steady scan for bugs/tests/style.
Human: product intent, security context, merge decision.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

Review in 3

Diff + intent.
AI checklist.
Human verify + approve.
Ravindra Bagale · ravindrabagale.com/ai-coding