
What happened
A hands-on guide shows three Claude Code hooks — PostToolUse auto-formats edited files with prettier, ruff, or gofmt, PreToolUse blocks commands like 'rm -rf' with exit code 2, and Stop runs lint when the agent finishes.
Why it matters
Unlike asking the model in a prompt to 'always run prettier after edits', which may or may not be followed, a hook fires every time the specified event occurs, so the rule no longer depends on the AI's judgment.
What to watch
Hooks run shell commands with the user's own permissions, so the guide warns against using an unreviewed repository's .claude/settings.json, and notes that hook specifications can change between versions.
WHO IT HITSDevelopers and platform teams running Claude Code on shared codebases are the ones who can turn formatting, guardrails, and end-of-task checks into enforced rules rather than hopes.
Summaries like this, in your inbox every morning.
The article frames hooks as a shift in how rules are enforced when working with an AI coding agent. Asking in a prompt for the agent to run a formatter after every edit is a request; the guide's point is that it may or may not be honored. A hook instead runs a user-defined command whenever a specified event occurs, so the behavior is no longer left to the model's judgment.
The three hands-on examples map to three different moments. PostToolUse fires right after a tool runs, so editing a file can trigger a formatter such as prettier for JavaScript and TypeScript, ruff for Python, or gofmt for Go, keeping the diff aligned with the formatter. PreToolUse fires just before a tool runs and is the one that can block: the sample script greps the incoming command and rejects destructive or irreversible patterns, exiting with code 2, which sends its stderr message back to Claude so the agent knows why it was stopped and may try another approach. Stop fires when the agent finishes responding and carries no matcher, making it a place for lightweight checks like lint or a type check.
The guide is candid about what comes with this power. Hooks execute shell commands with the user's own permissions, so it warns against using an untrusted repository's .claude/settings.json without reviewing it. It also notes that a hook can hang and stall the session, that a PostToolUse formatter rewriting files can create loops if the hook itself calls the agent's tools, and that hook specifications may change by version. Whether these hooks pay off in practice is likely to hinge on how carefully teams keep them fast, scoped, and reviewed — and on whether the enforcement they buy is worth the shell access they grant.
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 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.
NVIDIA posted $89.02 billion in Data Center revenue for the second quarter of fiscal 2027, reported August 26…

Deepmind Institute researchers proposed "Artificial Symbiotic Intelligence," calling for coordination of netwo…

A developer behind the Japan-equity platform ALPHA FORGE published a Three.js 3D simulation of its pipeline, w…

Moongazer RL, released as foxn2000/moongazer-rl, ran a fully asynchronous RL loop — rollout generation and mod…

Of 475 published Opus 5.5 videos, about 60% are motion graphics; Canvas was the most common rendering route at…

David Soria Parra led the 2026-07-28 Model Context Protocol spec, which deletes the initialize/initialized han…
