Windows: Bash tool child processes (python -u -c) are not cleaned up, causing process leak

Resolved 💬 3 comments Opened Feb 28, 2026 by masahiroono36 Closed Mar 3, 2026

Description

On Windows (Git Bash / MSYS2), the Bash tool spawns child Python processes (python -u -c "import sys;exec(eval(sys.stdin.readline()))") that are not cleaned up after the tool call completes. Over time, these accumulate and cause severe performance degradation.

Environment

  • Claude Code version: 2.1.62
  • OS: Windows 11 Home 10.0.26200
  • Shell: Git Bash (bash)
  • Python: 3.14 (via Windows Store)

Steps to reproduce

  1. Start Claude Code on Windows
  2. Use the Bash tool repeatedly (or run an autonomous agent that makes many Bash calls)
  3. Observe that python.exe processes accumulate in Task Manager

Observed behavior

After extended use (autonomous coder/reviewer agents running for hours):

  • 87 orphaned python.exe processes found, each running python -u -c "import sys;exec(eval(sys.stdin.readline()))"
  • 4 stale pytest parent processes (spawned via Bash tool) running for up to 25 hours, each holding 16 child processes
  • 4 stale claude.exe processes from a session 3 days ago that never exited
  • PC overheating due to accumulated CPU/IO load
  • All operations (including regular conversation) became ~10x slower

Process tree example:

claude.exe (PID 18512, created 2026-02-25, ZOMBIE)
├── claude.exe (PID 22484, child)
├── claude.exe (PID 21824, child)
└── claude.exe (PID 17884, child)

python.exe -m pytest tests/ -v (PID 80160, running 1486 min)
├── python.exe -u -c "import sys;exec(eval(sys.stdin.readline()))" x16

Expected behavior

Child processes spawned by the Bash tool should be terminated when:

  • The tool call completes
  • The Claude Code session ends
  • The parent process exits

Workaround

Manually kill stale processes:

# Kill pytest processes running > 60 minutes
Get-WmiObject Win32_Process -Filter "Name='python.exe'" | Where-Object {
    $_.CommandLine -like "*pytest*" -and
    ((Get-Date) - $_.ConvertToDateTime($_.CreationDate)).TotalMinutes -gt 60
} | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }

Additional context

This issue is particularly impactful for autonomous agent workflows (e.g., CI/CD automation) where Claude Code runs unattended for extended periods making many Bash tool calls. The process leak compounds over time and eventually degrades the entire system.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗