AINews wire, Yesterday
Claude Code hooks can enforce project rules and check edits automatically
Reported by XDA Developers

A developer writing for XDA Developers says Claude Code hooks stopped the AI coding tool from repeating the same mistakes. The author had corrected the same errors many times. Project instruction files helped, but the author still had to check whether the model followed them.
Hooks are scripts or commands that run automatically before or after certain actions, or when Claude finishes a task. The author calls them one of the most underrated features of the tool. Here they are used to catch errors, enforce project rules and make Claude check its own work without a reminder each time.
The article separates several kinds of hook. A PreToolUse hook runs before a tool action and can block it, for example an edit to a protected file. A PostToolUse hook runs after a tool completes and can run formatting, linting or other checks. Stop and TaskCompleted hooks can test whether conditions are met before Claude finishes. If a check fails, the hook can return feedback or block the step.
The author gives a practical example. A small script checks the file path before each edit. If the path matches a protected file such as .env, the script exits with code 2 and returns an explanation, and Claude Code blocks the edit. The scripts are kept in the project's .claude/hooks/ directory and registered in .claude/settings.json. Expensive checks, such as a full test suite, are better run when the task is complete. A TaskCompleted hook can stop the task from being marked finished if the tests fail.
Users do not need to write the scripts by hand. The article says a user can describe the checks they want and have the tool write the hook scripts and settings. The /hooks command shows what is configured, and a deliberately failing condition can confirm that the setup works.
Hooks can also cover other tasks. The article describes a Notification hook that sends a desktop alert when Claude needs permission or an answer. It also describes a SessionStart hook that runs after context compaction to reload recent commits, open tasks or project notes. Another hook could send a webhook to n8n when a task completes, or write a local activity log.
The author also mentions a personal mod that tracks usage limits, along with other customisations such as status lines and shortcuts. The piece is an experience-based opinion by one user. It does not say which version of Claude Code it covers, and it does not compare hooks with other tools.
Enjoying this? Get the AI brief
Every Thursday: AI that matters for your home.
✓ Free · seven editions · one click to leave
Original reporting by the sources above. Summary by smart-home.space.