Background Bash tasks leave orphaned child processes on kill
Description
When a background Bash task (started with run_in_background) is stopped via TaskStop, only the parent shell process is terminated. Child processes spawned by the command (e.g., via concurrently, npm run dev, etc.) continue running as orphans.
Steps to Reproduce
- Start a dev server as a background task:
```
Bash: cd /path/to/project && npm run dev
(run_in_background: true)
npm run dev
Where uses concurrently` to spawn multiple child processes (e.g., tsx watch + vite)
- Stop the task via
TaskStopwith the task ID
- Check for orphaned processes:
````
netstat -ano | grep -E ':3001 |:5174 ' | grep LISTENING
Expected Behavior
All child processes (grandchildren of the shell) should be terminated when the background task is stopped.
Actual Behavior
Only the parent shell is killed. Child processes (tsx, vite, node, etc.) remain running and hold onto their ports. Users must manually find and kill them via taskkill /F /PID <pid>.
Environment
- OS: Windows Server 2025 (Git Bash shell)
- Claude Code version: Latest (as of Feb 2026)
- Shell: bash
Notes
- This is particularly problematic with tools like
concurrently,npm-run-all, or any command that spawns multiple child processes - On Windows, process groups / job objects may be needed to ensure all descendants are terminated
- On Unix, sending SIGTERM to the process group (
kill -TERM -<pgid>) would handle this
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗