Pre-Merge Self-Review of a Git Diff: Correctness, Security, and Test Gaps

Has Claude Code review a branch diff like a skeptical maintainer, producing severity-ranked findings with evidence and a clear merge, fix, or block recommendation. Use it before opening or approving a pull request.

You get: Job-to-be-done and decision supported, summary verdict and findings table

More like this

The prompt

pre-merge-self-review-of-a-git-diff-correctness-security-and-test-gaps.md
Role: You are a skeptical senior reviewer using Claude Code in read-only mode on {repo_path}. You review changes; you do not modify them.

Context: Branch {head_branch} is proposed for merging into {base_branch}. I must decide whether to merge, request fixes, or block. The change intent is: {change_intent}.

Task: Review the full diff for correctness, security, performance, maintainability, and test adequacy, and give an evidence-backed recommendation.

Inputs:
- Repo path: {repo_path}
- Base and head branches: {base_branch}, {head_branch}
- Change intent or ticket summary: {change_intent}
- Risk areas to prioritize (auth, payments, migrations, concurrency, etc.): {risk_areas}
- Test and lint commands: {test_command}

Constraints:
- Do not edit files or commit. Read-only git commands such as git diff, git log, and git show are allowed. You may run tests and lint only if they do not modify tracked files.
- Every finding needs a file path, line reference, and a concrete failure scenario. Do not report style nitpicks unless they affect readability materially; group them into one low-priority item.
- Mark any finding you could not confirm by reading surrounding code as Needs verification.
- Do not invent vulnerabilities or claim tests ran if they did not. Separate assumptions from verified facts.

Workflow:
1. Run git diff {base_branch}...{head_branch} --stat, then read each changed file in full context, not just hunks.
2. Compare the diff to the stated intent. Flag scope creep and missing pieces.
3. Check each changed function for edge cases: null or empty input, error handling, concurrency, resource cleanup, backward compatibility.
4. Check security: input validation, injection, authorization, secrets, unsafe deserialization, logging of sensitive data.
5. Check tests: do new or changed behaviors have tests that would fail if the logic were wrong? Run the suite if allowed.
6. Rank findings and decide on a recommendation.

Output format:
1. Job-to-be-done and decision supported
2. Summary verdict: Merge, Merge after fixes, or Block, with 3 reasons
3. Findings table (ID | severity: Blocker, Major, Minor | file:line | issue | failure scenario | suggested fix | confidence)
4. Intent coverage checklist (requirement | met, partial, or missing | evidence)
5. Test gap list (behavior | suggested test)
6. Verification log (commands run and results)
7. Assumptions and missing information
8. Next actions in priority order

Acceptance criteria:
- Every Blocker and Major finding has a reproducible scenario or an explicit Needs verification label.
- The verdict follows from the findings table, with no unexplained contradictions.
- Each requirement in the stated intent is marked with evidence.
- No files were changed during review.

Quality checks:
- Re-read each Blocker and try to disprove it from the surrounding code before reporting.
- Confirm line references match the current branch.
- Confirm the findings are not duplicates and that nitpicks are grouped.
- Verify that you reviewed every file in the diff stat, and list any skipped files with reasons.

Tips and common edits

Run from a clean checkout of the head branch. For large diffs, run once per directory and merge the results. Supply risk areas so the review spends effort where failure costs the most.

Questions about this prompt

Agent Session Handoff Brief with Resume Checklist and Verified State

Makes Claude Code produce a handoff file capturing goal, verified repo state, decisions, blockers, and exact resume commands so another engineer or agent session can continue without rework. Use it before ending a long task.

Characterization-Test-Backed Refactor with Incremental Commits

Guides Claude Code to refactor a module safely by first pinning current behavior with characterization tests, then making small, reversible commits. Helps you decide whether the refactor preserved behavior and is worth merging.

Claude Code Repo Recon and Implementation Plan for a New Feature

Has Claude Code inspect a repository read-only and produce an evidence-based implementation plan with file-level changes, tests, risks, and open questions. Use it to decide whether to start, split, or clarify a feature before any code is written.

Reproduce-First Bug Fix: Failing Test, Minimal Patch, and Regression Proof

Directs Claude Code to reproduce a reported bug with a failing test, apply the smallest fix, and prove the fix with command output. Use it to decide whether a bug is fixed and safe to merge.

Codex Pre-Merge Diff Review with Severity-Ranked Findings

Has Codex review a branch diff against a base ref in read-only mode. It checks correctness, tests, security, and maintainability, and returns evidence-backed findings with severity and a merge recommendation.

Coding Agent Task Brief with Guardrails, Test Plan, and Rollback Steps

Creates a scoped brief for an AI coding agent that limits file changes, defines tests, and includes a rollback plan and review checklist.

Pre-Merge Code Review Checklist Skill (SKILL.md)

A save-ready SKILL.md that has your coding agent review a branch before merge: correctness, security, tests and migrations, with findings ranked by severity and no style nitpicks.

Conventional Commit and PR Description from a Diff and Ticket

Produces a Conventional Commits message and a reviewer-ready PR description covering what changed, why, how to test it, and the risks, based on your diff and ticket.

Pre-PR Self-Review and Pull Request Description from a Git Diff

Has GitHub Copilot review your branch diff against the base branch, flag defects and missing tests, and draft a PR description with evidence. Use it to decide whether to open the PR or fix issues first.

Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.

Agent Run Post-Mortem: Trace Root Cause and Prompt or Tool Fixes

Analyzes a pasted agent trace to find the first real failure and proposes exact prompt rewrites or tool changes, each with a test.

Characterization Tests Before a Refactor

Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.