Claude Certified Architect – Foundations Practice Question 25: PostToolUse Formatter Hook

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

Claude Code Configuration & Workflowseasy

A team wants every file Claude Code edits to be run through the project's formatter automatically, every time, with no reliance on the model remembering. The current approach, a line in CLAUDE.md saying "always run the formatter after editing", is followed inconsistently. What is the best fix?

Select one answer
Show answer and explanation

Answer:

  • A. Configure a PostToolUse hook with a matcher for the edit and write tools that runs the formatter command on the changed file

Hooks are deterministic: they are shell commands that Claude Code runs at lifecycle events regardless of what the model decides. A PostToolUse hook matched to Edit and Write runs after each successful edit, which is exactly when formatting should happen.

- B is wrong: PreToolUse runs before the edit, so the file has not yet changed and there is nothing new to format. - C is wrong: CLAUDE.md is guidance the model may or may not follow; emphasis does not make it guaranteed. - D is wrong: a format tool still depends on Claude choosing to call it, so it has the same reliability problem.

Reference: Automate workflows with hooks

Practice Test 3 ›

Study guides for Claude Certified Architect, Foundations