BeCuriouzBeCuriouz

Learn something new every day

🛠️ Tools & Services
🪝

Hooks let you run code every time Claude does something — before or after

💡 Hooks fire shell commands at lifecycle events — PreToolUse hooks can block dangerous actions with hard enforcement, unlike CLAUDE.md soft instructions.

Hooks are shell commands that fire automatically at specific points in Claude Code's lifecycle. Want to auto-format every file after Claude edits it? Block dangerous rm -rf commands before they run? Log every tool usage? Hooks make it happen.

There are three cadences: per-session (start/end), per-turn (before Claude processes your input, after it responds), and per-tool-call (before/after each action Claude takes).

The most powerful are PreToolUse hooks — they run before Claude executes a tool and can block it. You can write a hook that intercepts every Bash command, checks if it contains rm -rf, and returns a deny decision. Unlike CLAUDE.md instructions (which Claude might not follow perfectly), hooks are hard enforcement.

Configure them in your settings JSON under the hooks key. They can be shell commands, HTTP endpoints, MCP tool calls, or even LLM prompts that evaluate whether an action is safe.