Fix Stop hook example prompt to prevent JSON parsing failures#31
Open
Haikane wants to merge 1 commit intotrailofbits:mainfrom
Open
Fix Stop hook example prompt to prevent JSON parsing failures#31Haikane wants to merge 1 commit intotrailofbits:mainfrom
Haikane wants to merge 1 commit intotrailofbits:mainfrom
Conversation
The anti-rationalization Stop hook example uses a prompt hook evaluated by Haiku. Without an explicit formatting constraint, Haiku wraps the JSON response in markdown code fences or adds explanatory text, which fails JSON parsing and silently breaks the hook. Fix the example prompt to prepend a JSON-only output instruction and add a timeout. Document the pitfall so others don't hit it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
timeoutfield to the example (missing from original)Problem
The anti-rationalization Stop hook example asks Haiku to respond with
{"ok": true}or{"ok": false, "reason": "..."}. Without an explicit formatting constraint, Haiku responds with:or:
Both fail JSON parsing, producing
Hooks: error parsing response as JSONin debug logs. The hook silently does nothing.Fix
Prepend the prompt with:
This is a README-only change. The Stop hook is intentionally not in
settings.json(it's an opt-in pattern per the "patterns to adapt, not drop-in configs" guidance).Test plan
~/.claude/settings.jsonand run a session with--verboseModel response: {"ok": true}(clean JSON, no fences)🤖 Generated with Claude Code