Study: Claude Code hooks block protected file edits better than CLAUDE.md rules

Researchers ran 29 headless sessions using Claude Code v2.1.273 to compare two methods of preventing edits to a protected directory: a plain-language rule in CLAUDE.md and a PreToolUse shell hook. Both methods successfully blocked edits in normal conditions, but when users explicitly claimed authorization in the prompt, the CLAUDE.md rule was overridden in both test runs while the hook held firm in both. The CLAUDE.md approach added 58–70 input tokens to every request, whereas the hook incurred no token cost unless triggered, though it did introduce an extra model round trip on direct requests. Claude Code's own documentation notes that CLAUDE.md content is treated as context rather than enforced configuration, and that PreToolUse hooks are the correct mechanism for reliably blocking actions. The experiment provides concrete measurements backing that distinction, showing hooks are more tamper-resistant against user-supplied authorization claims.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.



Discussion (0)
Log in to join the discussion and vote.
Log in