[BUG] Background-shell counter under-counts SSH-wrapped Bash invocations (v2.1.144)
Environment
- Claude Code version: 2.1.144
- OS: Linux 6.19.14+kali-amd64 x86-64
- Runtime: Bun
Symptom
Claude Code's built-in background-task counter (the ● Bash(...) ↓ to manage UI affordance) decrements when the inner command's stdout has been delivered to the agent's tool_result, even though the local wrapping zsh (and its child ssh) are still alive.
Result: SSH commands run with run_in_background: true typically do NOT appear in the counter, while symmetric local long-running invocations do.
Empirical evidence
Active session (PID 1493916, batmon-ha cwd) ran:
ssh user@host 'sudo systemctl restart svc; sleep 25; sudo journalctl -u svc --since "30 sec ago" | grep -iE ...'
with run_in_background: true. Live pstree:
claude(1493916)---zsh(1826134)---ssh(1826140)
— wrapping zsh and ssh child both alive. Status-line shell counter showed 0 background shells.
The symmetric case for a local long-running build:
bash /path/to/build.sh --build 2>&1 | tail -3 && bash /path/to/build.sh --install 2>&1 | tail -5
— same run_in_background: true, does show in the counter while live.
Probable cause
The background-task tracker probably decrements its counter when the inner-command stdout has been consumed + delivered as tool_result, not when the local zsh actually exits. SSH commands stream the remote stdout fast (journalctl print is ~instant once the remote sleep completes) so the manage-queue drops them, but the local zsh → ssh pair persists until the remote command's full lifecycle (including any local-side socket teardown) completes. Local builds keep streaming output for minutes so they stay in the manage-queue.
Impact
Agent + user cannot trust the status-line shell counter for SSH-backgrounded work — invisible long-running SSH calls accumulate without a UI indicator. Authoritative live count requires pstree -p <claude-pid> | grep zsh.
Suggested fix
Tie the counter decrement to the wrapping zsh's wait() return (PID-level lifecycle) instead of to the tool_result delivery. SSH commands' tool_result is "complete" only when the local zsh exits, not when the remote stdout has been read.
🤖 Reported with Claude Code
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗