Extensions
Hooks
What hooks are, the lifecycle events, and how to configure them in settings.json. Concept and a generic example.
2 min read
Hooks are commands that Claude Code runs automatically at defined points in the lifecycle — before using a tool, after editing a file, when you submit a prompt, when a session starts. The difference from an instruction in CLAUDE.md is the guarantee: CLAUDE.md asks the model for something, and it may forget or ignore it; a hook is your own code that always runs. It's Claude Code's deterministic mechanism.
Events
Each hook attaches to an event. Among the available ones:
- PreToolUse — before Claude runs a tool (can block execution).
- PostToolUse — after a tool runs successfully.
- UserPromptSubmit — when you submit a prompt, before Claude processes it.
- SessionStart / SessionEnd — at the start and end of a session.
- Stop — when Claude finishes responding.
- SubagentStop — when a subagent completes.
- Notification — when Claude Code emits a notification (for example, asking for permission).
- PreCompact — before compacting the context window.
Premium Content
Unlock all 20 sections of the Claude Code Guide with lifetime access.
$57· Lifetime
What's included:
- 19 detailed sections, from setup to workflow
- Lifetime access with updates
- Practical examples and ready-to-use configs
- Bilingual support (PT-BR and EN)