claude-code - 💡(How to fix) Fix Feature request: PreDisplay hook to post-process assistant output [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#51714Fetched 2026-04-22 07:54:48
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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 text field, or raw stdout, matching existing hook conventions).
  • Exit 0 = use returned text; non-zero = pass through original unchanged (fail-safe default).
  • Configurable in settings.json alongside 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

  • Stop hook 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.md nudges: 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.

extent analysis

TL;DR

Implement a PreDisplay hook to transform assistant output before rendering, allowing for customizable formatting, syntax highlighting, and redaction.

Guidance

  • Introduce a new hook event, PreDisplay, that receives the rendered text and returns a modified version, enabling users to enforce display conventions without re-prompting or re-generating text.
  • Configure the hook in settings.json to opt-in for specific projects or users, ensuring a fail-safe default that passes through the original text if the hook errors or returns non-zero.
  • Use the hook to perform tasks such as regex-based syntax highlighting, formatting convention enforcement, and redaction of sensitive patterns.
  • Consider implementing the hook as a JSON payload with a text field or raw stdout, matching existing hook conventions.

Example

{
  "hook": "PreDisplay",
  "input": "assistant's rendered text",
  "output": {
    "text": "modified text"
  }
}

Notes

The proposed PreDisplay hook aims to address the limitations of existing hooks, which fire at tool/lifecycle boundaries and cannot modify the text already shown. This new hook provides a clean, portable, and fail-safe path for transforming assistant output.

Recommendation

Apply a workaround by implementing a custom solution using existing hooks, such as the Stop hook, until a first-class PreDisplay hook is available. This will allow users to enforce display conventions, albeit with potential limitations and increased latency.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Feature request: PreDisplay hook to post-process assistant output [1 comments, 2 participants]