| name | commit-hygiene |
| description | Atomic commits, PR size limits, commit thresholds, stacked PRs |
| when-to-use | When committing code, creating PRs, or when change set is growing large |
| user-invocable | false |
| effort | low |
Commit Hygiene Skill
Purpose: Keep commits atomic, PRs reviewable, and git history clean. Advise when it's time to commit before changes become too large.
Core Philosophy
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ATOMIC COMMITS โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ One logical change per commit. โ
โ Each commit should be self-contained and deployable. โ
โ If you need "and" to describe it, split it. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SMALL PRS WIN โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ < 400 lines changed = reviewed in < 1 hour โ
โ > 1000 lines = likely rubber-stamped or abandoned โ
โ Smaller PRs = faster reviews, fewer bugs, easier reverts โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ COMMIT EARLY, COMMIT OFTEN โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Working code? Commit it. โ
โ Test passing? Commit it. โ
โ Don't wait for "done" - commit at every stable point. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Commit Size Thresholds
Warning Thresholds (Time to Commit!)
| Metric | Yellow Zone | Red Zone | Action |
|---|
| Files changed | 5-10 files | > 10 files | Commit NOW |
| Lines added | 150-300 lines | > 300 lines | Commit NOW |
| Lines deleted | 100-200 lines | > 200 lines | Commit NOW |
| Total changes | 250-400 lines | > 400 lines | Commit NOW |
| Time since last commit | 30-60 min | > 60 min | Consider committing |
Ideal Commit Size
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ IDEAL COMMIT โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Files: 1-5 โ
โ Lines: 50-200 total changes โ
โ Scope: Single logical unit of work โ
โ Message: Describes ONE thing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Check Current State (Run Frequently)
Quick Status Check
git status --short
git diff --stat
git diff --cached --stat
git diff --shortstat
Detailed Change Analysis
git diff --stat HEAD
git diff --numstat HEAD | awk '{add+=$1; del+=$2} END {print "+"add" -"del" total:"add+del}'
git status --porcelain | wc -l
Pre-Commit Check Script
#!/bin/bash
MAX_FILES=10
MAX_LINES=400
WARN_FILES=5
WARN_LINES=200
FILES=$(git status --porcelain | wc -l | tr -d ' ')
STATS=$(git diff --shortstat HEAD 2>/dev/null)
INSERTIONS=$(echo "$STATS" | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+' || echo 0)
DELETIONS=$(echo "$STATS" | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+' || echo 0)
TOTAL=$((INSERTIONS + DELETIONS))
echo "๐ Current changes: $FILES files, +$INSERTIONS -$DELETIONS ($TOTAL total lines)"
if [ "$FILES" -gt "$MAX_FILES" ] || [ "$TOTAL" -gt "$MAX_LINES" ]; then
echo "๐ด RED ZONE: Commit immediately! Changes are too large."
echo " Consider splitting into multiple commits."
exit 1
elif [ "$FILES" -gt "$WARN_FILES" ] || [ "$TOTAL" -gt "$WARN_LINES" ];
0
0
When to Commit
Commit Triggers (Any One = Commit)
| Trigger | Example |
|---|
| Test passes | Just got a test green โ commit |
| Feature complete | Finished a function โ commit |
| Refactor done | Renamed variable across files โ commit |
| Bug fixed | Fixed the issue โ commit |
| Before switching context | About to work on something else โ commit |
| Clean compile | Code compiles/lints clean โ commit |
| Threshold hit | > 5 files or > 200 lines โ commit |
Commit Immediately If
- โ
Tests are passing after being red
- โ
You're about to make a "big change"
- โ
You've been coding for 30+ minutes
- โ
You're about to try something risky
- โ
The current state is "working"
Don't Wait For
- โ "Perfect" code
- โ All features done
- โ Full test coverage
- โ Code review from yourself
- โ Documentation complete
Atomic Commit Patterns
Good Atomic Commits
โ
"Add email validation to signup form"
- 3 files: validator.ts, signup.tsx, signup.test.ts
- 120 lines changed
- Single purpose: email validation
โ
"Fix null pointer in user lookup"
- 2 files: userService.ts, userService.test.ts
- 25 lines changed
- Single purpose: fix one bug
โ
"Refactor: Extract PaymentProcessor class"
- 4 files: payment.ts โ paymentProcessor.ts + types
- 180 lines changed
- Single purpose: refactoring
Bad Commits (Too Large)
โ "Add authentication, fix bugs, update styles"
- 25 files changed
- 800 lines changed
- Multiple purposes mixed
โ "WIP"
- Unknown scope
- No clear purpose
- Hard to review/revert
โ "Updates"
- 15 files changed
- Mix of features, fixes, refactors
- Impossible to review properly
Splitting Large Changes
Strategy 1: By Layer
Instead of one commit with:
- API endpoint + database migration + frontend + tests
Split into:
1. "Add users table migration"
2. "Add User model and repository"
3. "Add GET /users endpoint"
4. "Add UserList component"
5. "Add integration tests for user flow"
Strategy 2: By Feature Slice
Instead of one commit with:
- All CRUD operations for users
Split into:
1. "Add create user functionality"
2. "Add read user functionality"
3. "Add update user functionality"
4. "Add delete user functionality"
Strategy 3: Refactor First
Instead of:
- Feature + refactoring mixed
Split into:
1. "Refactor: Extract validation helpers" (no behavior change)
2. "Add email validation using new helpers" (new feature)
Strategy 4: By Risk Level
Instead of:
- Safe changes + risky changes together
Split into:
1. "Update dependencies" (safe, isolated)
2. "Migrate to new API version" (risky, separate)
PR Size Guidelines
Optimal PR Size
| Metric | Optimal | Acceptable | Too Large |
|---|
| Files | 1-10 | 10-20 | > 20 |
| Lines changed | 50-200 | 200-400 | > 400 |
| Commits | 1-5 | 5-10 | > 10 |
| Review time | < 30 min | 30-60 min | > 60 min |
PR Size vs Defect Rate
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ RESEARCH FINDINGS (Google, Microsoft studies) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ PRs < 200 lines: 15% defect rate โ
โ PRs 200-400 lines: 23% defect rate โ
โ PRs > 400 lines: 40%+ defect rate โ
โ โ
โ Review quality drops sharply after 200-400 lines. โ
โ Large PRs get "LGTM" rubber stamps, not real reviews. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
When PR is Too Large
git diff main --stat
git diff main --shortstat
Commit Message Format
Structure
<type>: <description> (50 chars max)
[optional body - wrap at 72 chars]
[optional footer]
Types
| Type | Use For |
|---|
feat | New feature |
fix | Bug fix |
refactor | Code change that neither fixes nor adds |
test | Adding/updating tests |
docs | Documentation only |
style | Formatting, no code change |
chore | Build, config, dependencies |
Examples
feat: Add email validation to signup form
fix: Prevent null pointer in user lookup
refactor: Extract PaymentProcessor class
test: Add integration tests for checkout flow
chore: Update dependencies to latest versions
Git Workflow Integration
Pre-Commit Hook for Size Check
#!/bin/bash
MAX_LINES=400
MAX_FILES=15
FILES=$(git diff --cached --name-only | wc -l | tr -d ' ')
STATS=$(git diff --cached --shortstat)
INSERTIONS=$(echo "$STATS" | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+' || echo 0)
DELETIONS=$(echo "$STATS" | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+' || echo 0)
TOTAL=$((INSERTIONS + DELETIONS))
if [ "$TOTAL" -gt "$MAX_LINES" ]; then
echo "โ Commit too large: $TOTAL lines (max: $MAX_LINES)"
echo " Consider splitting into smaller commits."
echo " Use 'git add -p' for partial staging."
exit 1
fi
if [ "$FILES" -gt "$MAX_FILES" ]; then
echo "โ Too many files: $FILES (max: $MAX_FILES)"
echo " Consider splitting into smaller commits."
exit 1
fi
echo "โ
Commit size OK: $FILES files, lines"
Partial Staging (Split Large Changes)
git add -p
git add path/to/specific/file.ts
git add -N file.ts
git diff
git add file.ts
Unstage If Too Large
git reset HEAD
git reset HEAD path/to/file.ts
git add -p
Claude Integration
Periodic Check During Development
Claude should run this check after every significant change:
git diff --shortstat HEAD
Thresholds for Claude to advise committing:
| Condition | Claude Action |
|---|
| > 5 files changed | Suggest: "Consider committing current changes" |
| > 200 lines changed | Suggest: "Changes are getting large, commit recommended" |
| > 10 files OR > 400 lines | Warn: "โ ๏ธ Commit now before changes become unmanageable" |
| Test just passed | Suggest: "Good checkpoint - commit these passing tests" |
| Refactoring complete | Suggest: "Refactoring done - commit before adding features" |
Claude Commit Reminder Messages
๐ Status: 7 files changed, +180 -45 (225 total)
๐ก Approaching commit threshold. Consider committing current work.
---
๐ Status: 12 files changed, +320 -80 (400 total)
โ ๏ธ Changes are large! Commit now to keep PRs reviewable.
Suggested commit: "feat: Add user authentication flow"
---
๐ Status: 3 files changed, +85 -10 (95 total)
โ
Tests passing. Good time to commit!
Suggested commit: "fix: Validate email format on signup"
Stacked PRs (For Large Features)
When a feature is genuinely large, use stacked PRs:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ STACKED PR PATTERN โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โโโ PR #1: Database schema (200 lines) โ Review first โ
โ โโโ PR #2: API endpoints (250 lines) โ Review second โ
โ โโโ PR #3: Frontend (300 lines) โ Review third โ
โ โ
โ Each PR is reviewable independently. โ
โ Merge in order: #1 โ #2 โ #3 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Creating Stacked PRs
git checkout -b feature/auth-schema
git commit -m "feat: Add users table schema"
git push -u origin feature/auth-schema
gh pr create --base main --title "feat: Add users table schema"
git checkout -b feature/auth-api
git commit -m "feat: Add authentication API endpoints"
git push -u origin feature/auth-api
gh pr create --base feature/auth-schema --title "feat: Add auth API endpoints"
Checklist
Before Every Commit
Before Creating PR
Red Flags (Stop and Split)
- โ Commit message needs "and"
- โ > 10 files in one commit
- โ > 400 lines in one commit
- โ Mix of features, fixes, and refactors
- โ "I'll clean this up later"
Quick Reference
Thresholds
Files: โค 5 = ๐ข | 6-10 = ๐ก | > 10 = ๐ด
Lines: โค 200 = ๐ข | 201-400 = ๐ก | > 400 = ๐ด
Time: โค 30min = ๐ข | 30-60min = ๐ก | > 60min = ๐ด
Commands
git diff --shortstat HEAD
git diff --stat HEAD
git add -p
git diff main --shortstat
Commit Now If
- โ
Tests just passed
- โ
> 200 lines changed
- โ
> 5 files changed
- โ
About to switch tasks
- โ
Current state is "working"