Skip to content

Comments

Fix Stop hook example prompt to prevent JSON parsing failures#31

Open
Haikane wants to merge 1 commit intotrailofbits:mainfrom
Haikane:fix-stop-hook-prompt-v2
Open

Fix Stop hook example prompt to prevent JSON parsing failures#31
Haikane wants to merge 1 commit intotrailofbits:mainfrom
Haikane:fix-stop-hook-prompt-v2

Conversation

@Haikane
Copy link

@Haikane Haikane commented Feb 20, 2026

Summary

  • Adds a JSON-only output instruction to the Stop hook example prompt in the README
  • Adds a timeout field to the example (missing from original)
  • Documents the pitfall so others don't hit it

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:

```json
{"ok": true}
```

or:

The work appears complete. {"ok": true}

Both fail JSON parsing, producing Hooks: error parsing response as JSON in debug logs. The hook silently does nothing.

Fix

Prepend the prompt with:

You are a JSON-only evaluator. You MUST respond with a single JSON object and NOTHING else. No markdown, no code fences, no explanation, no preamble. Just the raw JSON object.

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

  • Copy the example into ~/.claude/settings.json and run a session with --verbose
  • Verify debug logs show Model response: {"ok": true} (clean JSON, no fences)

🤖 Generated with Claude Code

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>
@CLAassistant
Copy link

CLAassistant commented Feb 20, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants