A safety net before every commit
git commit and runs your validation suite before the commit executes. If type checking fails or tests break, Claude sees the errors and can fix them before trying again. This is your last line of defense against committing code that does not compile or pass tests.Claude initiates a commit
When Claude runs a Bash command containing <code>git commit</code>, the PreToolUse event fires before the command executes.
Hook detects the commit intent
The command inspects <code>$CLAUDE_TOOL_INPUT</code> for the string "git commit". If found, it triggers the validation step. Other Bash commands pass through unaffected.
Validation runs
Your configured checks execute: type checking with tsc, test suite with jest or vitest, or a custom validation script. Any failures produce output that Claude can read.
Claude responds to the result
If validation passes, the commit proceeds normally. If it fails, Claude sees the errors, fixes the code, and tries the commit again with clean code.