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):

  1. **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"). ps showed no matching process for any of them; TaskStop on 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.
  1. A run_in_background Bash 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/null by 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

  1. 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.

  1. After 600 s the tool returns "Command did not complete within its 600s timeout and was moved to the background (ID: …)".
  2. When the file gets DONE, the loop exits (cat prints, process ends).
  3. Open the Background tasks panel: the entry is still "Running" with a growing timer; /tasks agrees; ps shows no such process. It stays that way for hours until TaskStop.

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_background tasks and background agents; the same stale-Running behaviour happened three times for three different moved-to-background commands.

View original on GitHub ↗