claude-code - 💡(How to fix) Fix Add displayContext hook field for human-visible, agent-hidden 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#47862Fetched 2026-04-15 06:40:12
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×2closed ×1commented ×1

Code Example

#!/bin/bash
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
[[ "$COMMAND" == *"test"* || "$COMMAND" == *"spec"* ]] || exit 0

STDOUT=$(echo "$INPUT" | jq -r '.tool_result.stdout // empty')
SUMMARY=$(echo "$STDOUT" | tail -5)

if [ -n "$SUMMARY" ]; then
  jq -n --arg ctx "$SUMMARY" '{"displayContext": $ctx}'
fi
RAW_BUFFERClick to expand / collapse

Problem

Hooks support additionalContext — output injected into the agent's context but hidden from the human in the terminal. There's no inverse: a way for hooks to display output to the human without adding it to the agent's context.

This matters for observability. When the agent runs tests, linters, or builds via Bash, the human loses visibility into results unless they read through tool output. A hook could surface a formatted summary directly in the conversation thread — but today, any hook output that reaches the thread also lands in the agent's context, which is wasteful when the agent already has the full tool result.

Use cases:

  • Test run summaries after test commands
  • Lint/typecheck results after file edits
  • Deploy status after push commands
  • Any "FYI" output where the human benefits from visibility but the agent doesn't need the extra context

Proposed solution

Add a displayContext field symmetric to additionalContext:

FieldTerminal (human)API context (agent)
additionalContextHiddenIncluded
displayContextRenderedExcluded

Example

A PostToolUse hook on Bash that surfaces a test summary to the human:

#!/bin/bash
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
[[ "$COMMAND" == *"test"* || "$COMMAND" == *"spec"* ]] || exit 0

STDOUT=$(echo "$INPUT" | jq -r '.tool_result.stdout // empty')
SUMMARY=$(echo "$STDOUT" | tail -5)

if [ -n "$SUMMARY" ]; then
  jq -n --arg ctx "$SUMMARY" '{"displayContext": $ctx}'
fi

The human sees the summary inline in the conversation. The agent doesn't.

extent analysis

TL;DR

To address the issue of hooks not being able to display output to humans without adding it to the agent's context, introduce a displayContext field that allows hooks to render output in the terminal without including it in the agent's context.

Guidance

  • Introduce a new field displayContext in the hook output to separate output intended for human visibility from that intended for the agent's context.
  • Update the rendering logic to display displayContext in the terminal while excluding it from the agent's context.
  • Modify existing hooks, such as the PostToolUse hook, to utilize displayContext for surfacing summaries or results to humans, as shown in the proposed example.
  • Ensure that the agent's context only includes additionalContext and not displayContext to avoid unnecessary data inclusion.

Example

The provided Bash script example demonstrates how a PostToolUse hook can use displayContext to surface a test summary to the human:

jq -n --arg ctx "$SUMMARY" '{"displayContext": $ctx}'

This example assumes that the SUMMARY variable contains the desired output to be displayed to the human.

Notes

The introduction of displayContext requires updates to both the hook logic and the rendering of output in the terminal. This solution assumes that the underlying infrastructure supports the differentiation between additionalContext and displayContext.

Recommendation

Apply the workaround by introducing the displayContext field and updating hooks to utilize it, as this directly addresses the issue of separating human-visible output from the agent's context.

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 Add displayContext hook field for human-visible, agent-hidden output [1 comments, 2 participants]