Recurring failure with Claude Code: it kept building duplicate probe scripts without checking whether the work already existed in the codebase. Pre-build audit rule documented in CLAUDE.md, in memory, with case studies. The model would acknowledge it and skip it on the next answer. Five documented failures over three weeks. The fix wasn't more prose. It was a PreToolUse hook in .claude/settings.jsonl a shell script that runs before every Write/Edit, greps the codebase for existing infrastructure matching the filename topic, and exits 2 to block the write if it finds anything.
Rules you remember can be bypassed. Rules the harness enforces cannot.
Copy-paste snippet for the tweet (the actual config):
// .claude/settings.json
{
"hooks": {
"PreToolUse": [{
"matcher": "Write|Edit",
"hooks": [{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/<your-script>.sh"
}]
}]
}
}
Plus a sentence: "Your script gets the tool input as JSON on stdin. Exit 0 = allow, exit 2 = block