Orphaned child processes (vitest) persist after Bash tool execution and session end
Resolved 💬 3 comments Opened Jan 18, 2026 by binhonglee Closed Jan 18, 2026
When running npm test (which executes vitest run) via the Bash tool, vitest worker processes are left orphaned even after:
- The test command completes successfully
- The Claude Code prompt/turn ends
- The entire Claude Code session ends
Environment:
- OS: macOS (Darwin 24.4.0)
- Claude Code version: 2.1.7
- Node.js version: 25.0.0
- vitest version: 3.2.4
- Feedback ID: 94c85071-badb-4ab0-96ac-f6411b51ba48
Steps to reproduce:
- Run npm test via Claude Code Bash tool in a project using vitest
- Wait for tests to complete and Claude Code to return results
- Check for orphaned processes: ps aux | grep vitest
- Multiple vitest processes remain running
Expected behavior:
All child/grandchild processes spawned by the Bash tool should be terminated when the command completes.
Actual behavior:
4+ vitest processes remain running indefinitely, accumulating across multiple test runs.
Workarounds attempted but not working:
- watch: false in vitest config
Additional context:
This issue does not occur with OpenAI Codex CLI when running the same test command, suggesting the issue is specific to how Claude Code's Bash tool manages process trees and cleanup, not vitest itself.
The Bash tool may not be properly:
- Waiting for grandchild processes (npm → node → vitest workers)
- Sending SIGTERM/SIGKILL to the entire process group
- Using proper process group management (e.g., setsid or kill -TERM -$PID)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗