Ask Claude to Write Git Hooks That Enforce Your Team's Standards on Every Commit
Git hooks are the last line of defense before bad code enters your repo, but writing them by hand means dealing with bash quirks, exit codes, and edge cases. Tell Claude what you want to enforce and it writes the hook scripts ready to drop into .git/hooks/ or your hooks manager.
> write a pre-commit hook that runs our linter and formatter on
> staged files only — don't check files that aren't being committed
Claude reads your project to find which linter and formatter you use, then writes a hook that targets only staged files — so it's fast and only blocks commits that actually introduce problems.
#!/bin/sh
# .git/hooks/pre-commit — Claude generates this
STAGED_PHP=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')
if [ -n "$STAGED_PHP" ]; then
vendor/bin/pint --test $STAGED_PHP || {
echo "Fix formatting: vendor/bin/pint"
exit 1
}
fi
You can ask for multiple hooks at once:
> create git hooks for our team:
> - pre-commit: run Pint on staged PHP files, ESLint on staged JS
> - commit-msg: enforce conventional commit format (feat:, fix:, etc.)
> - pre-push: run the test suite before allowing push to main
> also create a setup script that installs these hooks for
> new team members
Claude generates each hook and a setup script. For teams using Husky, lint-staged, or Lefthook, Claude writes the config for your hook manager instead of raw shell scripts:
> we use Husky — configure pre-commit to run lint-staged with
> Pint for PHP and Prettier for JS/CSS
Common hooks Claude can write:
- Pre-commit — lint, format, check for
dd(),console.log,TODOmarkers, or secrets - Commit-msg — enforce conventional commits, max length, issue number references
- Pre-push — run tests, check branch protection, prevent force-push to main
- Post-merge — auto-run
composer installornpm installwhen lock files change
Git hooks enforce standards silently — every developer on the team follows the rules without thinking about it.
via Claude Code
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.