PRODUCTION SCENARIO
A team's CLAUDE.md says never to edit files under infra/prod/, yet Claude Code still occasionally modifies them. The team wants a guarantee that holds regardless of what the model decides.
Which mechanism provides that guarantee?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: A PreToolUse hook on Edit and Write that exits with code 2 for those paths
Memory files are context rather than enforced configuration, so instructions there can be missed. On a PreToolUse event, exit code 2 blocks the tool call regardless of any JSON output and feeds the stderr reason back to Claude, which makes it a hard enforcement point.
Official Source: https://code.claude.com/docs/en/hooks ↗