
Build a pre-commit script that flags common AI-generated code patterns your team needs to audit
You'll have a working Git hook that scans staged code for patterns like type duplication, swallowed exceptions, orphaned variables, and copy-paste markers—catching AI quality issues before they ship.
What you'll make
AI Code Audit Script
- scan_staged_files() — file detection and filtering: what to include
- detect_ai_patterns() — pattern matching rules: what to include
- format_violations() — human-readable output: what to include
- main() — Git hook integration: what to include
Paste your Python script that can be installed as a pre-commit hook
The 4 parts
Each part ends with a check you can see.
Find AI Fingerprints in Real Code
Examine code your team has written with AI tools to identify detectable patterns that indicate AI generation
Done when
A documented list of 5+ specific code patterns that reliably indicate AI generation vs human authoring in your codebase
Validate Pattern-to-Problem Links
Test whether your detected AI patterns actually correlate with code that needs human review or causes problems
Done when
A ranked list of your AI patterns scored by how reliably they predict code that needed fixes, caused bugs, or required rework
Code the Pattern Scanner
Build the core detection logic that scans staged files for your validated AI patterns and formats violations for developer review
Done when
A working script that processes Git staged files, detects your AI patterns, and outputs actionable violation reports
Install as Pre-Commit Hook
Deploy the script as a Git pre-commit hook and calibrate its sensitivity based on real team usage over one week
Done when
A deployed pre-commit hook that has processed at least 10 real commits with documented adjustments to reduce false positives while maintaining catch rate
Capstone: you put together your AI Code Audit Script.
Where this helps
An elective: a single lesson that sits outside rtwo's job certificates and doesn't count toward one.
About this lesson
What you'll be able to do
- Run a working pre-commit hook that flags AI-generated code patterns on your team's actual repository
- Identify 3-5 specific code smells that indicate AI generation vs human authoring
- Have a calibrated judgment about when AI code needs human review vs when it can ship as-is
- Document your team's AI code audit rules in executable form
Who it's for
- Development teams using AI coding tools who want to catch quality issues before they reach production
- Tech leads responsible for code quality who need systematic ways to audit AI-generated contributions
- Anyone who's wondered if there are detectable patterns in AI-written code
What it won't cover
- Setting up Git hooks infrastructure from scratch
- Comprehensive static analysis beyond AI-specific patterns
- Banning AI tools or replacing human code review
- Training custom models to detect AI generation
Skills you'll practise
- Pattern recognition in AI-generated code
- Pre-commit hook development
- Code quality rule specification
- Cross-tool AI output comparison