What are hooks in Claude Code?
Categories:
Claude Code Developer Guide
Hooks are shell scripts that run before or after Claude Code performs an action — editing a file, running a Bash command, finishing a tool call. They’re your safety net.
- PreToolUse hooks can block dangerous actions: refuse to
rm -rf /, refuse to push tomainbranch, refuse to write intovendor/, refuse to edit prod credentials. Hook returns non-zero exit, action is cancelled, you stay safe. - PostToolUse hooks auto-run lint / format / tests after every file edit.
phpcs+phpstan+composer validateon every Magento file change — built into the CLI, not bolted on. - Stop hooks run when Claude finishes a session — great for auto-committing or running test suite.
Configure hooks in .claude/settings.json. They’re the difference between “cool AI demo” and “production-grade workflow.”
Was this helpful?