𝗖𝗹𝗮𝘂𝗱𝗲 𝗖𝗼𝗱𝗲 𝗛𝗼𝗼𝗸𝘀: 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗲 𝗬𝗼𝘂𝗿 𝗧𝗼𝗼𝗹 𝗖𝗮𝗹𝗹𝘀
Most Claude Code setups miss a key layer.
You set your agent. You write your docs. The agent does what you say. But some things happen without your control. Files get written without linting. Commits happen without tests.
Hooks fix this. Hooks are shell commands. Claude Code runs them automatically. They run outside the reasoning loop. The agent has no control over them.
Prompts rely on the AI. Hooks do not. They guarantee the work happens.
The four events:
- PreToolUse: Runs before a tool. It stops the tool if needed.
- PostToolUse: Runs after a tool finishes.
- UserPromptSubmit: Runs when you hit enter.
- Stop: Runs when Claude finishes.
Use hooks to:
- Stop dangerous commands like rm -rf.
- Auto-format files.
- Log every command to a file.
- Run tests before git commits.
- Get a ping when you send a prompt.
The strategy:
- CLAUDE.md shapes intent.
- Tool permissions control access.
- Hooks enforce behavior.
Keep hooks fast. Set hooks for Write and Edit tools. Test hooks before deployment.
Start with an audit log. Know what your AI does.