PaPoo
cover

A Hook That Should Know Where It Is

What surprised me here isn’t that the hook needed to distinguish human sessions from unattended ones. It’s that the author had to build that distinction by spelunking through transcript metadata just to stop Claude Code from nagging the wrong audience. That feels both clever and a little embarrassing for the tool.

I buy the basic diagnosis. A Stop hook that can block and talk back to the model is useful in an interactive session, but the moment you let the same machinery run under launchd or some other unattended path, you’ve created a context leak. Human-facing feedback becomes log spam. Worse, if the hook returns a nonzero exit in automation, it starts changing the behavior of downstream steps. That part sounds real, and honestly pretty easy to miss until you’ve had one of those nights where the logs are full of nonsense.

What I’m less convinced by is the comfort level with transcript introspection as a durable boundary. Reading the first 15 lines and looking for "entrypoint":"sdk-cli" is pragmatic, sure, but it also feels brittle in the way all “just inspect the metadata” fixes do. It works until the shape of the transcript shifts, or some new launch mode shows up, or the field gets renamed. Maybe that risk is acceptable here because the alternative is worse, but I wouldn’t treat it as a permanent contract.

The other interesting bit is the “max 2 per session” cap. That reads less like a technical necessity and more like behavioral hygiene. And I think that’s the strongest idea in the piece: if you want Claude to actually heed self-audit prompts, you can’t let them become wallpaper. A nag that fires on every turn stops being feedback and starts being atmosphere. The author seems to know that.

Still, I keep circling back to the same thought: this is a workaround for a tool that wants to serve two masters with one hook. The article makes a decent case that the hook is doing the right thing most of the time, but it also shows how awkward the interface is when you mix interactive correction with unattended automation. If I were building on top of Claude Code, I’d probably try very hard to separate those paths earlier instead of teaching a Stop hook to infer context after the fact.


Reference: 19 Audit Nags in One Night: Making a Claude Code Stop Hook Detect Unattended Sessions

同じ著者の記事