AIToday
Large Language ModelsAI Coding AssistantsZenn AI/MLPublished: Nov 23, 2026, 04:00 JST

Claude Code Hooks: PostToolUse, PreToolUse and Stop recipes

Send on LINE
Claude Code Hooks: PostToolUse, PreToolUse and Stop recipes

3 Key Points

  1. What happened

    A Zenn walkthrough lays out three ready-to-copy Hooks — PostToolUse runs a formatter after every Edit or Write, PreToolUse blocks dangerous commands, and Stop runs tests — configured in .claude/settings.json.

  2. Why it matters

    Hooks are a mechanism, not an instruction, so they fire every time the matcher matches; formatting and blocking no longer depend on the model reading context correctly.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

Context & Analysis

The piece draws its main distinction between Hooks and CLAUDE.md. CLAUDE.md is read as context, so a formatting or safety instruction may be missed depending on the situation. A hook, by contrast, runs whenever its matcher matches, which is why the author routes formatting and blocking there and leaves judgment-heavy working policy to CLAUDE.md.

Scope is set by where the JSON lives. ~/.claude/settings.json applies to all projects on one machine, .claude/settings.json is per project and can be committed so a team shares the same rules, and .claude/settings.local.json is per project but personal and gitignored. Cloud sessions do not read the local file, so anything meant for cloud or team use belongs on the project side. Hooks defined in settings files also fire inside subagents.

The recipes come with limits. A PostToolUse failure cannot undo the tool call that already ran. Blocking too broadly in PreToolUse stops ordinary work, so the author starts narrow. Stop hooks have a runtime cap, so heavy processing may be cut off. The advice is to add hooks one at a time, keep team rules in committed project settings, and review with the /hooks command.

FAQ
Where do I put the hook settings so my whole team gets them?
Put them in the project's .claude/settings.json, which can be committed to the repository and shared.
Can hooks be used in cloud sessions?
Local ~/.claude/settings.json is not read in cloud sessions, so hooks meant for cloud use should go in the project settings.
What should I keep out of the Stop hook?
Heavy full test suites, which cause waiting; keep light checks in the hook and push heavier suites to CI.
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleAnthropic IPO filing flags AI that refuses stop orders, games tests