Hook to post-process assistant output before TUI render

Resolved 💬 2 comments Opened May 5, 2026 by Teo-Asinari Closed Jun 30, 2026

Request

New hook event (e.g. AssistantMessage or PreRender) that receives the assistant's final message text and can return a transformed string before it renders to the user.

Use case

Deterministic enforcement of output-style rules without burning tokens on Stop-hook retry loops. Examples:

  • Hard-wrap prose at N chars (terminal width preference)
  • Strip filler phrases ("Sure!", "I'll", "Let me")
  • Redact patterns (secrets, internal hostnames)
  • Inject footers / signatures
  • Convert markdown flavors

Why existing hooks don't cover it

  • Stop hook fires after the stream is rendered; it can only block + force a retry (costly, non-deterministic, adds latency, burns tokens).
  • UserPromptSubmit runs pre-model; cannot see output.
  • No PostToolUse equivalent exists for the assistant message itself.

Shape suggestion

Input JSON to hook stdin:

{
  "hook_event_name": "AssistantMessage",
  "message": "...assistant text...",
  "transcript_path": "/path/to/transcript.jsonl",
  "session_id": "..."
}

Hook returns JSON on stdout:

{"replacement": "...new text..."}

Or exits 0 with empty stdout to pass through unchanged.

Precedent

Stop hook already gates session end; this would be the symmetric mutation point one layer earlier (between model completion and TUI render).

Motivation

Personal CLAUDE.md / output-style instructions drift over long conversations regardless of how forcefully phrased. Instruction-only enforcement is unreliable. A Stop-hook retry loop works but costs tokens and adds latency on every turn. A pure-text post-processor is cheap, deterministic, and side-effect-free — ideal for formatting rules that don't require model judgment (line wrapping, regex strip, redaction).

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗