# Check for zombie/orphaned processes during Claude Code sessions
# This script identifies processes that may be consuming memory

Write-Host "[INFO] Checking for zombie processes..."
Write-Host ""

# Check for Python processes
$pythonProcs = Get-Process | Where-Object {$_.ProcessName -like '*python*'}
Write-Host "[PYTHON] Found $($pythonProcs.Count) Python processes"
if ($pythonProcs.Count -gt 0) {
    $pythonProcs | Select-Object ProcessName, Id, @{Name='MemoryMB';Expression={[math]::Round($_.WorkingSet64/1MB,2)}}, StartTime | Format-Table -AutoSize
}

# Check for Node processes
$nodeProcs = Get-Process | Where-Object {$_.ProcessName -like '*node*'}
Write-Host "[NODE] Found $($nodeProcs.Count) Node processes"
if ($nodeProcs.Count -gt 0) {
    $nodeProcs | Select-Object ProcessName, Id, @{Name='MemoryMB';Expression={[math]::Round($_.WorkingSet64/1MB,2)}}, StartTime | Format-Table -AutoSize
}

# Check for agent-related processes (background tasks)
$backgroundProcs = Get-Process | Where-Object {$_.CommandLine -like '*agent*' -or $_.CommandLine -like '*Task*'}
Write-Host "[BACKGROUND] Checking for agent/task processes..."

# Total memory summary
$totalMem = (Get-Process | Measure-Object WorkingSet64 -Sum).Sum
Write-Host ""
Write-Host "[SUMMARY] Total system memory in use: $([math]::Round($totalMem/1GB,2)) GB"
