Skip to content

Instantly share code, notes, and snippets.

@nazt
Created January 19, 2026 15:14
Show Gist options
  • Select an option

  • Save nazt/e130ce7cf1548e5efb718e47c1fd0e2b to your computer and use it in GitHub Desktop.

Select an option

Save nazt/e130ce7cf1548e5efb718e47c1fd0e2b to your computer and use it in GitHub Desktop.
claude-cleanup.sh
#!/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