How to Use Hooks in Claude Code
Set up Claude Code hooks to run custom scripts before or after tool calls. Automate linting, testing, and validation.
Step-by-step
How to Use Hooks in Claude Code
Understand hook types
Hooks run shell commands at specific points: 'PreToolUse' (before a tool runs), 'PostToolUse' (after a tool runs), 'Notification' (when Claude sends a notification), and 'Stop' (when Claude finishes a turn).
Add hooks to your settings
Add hook configurations to `.claude/settings.json`. Each hook specifies a matcher (which tool to hook into) and a command to run.
Create a pre-commit hook example
Hook into 'PostToolUse' with matcher 'Write' to run your linter after every file write: `{"hooks": {"PostToolUse": [{"matcher": "Write", "command": "eslint --fix $FILE_PATH"}]}}`
Test your hooks
Make a change that triggers your hook and verify it runs correctly. Hook output is shown in the Claude Code interface.
Tips
Pro tips
- *
Use hooks for automated linting, formatting, and test running after edits
- *
Hook commands can block Claude's action — use 'PreToolUse' hooks as guardrails
- *
Keep hook commands fast (under 5 seconds) to avoid slowing down the workflow
Related guides