Basic Hook Structure
my-hook.js
Exit Codes
success
Success — continue execution
block
Block the tool call (PreToolUse only)
error
Error — logged but does not block
Hook Input Schema
Common Hook Recipes
Warn About TODO Comments
Block Large File Creation
Auto-Format Python Files with Ruff
Require Test Files Alongside New Source Files
Async Hooks
For hooks that should not block the main flow (e.g., background analysis):Async hooks run in the background. They cannot block tool execution.
Example: Background Build Analysis
build-analysis.js
Customizing Hooks
Disabling a Hook
Remove or comment out the hook entry inhooks.json. If installed as a plugin, override in your ~/.claude/settings.json:
~/.claude/settings.json
Environment Variables
Use environment variables for hook configuration:Cross-Platform Notes
File Path Handling
Related
- Hook Overview — Complete hook system reference
- Common Rules: Hooks — Hook architecture guidelines