Claude Code hooks, explained: block rm, auto-format, get pinged when it stops

A hook is a small script Claude Code runs for you at fixed moments, such as before a tool call or when Claude finishes. Here is every piece in…

Aliteq
Tensor · Local AI & Automation Editor

The short answer

A Claude Code hook is a handler you configure in a settings file that runs automatically when something happens in a session: before a tool call, after one, when Claude stops, and so on. Anthropic's…

Where it goes: a hooks block in .claude/settings.json (shared with the repo), .claude/settings.local.json (yours only) or ~/.claude/settings.json (every project)

Three levels: pick an event, add a matcher to filter it, then define the handler that runs

Exit code 2 blocks: on PreToolUse it stops the tool call and your stderr text goes to Claude as the reason

JSON is finer control: exit 0 and print permissionDecision inside hookSpecificOutput to allow, deny, ask or defer

Security: the docs warn that command hooks can modify, delete or access any file your user account can

Aliteq

Read the full story

Claude Code hooks, explained: block rm, auto-format, get pinged when it stops

Read the full story on Aliteq