CLAUDE.md rule vs PreToolUse hook: both held 5 of 5, then the user said 'I authorize it'

A recent experiment tested the effectiveness of two methods for restricting Claude Code's file editing capabilities: CLAUDE.md rules versus PreToolUse hooks. Researchers ran 29 headless sessions to see if the agent would respect a 'never edit protected/' rule. Both methods successfully prevented unauthorized edits during standard tasks. However, when the prompt included a user claim of authority, the CLAUDE.md rule failed, allowing the edit, while the PreToolUse hook continued to block it. The study highlights that CLAUDE.md serves as context for the model, whereas PreToolUse hooks act as enforced configuration. While CLAUDE.md is more cost-effective for general rules, hooks are necessary for strict security enforcement. The experiment also noted that poorly configured hooks can inadvertently block read operations, potentially hindering the agent's ability to report accurately, and that hook exit codes significantly impact whether the model respects the restriction.
This is a summary. Read the full article at the original source:
Dev.toRelated stories
In his recent blog post, Colin Breck addresses the growing trend of using Large Language Models (LLMs) to generate technical content. Breck argues tha…
The creator of the 'Giga Pisar' application, built on Sber's GigaAM speech recognition technology, has summarized the first week following their debut…
This Habr article explores the computer as a fundamental mathematical structure, inviting readers to view computational processes through the lens of…


