Created
January 19, 2026 15:14
-
-
Save nazt/e130ce7cf1548e5efb718e47c1fd0e2b to your computer and use it in GitHub Desktop.
claude-cleanup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # claude-cleanup - Kill orphan Claude Code processes | |
| # Usage: claude-cleanup [--dry-run] | |
| DRY_RUN=false | |
| [[ "$1" == "--dry-run" ]] && DRY_RUN=true | |
| # Count before | |
| BEFORE=$(ps aux | grep -E "claude.*resume" | grep -v grep | wc -l | tr -d ' ') | |
| MEM_BEFORE=$(ps aux | grep -E "claude.*resume" | grep -v grep | awk '{sum+=$6} END {printf "%.0f", sum/1024}') | |
| echo "Orphan resume agents: $BEFORE ($MEM_BEFORE MB)" | |
| if [[ "$BEFORE" -eq 0 ]]; then | |
| echo "✅ No orphans found" | |
| exit 0 | |
| fi | |
| if [[ "$DRY_RUN" == "true" ]]; then | |
| echo "[dry-run] Would kill $BEFORE processes" | |
| exit 0 | |
| fi | |
| # Kill orphans | |
| pkill -f "claude.*resume" | |
| sleep 1 | |
| # Count after | |
| AFTER=$(ps aux | grep -E "claude.*resume" | grep -v grep | wc -l | tr -d ' ') | |
| KILLED=$((BEFORE - AFTER)) | |
| echo "✅ Killed $KILLED orphans, recovered ~${MEM_BEFORE} MB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment