Last active
August 16, 2025 14:11
-
-
Save L422Y/94a79d56a3f32304a8d7032d4d5bae25 to your computer and use it in GitHub Desktop.
Script to assist in removing `claude-flow` from claude code... use at your own risk
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| backup() { [ -f "$1" ] && cp "$1" "$1.bak.$(date +%s)" || true; } | |
| has() { command -v "$1" >/dev/null 2>&1; } | |
| # mac/gnu portable in-place sed | |
| sed_in_place() { | |
| f="$1"; expr="$2" | |
| if has gsed; then gsed -i.bak "$expr" "$f" || true | |
| else sed -i.bak "$expr" "$f" || true | |
| fi | |
| rm -f "$f.bak" | |
| } | |
| json_scrub() { | |
| f="$1" | |
| [ -f "$f" ] || return 0 | |
| backup "$f" | |
| if has jq; then | |
| tmp="$f.tmp" | |
| if jq ' | |
| del(.hooks) | |
| | del(.commandHooks) | |
| | del(.agentHooks) | |
| | (if .mcp then .mcp |= ( del(.hooks) | |
| | (if .servers then .servers |= del(."claude-flow") | .servers |= del(."ruvnet/claude-flow") else . end) | |
| ) else . end) | |
| | (if .servers then .servers |= del(."claude-flow") | .servers |= del(."ruvnet/claude-flow") else . end) | |
| | with_entries(select((.value|tostring|test("claude-flow|hooks pre-command")|not))) | |
| ' "$f" > "$tmp" 2>/dev/null; then | |
| mv "$tmp" "$f" | |
| else | |
| rm -f "$tmp" | |
| sed_in_place "$f" '/claude-flow/d; /hooks pre-command/d' | |
| fi | |
| else | |
| sed_in_place "$f" '/claude-flow/d; /hooks pre-command/d' | |
| fi | |
| } | |
| rm_if_exists() { [ -e "$1" ] && rm -rf "$1" || true; } | |
| echo ">>> kill running bits" | |
| pkill -f 'claude-flow' 2>/dev/null || true | |
| pkill -f 'hooks pre-command' 2>/dev/null || true | |
| pkill -f 'ruv' 2>/dev/null || true | |
| echo ">>> scrub claude code configs" | |
| json_scrub "$HOME/.claude.json" || true | |
| json_scrub "$HOME/.claude/settings.json" || true | |
| json_scrub "$HOME/.claude/settings.local.json" || true | |
| json_scrub "$PWD/.claude.json" || true | |
| # find nested .claude/*.json without process substitution | |
| if has find; then | |
| IFS=$'\n' | |
| for f in $(find "$PWD" -maxdepth 5 -type f -path '*/.claude/*.json' 2>/dev/null); do | |
| json_scrub "$f" || true | |
| done | |
| IFS=$' \t\n' | |
| fi | |
| echo ">>> scrub vscode workspace configs" | |
| json_scrub "$PWD/.vscode/settings.json" || true | |
| json_scrub "$PWD/.vscode/tasks.json" || true | |
| json_scrub "$HOME/Library/Application Support/Code/User/settings.json" || true | |
| json_scrub "$HOME/Library/Application Support/Code - Insiders/User/settings.json" || true | |
| echo ">>> scrub package.json scripts" | |
| if [ -f "$PWD/package.json" ]; then | |
| if has jq; then | |
| tmp="$PWD/package.json.tmp" | |
| if jq 'if .scripts | |
| then .scripts |= with_entries(select(.value|tostring|test("claude-flow|hooks pre-command")|not)) | |
| else . end' "$PWD/package.json" > "$tmp" 2>/dev/null; then | |
| mv "$tmp" "$PWD/package.json" | |
| else | |
| rm -f "$tmp" | |
| fi | |
| else | |
| sed_in_place "$PWD/package.json" '/claude-flow/d; /hooks pre-command/d' | |
| fi | |
| fi | |
| echo ">>> remove git and husky hooks that reference it" | |
| for hooksdir in .git/hooks .husky; do | |
| [ -d "$hooksdir" ] || continue | |
| if has rg; then | |
| IFS=$'\n' | |
| for hook in $(rg -Il --no-messages 'claude-flow|hooks pre-command' "$hooksdir" || true); do rm -f "$hook"; done | |
| IFS=$' \t\n' | |
| else | |
| IFS=$'\n' | |
| for hook in $(grep -RIl 'claude-flow\|hooks pre-command' "$hooksdir" 2>/dev/null || true); do rm -f "$hook"; done | |
| IFS=$' \t\n' | |
| fi | |
| done | |
| echo ">>> clear agents and caches" | |
| rm_if_exists "$HOME/.claude/agents" | |
| rm_if_exists "$HOME/.claude/packs" | |
| rm_if_exists "$HOME/.claude-flow" | |
| rm_if_exists "$HOME/.ruv-swarm" | |
| rm_if_exists "$HOME/.cache/claude-flow" | |
| rm_if_exists "$HOME/.config/claude-flow" | |
| echo ">>> clear shell rc hooks" | |
| for rc in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/fish/config.fish" "$HOME/.profile" "$HOME/.bash_profile"; do | |
| [ -f "$rc" ] || continue | |
| sed_in_place "$rc" '/claude-flow/d; /hooks pre-command/d; /npx .*claude-flow@alpha/d' | |
| done | |
| echo ">>> clear node tool caches" | |
| npm cache clean --force >/dev/null 2>&1 || true | |
| rm -rf "$HOME/.npm/_npx" "$HOME/.cache/yarn" "$HOME/.cache/pnpm" 2>/dev/null || true | |
| rm -rf "$HOME/Library/Caches/Yarn" "$HOME/Library/Caches/pnpm" 2>/dev/null || true | |
| echo ">>> validation" | |
| if has claude; then | |
| if claude mcp list 2>/dev/null | grep -qi 'claude-flow'; then | |
| echo "warn: mcp still listed above" | |
| else | |
| echo "ok: no claude-flow mcp listed" | |
| fi | |
| else | |
| echo "note: claude cli not found, skipping mcp check" | |
| fi | |
| echo ">>> scan for leftovers" | |
| # fall back to grep if ripgrep missing | |
| if has rg; then | |
| rg -n --hidden --no-messages -S 'claude-flow|hooks pre-command' "$HOME/.claude" "$PWD/.claude" "$PWD/.vscode" "$PWD" 2>/dev/null \ | |
| || echo "ok: no remaining references" | |
| else | |
| grep -Rin 'claude-flow\|hooks pre-command' "$HOME/.claude" "$PWD/.claude" "$PWD/.vscode" "$PWD" 2>/dev/null \ | |
| || echo "ok: no remaining references" | |
| fi | |
| echo ">>> done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment