Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

In a small Claude Code experiment, a CLAUDE.md rule and a PreToolUse hook each blocked all five ordinary attempts to edit a protected file. But when the prompt claimed the user authorized the edit, the rule gave way in both tested runs, while the hook blocked both. The result illustrates the key difference: CLAUDE.md guides model behavior; a hook can check a tool call before it runs. It does not establish that either approach will behave the same way in every project.

What happened in the experiment?

The authors of the Rulestack article report running a small experiment in a throwaway project with Claude Code v2.1.273 on September 16, 2026. Across its ordinary-task trials, the CLAUDE.md rule blocked five of five protected-file edit attempts, and the PreToolUse hook also blocked five of five. With neither control in place, all three reported runs edited the protected file.

The more revealing result came from two prompts that claimed the user was authorizing the edit. The CLAUDE.md rule gave way in both runs; the hook blocked both calls. The authors report 29 headless sessions in total across multiple conditions. These are counts from that setup, not a broad reliability estimate or a guarantee about other versions, prompts, repositories, or hook implementations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why did the authorization claim change the result?

CLAUDE.md steers the model

A CLAUDE.md file provides project instructions that the model uses as context. A rule such as “do not edit this protected file” can be effective during ordinary work, as the five blocked attempts in this test show. But the instruction is not itself a technical barrier around the file. A conflicting prompt can influence the model to act contrary to it, as happened in both authorization-claim runs.

The authors report that their rule added 58 to 70 input tokens per request in their setup. Treat that as their measured cost for that particular rule and configuration, not a typical or fixed cost for other projects.

PreToolUse checks a proposed call

The experiment’s hook checked tool input for a protected path and refused calls that matched. That puts the check at the tool-call boundary: rather than relying only on the model to remember an instruction, the hook evaluates a proposed action before execution. In the tested authorization-claim runs, the hook continued to block the matching calls.

The authors report that a direct hook request added a model round trip in their setup. That is a different operational cost from adding instruction text, and the result should not be assumed to describe every hook design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should you choose between the two?

Need Better fit Why
A preference or workflow convention CLAUDE.md It gives the model project-specific guidance without adding a separate enforcement layer.
A tool call should be blocked when it matches a protected-file rule, even if a prompt urges the model to proceed A carefully scoped PreToolUse hook or another enforcement mechanism A hook can inspect the proposed call before the tool executes; the tested hook blocked both authorization-claim calls.
Protection against every possible way of changing a file Neither option alone is established by this experiment The test covered a particular hook and path-checking approach, not every write route or a repository-wide security boundary.

Choose based on the consequence of a mistaken edit. If the rule is advisory, clear project guidance may be sufficient. If a matching tool call must be refused, place an explicit check at the tool boundary and consider whether an additional control outside model-authored instructions is appropriate.

What can a hook actually protect?

A hook enforces only what its logic recognizes, where it is configured, and while that configuration remains in force. The reported hook used string/path checks. A simple matcher can miss indirect ways of writing to a file or match unrelated calls, depending on its design. The experiment does not establish that its matcher covered every route to modifying the protected file.

  • Define the protected paths precisely and account for path representations your tools may use.
  • Check which tool calls can write or move content, rather than assuming one edit operation is the only route.
  • Review both false negatives, where a write is not blocked, and false positives, where an unrelated call is refused.
  • Consider who can edit or disable the hook configuration. A hook is not an unchangeable barrier against a user or process with authority over its setup.

The returned hooks reference mirror describes PreToolUse as a before-tool event that can approve, block, or modify a call. Because that is a documentation mirror rather than an official source, check the current Claude Code documentation for the supported syntax and exact behavior before implementing a hook. No implementation code is included here because the available evidence does not establish current official syntax.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the counts do—and do not—show

The ordinary runs show that both controls worked in the authors’ tested scenario; the no-control runs show that the protected file was edited in all three reported attempts without either one. The authorization-claim runs distinguish the mechanisms in that same setup: the model-guidance rule yielded, while the hook refused the calls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Because the experiment was small, used a throwaway project, and tested a particular version and path-matching hook, its counts cannot predict how often either mechanism will stop edits in a different environment. Use them as a concrete illustration of where guidance and tool-boundary checks operate, not as a universal security assessment.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.