claude-code - 💡(How to fix) Fix [BUG] Background-shell counter under-counts SSH-wrapped Bash invocations (v2.1.144) [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#60554Fetched 2026-05-20 03:55:34
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×5

Code Example

ssh user@host 'sudo systemctl restart svc; sleep 25; sudo journalctl -u svc --since "30 sec ago" | grep -iE ...'

---

claude(1493916)---zsh(1826134)---ssh(1826140)

---

bash /path/to/build.sh --build 2>&1 | tail -3 && bash /path/to/build.sh --install 2>&1 | tail -5
RAW_BUFFERClick to expand / collapse

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

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 [BUG] Background-shell counter under-counts SSH-wrapped Bash invocations (v2.1.144) [1 participants]