Regression: background shells killed ~5s after result breaks long-running background commands
A recent change (changelog: "Fixed claude -p hanging forever after its final result when a backgrounded command never exits — background shells are now stopped ~5s after the result once stdin closes") makes it impossible to run legitimate long-running background commands. v2.1.162 works fine, confirmed v2.1.163 as the curprit
Impact: Any background command that outlives a single turn is now force-killed ~5s after the turn's result. Agent launch a 30+ minute job which may output multiple lines to a file, then assistant responds that is waiting for results, and the job is killed seconds later. Background Bash is effectively useless.
Repro:
- Tell the agent to launch a long job in the background.
- Let the turn's result return.
- ~5s later the shell/process is dead, regardless of whether it was actively making progress.
Expected: Background processes should persist across turns until they finish or are explicitly stopped (TaskStop / kill). The original hang fix should not apply to processes that are still running and producing output.
Suggested fixes (any of):
- Only stop the background shell if it has been idle/silent for the grace window; never kill a process that's still emitting output or consuming CPU/GPU.
- Make the grace period configurable (e.g.
--background-grace/ env var) or add an explicit opt-out to keep background tasks alive until TaskStop or manually killed.
This was a usable workflow before the change; please revert or gate it so long-running background commands survive past the result.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗