Claude Certified Architect – Foundations Practice Question 55: Hook Exit Code Blocking

Claude Certified Architect, Foundations · Test 6 · question 5 of 10

Claude Code Configuration & Workflowsmedium

An engineer writes a Claude Code hook script for Bash commands. It must stop any command that contains "git push --force" and tell Claude why, so Claude can choose a safer alternative. The script is registered correctly and its pattern matching works. Which behavior makes the block actually happen?

Select one answer
Show answer and explanation

Answer:

  • A. Register it as a PreToolUse hook, write the reason to stderr, and exit with code 2

A is correct. Exit code 2 is the blocking error: on an event that can block, PreToolUse stops the tool call, and when no JSON decision is printed the stderr text is used as the blocking message that explains the refusal.

B is wrong because other non-zero codes are non-blocking for most events; the action proceeds and the transcript just shows a hook error notice. C is wrong because exit 0 means success, so the command runs; stdout is not a block signal. D is wrong because PostToolUse runs after the tool has already executed, so exit 2 there can only show stderr to Claude and cannot prevent the push.

Reference: Hooks reference

Practice Test 6 ›

Study guides for Claude Certified Architect, Foundations