Guaranteeing Claude Code never edits files under infra/prod
CCDV-F
Claude Code
Medium
Question 14 of 105
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?
Show answer and explanation
CA PreToolUse hook on Edit and Write that exits with code 2 for those paths
PreToolUse is the only one of these events that fires before the tool runs, and exit code 2 there blocks the call whatever JSON the hook prints, feeding the stderr reason back to Claude. PostToolUse fires after the tool has already run, so exit 2 cannot block it; the stderr reaches Claude only as a warning about a change already made. PermissionRequest does not honour exit 2 at all and expects a deny through its decision object. Exit 2 on Stop prevents Claude from stopping, which leaves the edit in place.
Source: code.claude.com/
Anonymous, no account needed. Your tally stays in this browser.
Practice by topic: Claude Code questions