pretooluse
2 questions
- AI
Which hook event should I use? The full list, ranked.
Claude Code exposes 28 hook events across five categories: lifecycle, tool execution, turn control, agent teams, and context management. Exit code 2 blocks the action on blocking events. Non-blocking events show stderr but cannot prevent what already happened.
- AI
What does Claude Code do when a PreToolUse hook denies a tool call mid-task?
A captured `claude --print` session against the demo app, with a PreToolUse hook that denies any Edit or Write to `src/shared/`. The prompt forced a collision: add a `formatForCity` helper to `src/shared/time.ts` AND use it from `src/reporting/service.ts`. Claude read four files, attempted the Edit, hit the block, read the hook script itself to understand the policy, then stopped with three concrete paths forward (workaround, lift the freeze, two-PR split). The article shows what the block looks like in the events stream, what Claude considered and rejected, and why this is the right shape of agent behavior under denial-mode hooks.