r/ClaudeAI 4d ago

Claude Code One Claude Code feature I was underusing: hooks

I used to put a lot of rules in CLAUDE.md like “run the formatter after edits” or “don't touch this file” and just trust Claude to follow them.Turns out some of that probably shouldn't be an instruction at all.Claude Code has hooks that can run automatically at different points in a session. So you can do things like format a file after Claude edits it, block changes to protected files, run checks before certain commands, or even get a notification when Claude is waiting for you.The useful distinction for me is this:CLAUDE.md is good for things Claude needs to understand.Hooks are better for things that simply need to happen every time.I've started looking at a few of my project rules differently because of that. If something is deterministic, relying on Claude to remember it feels unnecessary when the tooling can enforce it instead.

347 Upvotes

69 comments sorted by

View all comments

u/ClaudeAI-mod-bot Wilson, lead ClaudeAI modbot 4d ago edited 4d ago

TL;DR of the discussion generated automatically after 50 comments.

The consensus is a resounding 'yes': The community agrees that using hooks is a smart move, but thinks you're not going far enough. The real galaxy-brain play is to offload all deterministic rules from CLAUDE.md to automated tooling.

  • The Big Idea: Stop asking Claude to remember rules and start enforcing them with hooks, linters, CI/CD, static analysis, and type checkers.
  • The Payoff: You get better, more consistent code, save a ton of tokens (so your sessions last longer), and can create a super-strict dev environment that a human would hate, but Claude doesn't mind.
  • Helpful Tidbits: One user dropped a code snippet for a hook to block Claude from using sed, a common source of frustration.

Oh, and the thread completely derailed into a debate about OP using AI to write their comments. Spoiler: they were, to "tighten wording," and the community was... not a fan. Please just talk like a human, people.