The Blocking Mechanism: Ensuring Code Quality#
One of the most powerful features of Claude hooks is the ability to "block" a tool execution result and force the model to correct its mistakes.
How Blocking Works#
When dart analyze finds issues, the after_edit.sh script generates a JSON object that Claude interprets to modify the tool's behavior.
The JSON Response#
jq -n \
--arg output "$CLEAN_OUTPUT" \
--arg tool "$TOOL_NAME" \
--arg file "$FILE_PATH" \
'{
decision: "block",
reason: ("The tool \($tool) was executed, but dart analyze found issues in \($file). Please fix ALL errors, warnings, and info messages:\n\($output)"),
systemMessage: "⚠️ Lint issues found after \($tool)"
}'
Key Components:#
-
decision: "block": This is the crucial instruction. It tells Claude that the tool use should not be considered successful in its current state. -
reason: This text is presented to the model as if the tool itself returned an error. It contains the specific linting errors fromdart analyze, giving the model the exact context it needs to fix the code. -
systemMessage: A short, high-visibility message often shown in the UI to alert the user/system that a hook intervened.
Impact on Workflow#
By blocking the tool, the model is prevented from moving on to the next task until the code is perfectly formatted and free of static analysis issues. This creates a "self-healing" loop where the environment enforces quality standards automatically.