claude-code - 💡(How to fix) Fix Foreground Bash/TaskStop don't kill subprocesses; harness tracks ghost shells [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#51778Fetched 2026-04-22 07:53:06
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

In a single 40-minute session, three different harness paths left processes running after they should have been dead, and the UI kept reporting activity for work that had long finished. The result was ~35 minutes of wasted wall time plus orphan processes holding container / DB resources.

Error Message

Expected: TaskStop should propagate the signal to the process group (setpgrp + killpg), or at least warn "process still alive after stop signal".

Root Cause

In a single 40-minute session, three different harness paths left processes running after they should have been dead, and the UI kept reporting activity for work that had long finished. The result was ~35 minutes of wasted wall time plus orphan processes holding container / DB resources.

RAW_BUFFERClick to expand / collapse

Summary

In a single 40-minute session, three different harness paths left processes running after they should have been dead, and the UI kept reporting activity for work that had long finished. The result was ~35 minutes of wasted wall time plus orphan processes holding container / DB resources.

Repros

1. task test -- --filter=X hangs silently for 30+ min with zero feedback

The task wrapper (our project's taskfile) eventually invokes php artisan test which passes --no-output to Pest. With coverage-mode Xdebug enabled, Pest can stall at ~0% CPU while the UI shows a running Bash call producing zero output. No way to tell from the UI whether the call is working, hung, or deadlocked.

Expected: either periodic heartbeat output from the harness, or a timeout warning when a Bash call goes quiet for N minutes.

2. TaskStop removes the task from the harness but leaves the OS process alive

I called TaskStop on a task test:parallel shell. Harness reported "Successfully stopped task". `ps` showed the PHP / pest processes still running 28 minutes later at 0% CPU — they weren't sent SIGTERM/SIGKILL.

Expected: TaskStop should propagate the signal to the process group (setpgrp + killpg), or at least warn "process still alive after stop signal".

3. Rejecting a Bash tool call doesn't kill the subprocess it already started

I hit "reject" on a foreground `docker exec … pest …` call about 10 seconds after it started. Four minutes later the pest invocation was still running inside the container. I had to manually `kill -9` the host-side `sh` wrapper.

Expected: user-side rejection should trigger SIGKILL of the spawned subprocess tree, not just disconnect the harness's read handle.

4. UI "N shell still running" banner is stale

After (1) / (2) / (3) were manually reaped via `kill -9`, the UI kept displaying "1 shell still running" for the remainder of the session. No way to clear it without starting fresh tool work.

Impact

  • ~35 minutes of wasted wall time in one session.
  • Resource leak: orphan PHP / docker processes holding DB connections + container memory.
  • Status indicators can't be trusted — had to shell out to `ps` / `docker exec` repeatedly to know the real state, which defeats the purpose of an agentic harness.

Environment

  • Claude Code CLI
  • Model: Opus 4.7 (1M context)
  • OS: Fedora 43, Linux 6.19.12
  • Tools involved: Bash (foreground), TaskStop, Monitor

Suggested fixes

  • Spawn subprocesses in their own process group; on rejection / TaskStop / session end, `killpg(-PID, SIGKILL)`.
  • Emit a "no output for Nm" notification so silent hangs are visible without polling `ps`.
  • Reconcile the "shells running" counter against real PIDs at each tool call; auto-clear ghosts.

extent analysis

TL;DR

To address the issue of orphaned processes and inaccurate UI status indicators, implement process group management and timeout notifications.

Guidance

  • Use setpgrp to spawn subprocesses in their own process group, allowing for easier termination with killpg when necessary.
  • Implement a timeout mechanism to detect and notify when a subprocess has been silent for an extended period (e.g., "no output for Nm" notification).
  • Reconcile the "shells running" counter against real PIDs at each tool call to prevent stale status indicators.
  • Consider using SIGTERM followed by SIGKILL to ensure subprocesses are properly terminated when stopped or rejected.

Example

# Example of spawning a subprocess in its own process group
(set -m; exec your_command) &

Note: This example uses Bash's set -m option to enable job control, allowing the subprocess to be spawned in its own process group.

Notes

The suggested fixes assume that the issue is related to the lack of proper process group management and timeout handling. However, without more information about the specific implementation and environment, it's difficult to provide a more detailed solution.

Recommendation

Apply the suggested fixes, starting with implementing process group management using setpgrp and killpg, to address the issue of orphaned processes and inaccurate UI status indicators. This should help prevent resource leaks and improve the overall reliability of the system.

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