Regression: background shells killed ~5s after result breaks long-running background commands

Resolved 💬 1 comment Opened Jun 9, 2026 by infnada Closed Jul 16, 2026

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

https://github.com/anthropics/claude-code/blob/f967b36c1ba1c068372fa7dcac4fae93030103fb/CHANGELOG.md?plain=1#L80

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:

  1. Tell the agent to launch a long job in the background.
  2. Let the turn's result return.
  3. ~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.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗