CLAUDE.md is instruction the model can deprioritise under pressure. A PreToolUse hook is code that runs regardless. When an exam question says "must never", it is asking for the second. Build the same rule both ways and try to break each.
What to build
- Write a CLAUDE.md instruction: never edit files under infra/.
- Try to get the model to edit one anyway, across a long enough session to add context pressure.
- Now implement the same rule as a PreToolUse hook that inspects the tool input.
- Exit 2 from the hook to block, and write a clear reason to stderr.
- Confirm the model receives the stderr text and adapts its next step.
- Test exit code 0 and a non-zero, non-2 code and record how each behaves.
Done when
- The hook blocks the write every time, including when the model is instructed to ignore it.
- The stderr message is specific enough for the model to choose a different action.
- You can state what exit codes 0, 2 and other mean for hook handling.
- You can say which mechanism you would cite for a compliance requirement, and why.
If you want to go further
- Add a PostToolUse hook that runs a formatter, and note why that one cannot block.
The trap this exercise teaches
Before you start
The theory behind this build is covered in Hooks: events, exit codes and decisions. If any step below is unfamiliar, read that first — the exercise assumes it. Primary source: Claude Code Docs — Hooks.
Check yourself against the exam
This exercise sits in Domain 2, which is 20% of the CCAR‑F exam. Once you have built it, run a domain drill in the study app and see whether the questions read differently.