The cost of a bad commit (revert, force-push, embarrassed Slack message) is way higher than a 60-second pre-commit check. Most people skip it. AI makes it actually fast.
Who this is for
Anyone who commits 5+ times a day. Solo devs especially — no second pair of eyes downstream.
When to reach for it
Before every commit on a branch that other people will see. Especially when tired, late at night, or rushing.
When this is NOT the right tool
Drive-by typo commits, work-in-progress branches no one else watches. Save the cost for branches that matter.
Step by step
- Set up the prompt as a slash command in Claude Code or a saved snippet in Cursor. Make it one keystroke.
- Run “git diff —staged” mentally or via the agent. The agent should see exactly what you are about to commit.
- Prompt: “Review this staged diff. Flag: leftover console.log / debugger / TODO, missing null checks, accidentally committed secrets, off-by-one risks, and any line you would NOT ship to production.”
- Read the flags. Most are noise; one or two are usually real.
- Fix real ones in-place. Restage. Re-run if anything new staged.
- Commit.
Recommended workflow
Friday evening commit before logging off: /review → flagged a debugger statement and a .env accidentally staged → fixed both → committed → went home without weekend disaster. If the commit is about to ship to Firebase Hosting, run an AI Firebase deploy checks pass right after to catch rewrite-order and region issues before they hit production.
Common mistakes
- Letting the AI commit for you. Always do the commit yourself with intent.
- Accepting every flag. Most are stylistic noise. Use judgment.
- Running the review on unstaged changes. The agent gets confused about what is being committed.
- Skipping when tired — that’s exactly when you most need it.
Advanced tips
- Tailor the flag list to your stack. “leftover dbg!()” for Rust, “any” types for TypeScript.
- Add a “what NOT to flag” line: “Do not flag style preferences or naming bikeshedding.”
- Pair with a pre-commit hook (lefthook, husky) that auto-runs the prompt — true automation.
Copy-ready prompt
Review the following staged git diff. Flag ONLY:
- Forgotten debug code (console.log, debugger, dbg!, print statements not behind a flag)
- Hardcoded secrets, API keys, or credentials
- Obvious null / undefined / type errors
- Off-by-one or boundary mistakes
- Files that should not be committed (.env, .DS_Store, build artifacts)
Do NOT flag style, naming, or refactor ideas.
Diff:
{paste diff}
FAQ
- Slows me down?: 60 seconds. The first time it catches a real issue, ROI proven for the year.
- Replace code review?: No — it’s a pre-filter for your own commits. Real review still happens at PR time.
Related
- AI agent code review workflow
- How to review AI diffs
- Git commit with AI
- AI Debugging Workflow — From Stack Trace to Fix
- AI Migration Prompt Workflow — Framework / Language Migrations
- AI Test Generation Workflow — Tests You Can Actually Trust
Tags: #AI coding #Tutorial #Workflow