Question 90
An agent's PreToolUse hook returns malformed JSON and Claude Code proceeds inconsistently. What is the safest repair?
Explanation
Correct Answer
A PreToolUse hook that emits malformed JSON is not reliably communicating the approval or denial decision expected by Claude Code. The team must use the current documented hook response schema, ensure all required types and fields are correct, and test how the configured environment treats missing, invalid or timed-out responses. For high-risk operations, choose a documented blocking or escalation policy rather than assuming silent allow. Log the actual hook error without leaking sensitive input and confirm a forbidden synthetic operation is stopped. This distinguishes process exit status from parseable policy output and makes the security boundary observable.
Incorrect Answers
Removing a failing PreToolUse policy hook and relying solely on a natural-language rule would leave risky execution requests without the intended machine-enforced check. The malformed JSON problem is an output-contract defect, not proof that authorization should be abandoned. Validate hook responses against the documented fields and exit semantics, test both allowed and blocked operations, and define what happens if the hook errors. A prompt reminder can supplement the guard but cannot replace its execution-time decision. The appropriate repair strengthens the hook interface rather than disabling it.
A process can exit normally while returning malformed, incomplete or semantically inconsistent policy data. The host must validate the documented hook response schema and know how failure or absent decisions affect enforcement. Relying on exit status alone can bypass a required PreToolUse permission gate. Confirm both transport success and correctly typed output fields, then apply the configured fail-closed or escalation behavior when the payload violates the contract.
Accepting every malformed hook response as permission to proceed would convert a policy integration bug into an allow-by-default bypass. The model could then perform the very file edit the guard was installed to restrict, while operators see only an apparently harmless formatting failure. Test parsing failures and return a documented denial or escalation decision for protected actions; leave lower-risk behavior consistent with explicit policy. Unknown response shape is not evidence that the underlying request is safe or authorized.



Claude Certified Architect - Foundations (CCA-F) Practice Tests