expose parent TTY path to hooks via environment variable
Title
Feature request: expose parent TTY path to hooks via environment variable
Description
Hook commands (e.g., Stop, Notification) run orphaned with no access to the parent terminal (PPID=1, no controlling TTY). This is likely intentional, but it prevents hooks from sending terminal escape sequences — which unlocks useful integrations.
Use case: Ghostty (and other terminals) support visual bell features — colored border, tab badge, dock bounce — triggered by a BEL character (\a). This is great when running multiple Claude Code sessions in split panes: when one finishes, you can see which pane completed at a glance, without switching focus.
But since hooks can't write to the terminal, printf '\a' does nothing.
Current workaround
I built a 3-part workaround to make this work:
- Shell wrapper — a
cc()function in.zshrcthat injects a unique env var before launching claude:
``zsh``
cc() { CLAUDE_TTY_MARKER=$(uuidgen) command claude "$@"; }
- Stop hook — scans
ps -Ewwto find theclaudeprocess whose env contains the matching marker, reads its TTY, and writes\ato it:
``bash``
for PID in $(ps -eo pid,args | grep '[c]laude$' | awk '{print $1}'); do
if ps -Eww -o command= -p "$PID" | grep -q "CLAUDE_TTY_MARKER=$CLAUDE_TTY_MARKER"; then
TTY=$(ps -o tty= -p "$PID" | tr -d ' ')
printf '\a' > "/dev/$TTY"
fi
done
- Ghostty config —
bell-features = attention,title,border
This works but is fragile, macOS-specific, and requires launching claude through the wrapper instead of directly.
Proposal
Pass the parent terminal's TTY path as an environment variable to hook commands:
CLAUDE_TTY=/dev/ttys002
This would let hooks write escape sequences and visual indicators directly to the terminal. It's a small change that would unlock terminal-native integrations (visual bells, background color changes, OSC notifications, etc.) without compromising the current hook isolation model.
Environment
- Claude Code v2.1.63
- macOS (Darwin 25.3.0)
- Ghostty 1.2.3
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗