Background tasks: moved-to-background commands stay 'Running' after the process exits; background remote-shell call hangs on open stdin
Status Open
Reported on v2.1.240
Maintainer reply None cached
Activity 0 comments · opened Sep 13, 2026
Summary
Two related problems with background Bash tasks in the desktop app (Code tab), observed in one long session (~536 finished tasks, 14 h):
- **A foreground Bash call that hits the 600 s timeout is "moved to the background" and then stays listed as Running forever, even after the underlying shell has exited.** Three such entries sat in the "Background tasks" panel for 5–7 hours ("Wait for warm re-run results — 7h 40m", "Wait for the four-line acceptance run — 6h 06m", "Wait for the 20:00 acceptance run — 5h 27m").
psshowed no matching process for any of them;TaskStopon each id returned "Successfully stopped" with the original command text. So the task record is stale — the process was gone, the panel and the task list still said running.
- A
run_in_backgroundBash task whose last command was a remote shell call (ssh HOST 'md5sum …', no stdin redirection) hung for 9 h 56 min. The earlier commands in the same chain (ssh HOST 'cat > /tmp/x' < localfile) completed. Background tasks apparently give the child a stdin that never reaches EOF, so a plain ssh (which forwards stdin) blocks. Killing the ssh pid made the task complete with exit code 0 and a normal<task-notification>. If background tasks are meant to have no interactive stdin,</dev/nullby default (or closing stdin) would avoid this; at minimum the panel should show that the process is blocked on stdin rather than "running".
Steps to reproduce
- Bash tool call (foreground, default timeout) such as:
until grep -q DONE /tmp/some-file; do sleep 5; done; cat /tmp/some-file
where another background task writes DONE to the file after ~10 minutes.
- After 600 s the tool returns "Command did not complete within its 600s timeout and was moved to the background (ID: …)".
- When the file gets
DONE, the loop exits (cat prints, process ends). - Open the Background tasks panel: the entry is still "Running" with a growing timer;
/tasksagrees;psshows no such process. It stays that way for hours untilTaskStop.
For the second problem: run_in_background: true with a remote shell command (ssh HOST 'md5sum /tmp/x') as the last command and no </dev/null, where the earlier chain used ssh HOST 'cat > /tmp/x' < file.
Expected
- A moved-to-background task whose process exited should be marked finished (with its output) and produce the usual
<task-notification>. - Background tasks should not hand the child an open stdin (or should document that they do), so ssh/cat-style commands don't hang silently.
Environment
- Claude Code 2.1.240, desktop app (macOS 26.6.2, Apple silicon), Code tab, model claude-opus-5
- Long session with several
run_in_backgroundtasks and background agents; the same stale-Running behaviour happened three times for three different moved-to-background commands.