claude-code - 💡(How to fix) Fix [FEATURE] PreToolUse hooks inside sub-agents cannot surface interactive output to the user terminal [1 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#55094Fetched 2026-05-01 05:46:23
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×3subscribed ×1unsubscribed ×1

Fix Action

Fix / Workaround

None that preserves interactive behaviour. The only current workaround is to auto-block (exit 2) unconditionally when tty is unavailable, which removes user choice entirely.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

When a PreToolUse hook fires inside a sub-agent (spawned via the Agent tool), the hook process cannot display output to the user or read user input. The sub-agent's stdio is piped to the parent Claude Code process, not the user's tty. Calling open("/dev/tty") inside the hook fails silently or returns a tty disconnected from the user's session.

This means any hook that need to do the following (as examples), cannot do so from a sub-agent:

  • Print a panel or message the user will actually see
  • Prompt the user for a decision (allow / deny / modify)

The hook is forced to either default to Pass (allow) or auto-block without user input — neither of which is the intended behaviour.

Proposed Solution

Inherit the parent tty file descriptor into sub-agent hook processes. When Claude Code spawns a sub-agent, pass the parent's tty file descriptor through so hooks in the child can write to and read from it. This mirrors how Docker --interactive forward ttys to child processes.

Alternative Solutions

None that preserves interactive behaviour. The only current workaround is to auto-block (exit 2) unconditionally when tty is unavailable, which removes user choice entirely.

Priority

Medium - Would be very helpful

Feature Category

Interactive mode (TUI)

Use Case Example

https://github.com/dbmikeldb/tokenGate

A token analyser, developed to improve user knowledge and token efficency.

Additional Context

No response

extent analysis

TL;DR

Inherit the parent tty file descriptor into sub-agent hook processes to enable interactive behavior.

Guidance

  • Investigate using a library or system call to pass the parent's tty file descriptor to the sub-agent, similar to Docker's --interactive flag.
  • Verify that the sub-agent's stdio is correctly piped to the user's tty by checking the file descriptor numbers and testing interactive input/output.
  • Consider using a wrapper script or function to handle the tty inheritance and simplify the implementation.
  • Review the tokenGate use case example to ensure the proposed solution meets the requirements for interactive token analysis.

Example

No code snippet is provided due to the lack of specific implementation details, but the solution may involve using system calls like dup2 or fcntl to duplicate and pass the tty file descriptor.

Notes

The proposed solution assumes that inheriting the parent tty file descriptor is feasible and compatible with the existing Claude Code architecture. Additional research and testing may be necessary to ensure a smooth implementation.

Recommendation

Apply workaround: Inherit the parent tty file descriptor into sub-agent hook processes, as this approach is likely to preserve interactive behavior and meet the requirements for user input and output.

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] PreToolUse hooks inside sub-agents cannot surface interactive output to the user terminal [1 participants]