AI summary by TwinMind

The dangers of precommit hooks

Theo - t3․gg

18m 16s

Pre-commit Hooks Overview

  • Pre-commit hooks run before git commit executes
  • Common uses: code formatting, unit tests, commit message validation
  • Author threatens to quit if blocked from committing due to strict hooks
  • Video is remake of pre-mustache content with expanded explanation

Core Problem with Pre-commit Hooks Instead of CI

  • Using pre-commit hooks without CI is "incompetent" and "fireable offense"
  • Local hooks can be bypassed with --no-verify flag
  • Different developers may have different tool versions (prettier, linters)
  • Creates inconsistent enforcement across team members
  • Results in broken code reaching main branch

Real-world Failure Examples

  • Jay Larkey example: 200 unformatted files became 100 after cleanup, then grew again
  • Scenario: npm install → pull changes → modify file → commit → push fails CI
    • Cause: pulled changes included new prettier version
    • Solution requires npm install between steps 3-5
  • Developer environments vary: some disable hooks, others have outdated tools

Acceptable Use Case for Pre-commit Hooks

  • Scanning for leaked authentication credentials/secrets
  • Compared to "metal detector at McDonald's" - not ideal but sometimes necessary
  • Only justified when problem has occurred multiple times
  • Still requires CI enforcement as backup

Why CI is Essential

  • CI is the only guarantee rules are enforced before merge
  • Provides safety net when local hooks fail/bypassed
  • Enables proper code review process
  • Allows detection of developer environment issues

Editor Setup vs Automated Hooks

  • Format-on-save in editors preferred over pre-commit hooks
  • Failed CI checks reveal developer setup issues
  • Opportunity for mentoring and environment improvement
  • Poll results: vast majority prefer format-on-save in editor
  • Author credits CI failures for discovering better editor setup

Performance Impact

  • James Landrum example: 8+ minute pre-push hooks for build/test/security
  • Prevents context switching and parallel work
  • Blocks ability to start new branches while waiting
  • Universally considered unacceptable even by hook proponents

Guard Rails vs Safety Nets Philosophy

  • Guard rails: prevent mistakes (unit tests, linting)
  • Safety nets: catch you when mistakes happen (rollback capabilities)
  • Safety nets more important than guard rails
  • Emmy quote: "Insisting on guard rails over safety nets is sign of pathologically unaddressed skill issue"
  • Example safety net: easy deployment rollback (Vercel one-click)

Impact on Team Quality

  • Good engineers bypass hooks with --no-verify
  • Quality developers quit rather than deal with restrictive hooks
  • Hooks hide valuable information about team skill gaps
  • Prevents important conversations about developer tooling
  • Author aliases husky to /dev/null to avoid running hooks

Final Recommendations

  • Always run checks in CI regardless of local hooks
  • Use CI failures as learning opportunities
  • Focus on proper editor setup over automated hooks
  • Build safety nets before adding guard rails
  • Pre-commit hooks "instead of" CI is dangerous and irresponsible

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome