Feature request: PreDisplay hook to post-process assistant output
Summary
Add a hook event that fires between "assistant finishes generating text" and "text renders to the user," receiving the rendered output and able to return a modified version. Effectively a PreDisplay / OutputTransform hook.
Motivation
Formatting and coloring in chat output are mechanical concerns — ideal candidates for automation rather than things the model has to remember on every turn. Users already invest effort in CLAUDE.md to nudge the model toward consistent formatting, but the model will inevitably drift. A post-output transform layer would let users mechanically enforce display conventions without re-prompting, re-generating, or paying for a full round-trip through a Stop hook.
Concrete example from a real workflow: task UIDs in my project are hex tokens like 0x00, 0x01. A two-line regex-to-ANSI transform in a hook could colorize every occurrence — consistently, for free, forever. Today there is no way to do this.
Current hook landscape (as of filing)
Existing hooks fire at tool/lifecycle boundaries:
Stop— after a turn ends; can block stopping or inject context for the next turn, but cannot modify the text already shown.PostToolUse/PostToolUseFailure— after tool execution; see tool output, not assistant text.
None of these sit between text generation and display.
Proposed shape
A new hook event, tentatively PreDisplay (or AssistantOutput), with:
- Input: the assistant's rendered text for the current turn (stdin or JSON payload).
- Output: modified text on stdout (JSON with a
textfield, or raw stdout, matching existing hook conventions). - Exit 0 = use returned text; non-zero = pass through original unchanged (fail-safe default).
- Configurable in
settings.jsonalongside existing hooks.
Use cases
- Regex-based syntax highlighting for domain-specific tokens (task IDs, ticket refs, file paths).
- Enforcement of formatting conventions (strip/normalize emoji, rewrap long lines, swap color names for locale-appropriate ANSI).
- Redaction of known-sensitive patterns before display.
- Accessibility transforms (e.g., insert visual separators for screen-reader-friendly output).
Why this over alternatives
Stophook that blocks and forces regeneration: expensive (full re-gen), high latency, and doesn't guarantee the regeneration will comply.- Terminal-level regex recolor: only some emulators support it (iTerm2 triggers); not portable to Linux terminals / tmux / Steam Deck, etc.
- pty wrapper interposing on stdout: fragile against TUI redraws, cursor codes, resize events.
CLAUDE.mdnudges: rely on model memory; drift is inevitable on mechanical rules.
A first-class hook is the clean, portable, fail-safe path.
Scope and safety
- Opt-in, per-project or user-level, same as existing hooks.
- Fail-safe by default: if the hook errors or returns non-zero, original text renders unchanged.
- No impact on tool use or model behavior — purely a display-layer transform.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗