Context
The hook currently outputs hookSpecificOutput JSON format:
{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}
This was originally filed as a bug fix for anthropics/claude-code#17550, which reported hookSpecificOutput JSON causing errors on the first message of a new session. However, testing confirms the JSON format works correctly for first messages in current Claude Code versions. The upstream issue is stale and pending autoclose.
Rationale
Switching to plain text is still a worthwhile cleanup:
- Simpler code: Removes JSON construction, string escaping, and the
output_json() helper
- Fewer failure modes: No JSON parsing/escaping edge cases
- Equivalent functionality: Plain text stdout injects
additionalContext the same way
- Defensive: Avoids any future regressions in JSON parsing
Steps
- Refactor
scripts/improve-prompt.py to output plain text instead of JSON
- Update tests to validate plain text output format
- Verify bypass prefixes still work with plain text output
References
Context
The hook currently outputs
hookSpecificOutputJSON format:{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}This was originally filed as a bug fix for anthropics/claude-code#17550, which reported
hookSpecificOutputJSON causing errors on the first message of a new session. However, testing confirms the JSON format works correctly for first messages in current Claude Code versions. The upstream issue is stale and pending autoclose.Rationale
Switching to plain text is still a worthwhile cleanup:
output_json()helperadditionalContextthe same waySteps
scripts/improve-prompt.pyto output plain text instead of JSONReferences