
This first part focuses on the foundation: extracting Git diffs and sending them to an LLM for intelligent review.
Why Git Diff Is the Best Starting Point
A common mistake when building AI code reviewers is sending the entire repository to the LLM.
This creates multiple problems:
High token consumption
Slower responses
Increased cost
Poor context relevance
More hallucinations
Modern AI review systems instead focus on Git diffs.
Git diffs provide:
Changed lines
Added code
Removed code
Minimal contextual information
This keeps reviews focused and efficient.
Example:
git diff HEAD~1 HEADOr compare against the main branch:
git diff main...HEADThis approach scales far better in enterprise environments.
High-Level Architecture
The architecture is intentionally simple.
Developer Changes Code
↓
Git Diff Extraction
↓
Prompt Builder
↓
LLM API
↓
AI Review Response
↓
VS Code / PR Comments / CLIThis model can integrate into:
VS Code extensions
Azure DevOps
GitHub Actions
Pull request Automation
Internal Developer Portals
Step 1 — Extract Git Diff in C#
The first step is retrieving code changes from Git.
using System.Diagnostics;
public static class GitHelper
{
public static async Task<string> GetDiffAsync()
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "git",
Arguments = "diff HEAD~1 HEAD",
RedirectStandardOutput = true,
UseShellExecute = false
}
};
process.Start();
string diff =
await process.StandardOutput.ReadToEndAsync();
await process.WaitForExitAsync();
return diff;
}
}This extracts the latest code changes.
Step 2 — Build a Review Prompt
Once the diff is collected, we generate a focused review prompt.
public static string BuildPrompt(string diff)
{
return $@"
You are a senior C# code reviewer.
Review ONLY the changed code.
Focus on:
- Bugs
- Security vulnerabilities
- Null safety
- Performance issues
- Maintainability
Be concise and actionable.
Git Diff:
{diff}
";
}The quality of the prompt directly impacts review quality.
Step 3 — Send Prompt to LLM
Now we send the prompt to the LLM.

Join the conversation! Your thoughts help the community grow.