19 Audit Nags in One Night: Making a Claude Code Stop Hook Detect Unattended Sessions
My autonomous setup earns its keep precisely because Claude Code starts on its own and finishes on its own. The thing that nearly broke that setup was Claude Code itself. Why This Mechanism Matters The biggest time sink for me over the past six months wasn't code quality or billing costs. It was a structural problem: notifications that wouldn't stop firing at a screen with no human in front of…
The biggest challenge with Claude Code is its autonomous functionality, particularly notifications that persist even when no human is present. This issue was exacerbated by a script called ~/.claude/hooks/self_audit_stop.sh that checks for self-audits after each turn of Claude's output. The script was effective in interactive sessions but failed when Claude's automated pipeline, run through launchd, didn't include a human user.
The script encountered 19 "audit nags" overnight, causing issues in the automated pipeline. The problem stems from the fact that the same Stop hook is used for both interactive sessions and automated runs, causing confusion and degradation of execution quality. To solve this, the script determines whether the session was launched by a human or an automated process, using the entrypoint field.
The audit mechanism is then applied only to human-initiated sessions, capped at two occurrences per session to prevent the nag from becoming a ritual. This approach ensures that the audit remains relevant and effective when needed, while also preventing it from interfering with automated processes.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.