⚙️ Automation 📖 Official

Git Hooks Configuration

Set up Git hooks for automated code quality checks and workflow enforcement

★★★ Advanced 25 min January 13, 2025
📋

Scenario

Git hooks automate quality checks before commits and pushes. Cowork can generate customized hooks for linting, testing, commit message validation, and more.

💬

Prompt

I want to set up Git hooks for my JavaScript project at ~/Projects/myapp/. Please create:

1. pre-commit hook:
   - Run ESLint on staged files
   - Run Prettier formatting check
   - Prevent commits with console.log

2. commit-msg hook:
   - Enforce conventional commit format
   - Require ticket reference (PROJ-XXX)

3. pre-push hook:
   - Run full test suite
   - Check for TODO/FIXME comments
   - Prevent push to main without PR

Save hooks to .git/hooks/ and make them executable

Expected Result

Claude will generate complete Git hooks scripts: - pre-commit hook for code linting and formatting - commit-msg hook for validating commit message format - pre-push hook for running tests and preventing direct push to main

💡

Tips

  • Use husky or lefthook for easier hook management
  • Keep hooks fast to avoid developers skipping them
  • Use --no-verify to bypass hooks in emergencies