One Claude Code feature I was underusing: hooks
一位开发者发现他们低估了 Claude Code 的 hooks 功能。他们过去常在 CLAUDE.md 中设置规则,例如“编辑后运行格式化程序”或“不要触碰此文件”,并信任 Claude 遵循这些规则。然而,hooks 可以自动化这些任务,例如在 Claude 编辑文件后自动格式化、阻止对受保护文件的更改,或在执行特定命令前运行检查。关键的区别在于,CLAUDE.md 适用于 Claude 需要理解的事项,而 hooks 更适合那些每次都必须发生的确定性操作,让工具来强制执行规则,而不是依赖 Claude 记住它们。
- 发布
- 09/07 15:43 UTC+0
- 收录
- 09/07 19:00 UTC+0
- 来源类型
- 开发者社区
- 档位
- 社区
- 信源状态
- 正常
档位是按信源手工设定的编辑判断,不是逐条打分。
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.