Repository navigation
Conversation
A shell drawing its prompt hands the terminal for a few tens of milliseconds to a subshell or command-not-found handler run from PROMPT_COMMAND. quit.sh sampled the foreground process group once, so a sample in that window read the shell as running a command and ended the run with the session half quit. idle now polls for up to 2 seconds and reports busy only when the shell keeps the terminal away the whole time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Xu7qEsW42tJsJTDUBXwJK
A shell running a loop typed at its prompt takes the terminal back for an instant between the loop's commands, so accepting any one idle sample in 2 seconds read such a shell as idle and left a Ctrl-D in its input. A prompt keeps the terminal once its hooks finish, so 3 samples in a row, 0.1 seconds apart, tell the two apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Xu7qEsW42tJsJTDUBXwJK
A loop of fast external commands typed at the prompt gives the terminal back to the shell often enough that 3 samples 0.1 seconds apart could all land on it. Sampling every 0.01 seconds and asking for 20 in a row needs the shell to hold the terminal on end, which a loop handing it to each command never does. The comment also names the loop of builtins that still reads as idle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Xu7qEsW42tJsJTDUBXwJK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
quit.sh, run byC-q X, could stop with the session half quit andquit: pane %N runs a command in bashon the status line, although that shell sat at its prompt. It judged a shell busy from a single sample of the terminal's foreground process group, and drawing a prompt hands that group to another process for a few tens of milliseconds. A sample taken right after nvim or Claude Code exited could land in that window and end the run, in 1 of 6 runs of the reproduction under Verification.Key changes
while :; do :; done) keeps the terminal and still reads as idle, as it did with the single sampleNotes
In shells started from the
.functionsat this PR's base,prompts()exportsPROMPT_COMMAND. A tmux shell therefore inherits the entries Ghostty's shell integration added to it (shell-integration/bash/ghostty.bashin Ghostty.app builda7e8e4d15, lines 255-276), without the functions they call. Two of those entries take the terminal at each prompt:(exit "$__ghostty_status"), the fallback that runs when__ghostty_restore_statusis undefined, is a subshell-bash, a forked copy of the shell in a process group other than the shell's__ghostty_hookis not found, so bash runscommand_not_found_handle"in a separate execution environment" (bash(1), COMMAND EXECUTION)declare -f command_not_found_handleshows the handler mise's activation defines, which callsmise hook-not-foundSampling
ps -o tpgid=of a pane's shell after atruebuiltin showed the foreground group away from the shell for these windows over 5 prompts:The exported
PROMPT_COMMANDalso doublesprompt_aws;prompt_gc, which belongs to the shell config and is left for a separate change, sincequit.shhas to tolerate prompt-time processes either way.Verification
Each reproduction run below used a private tmux server loading this repository's
tmux.conf, a session laid out asidelays it out (nvim with nvim-tree on the left,claude --ideon the right), an attached client, andquit.shstarted throughrun-shell -bas the key binding starts it.bashpane withquit: pane %N runs a command in bashtabs-storesession includedbash -c 'sleep 30; echo SURVIVED'is still reported asquit: pane %28 runs a command in bash, and the trace shows nosend-keysto itidle(), called 10 times per case on a shell in a private tmux session, returned:while :; do /bin/date >/dev/null; done,while :; do /bin/sleep 0.01; done,while :; do /bin/sleep 0.02; done, andfor i in $(seq 100000); do /bin/sleep 0.02; done/bin/sleep 0.05was sent, while the prompt was being drawnidein Ghostty,C-q X, theny, closed every pane: a trace ofquit.shshows nvim's:qa, Claude Code's Ctrl-D twice, and one Ctrl-D to each pane's shell within 3 seconds, and no pane was left🤖 Generated with Claude Code
https://claude.ai/code/session_018Xu7qEsW42tJsJTDUBXwJK