Skip to content
CI/CD & Automation Simple

Pipe Git Diff for Review

Send staged or unstaged changes to Claude for automated code review

Command

"color:#9CA3AF;font-style:italic"># Review staged changes (what you're about to commit)
$ "color:#7C5CFC">git diff "color:#d97757">--staged | "color:#7C5CFC">claude -p "Review these changes" "color:#d97757">--output-format text
  
"color:#9CA3AF;font-style:italic"># Review only TypeScript changes
$ "color:#7C5CFC">git diff "color:#d97757">--staged -- '*.ts' '*.tsx' | \
    "color:#7C5CFC">claude -p "Review ">for type safety issues"
  
"color:#9CA3AF;font-style:italic"># Compare against main branch
$ "color:#7C5CFC">git diff main...HEAD | "color:#7C5CFC">claude -p "Summarize all changes ">for PR description"

Response

## Code Review: Staged Changes

### auth.ts
- Good: Added input validation for email format
- Issue: Missing null check on `user.role` (line +24)

### api.ts
- Good: Rate limiting added to /api/users endpoint
- Suggestion: Consider adding retry-after header

Parsing Code

059669">">const { execSync } = require(059669059669">">'child_process');

059669">">// Review staged changes before committing
059669">">const diff = execSync(059669059669">">'git diff --staged', { encoding: 059669059669">">'utf-8' });
059669">">if (diff.trim()) {
  059669">">const review = execSync(
    059669">`git diff --staged | claude -p "Review these changes059669">" --output-format text`,
    { encoding: 059669059669">">'utf-8', env: { ...process.env, CLAUDECODE: 059669059669">">'' } }
  );
  console.log(review);
}

Gotchas

! Use --staged to review what you're about to commit, not all uncommitted changes
! Limit scope with -- '*.ts' to reduce token cost on large diffs
! Large diffs (1000+ lines) may hit context limits — filter to specific directories

Related Recipes