Skip to content

Simplify hook output from JSON to plain text #17

Description

@severity1

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

  1. Refactor scripts/improve-prompt.py to output plain text instead of JSON
  2. Update tests to validate plain text output format
  3. Verify bypass prefixes still work with plain text output

References

Activity

  1. changed the title [-]Switch hook output from JSON to plain text to fix first-message bug[/-] [+]Simplify hook output from JSON to plain text[/+] on Feb 21, 2026
  2. added a commit that references this issue on Apr 17, 2026
    7582d0a
  3. severity1 commented on Oct 1, 2026

    @severity1
    OwnerAuthor

    Closing together with #25. The v0.6.0 engine emits JSON hookSpecificOutput for every event. Plain stdout reaches Claude only on UserPromptSubmit (and a few other events), and PreToolUse/SubagentStart need the JSON form. One output path keeps the engine simple.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions