From b5316cdf404b726247c28150a94d954c0c2501e2 Mon Sep 17 00:00:00 2001 From: AnnatarHe Date: Thu, 6 Aug 2026 02:00:01 +0800 Subject: [PATCH] fix(hooks): detach fish hook from the tty The fish hook ran `shelltime gc` and both `shelltime track` calls with the terminal still attached as stdin, and redirected stdout only. fish 4.1+ probes the terminal with OSC 11 / CPR / DA1 (the `query-term` feature) at startup and on prompt redraw; the terminal answers by writing into the tty input queue. A hook child holding that queue can leave those replies unconsumed, after which they are read as keystrokes and appear as literal escape text at the prompt. Redirect stdin from /dev/null so the hook can never sit on terminal input, and fold stderr into /dev/null to match the bash and zsh hooks, which already use `&> /dev/null`. Co-Authored-By: Claude Opus 5 (1M context) --- model/hooks/fish.fish | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/model/hooks/fish.fish b/model/hooks/fish.fish index da25227..6088cb3 100644 --- a/model/hooks/fish.fish +++ b/model/hooks/fish.fish @@ -4,7 +4,9 @@ if not command -v shelltime > /dev/null echo "Warning: shelltime CLI not found. Please install it to enable time tracking." else - shelltime gc + # Detached from the tty: this runs while fish is still probing the terminal + # (OSC 11 / CPR / DA1) at startup, and must not sit on the input queue. + shelltime gc < /dev/null end # Create a timestamp for the session when the shell starts @@ -19,7 +21,7 @@ function fish_preexec --on-event fish_preexec return end - shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=pre --ppid=$FISH_PPID > /dev/null + shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=pre --ppid=$FISH_PPID < /dev/null > /dev/null 2>&1 end # Define the postexec function @@ -29,5 +31,5 @@ function fish_postexec --on-event fish_postexec return end # This event is triggered before each prompt, which is after each command - shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT --ppid=$FISH_PPID > /dev/null + shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT --ppid=$FISH_PPID < /dev/null > /dev/null 2>&1 end