Created
April 25, 2026 00:17
-
-
Save hmmhmmhm/79c44da84d9020dea6b35eeb1957a9b1 to your computer and use it in GitHub Desktop.
How to clean remove claude code
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 -u | |
| existing_paths=() | |
| removal_failures=() | |
| detect_platform() { | |
| local kernel | |
| kernel="$(uname -s 2>/dev/null || printf 'unknown')" | |
| case "$kernel" in | |
| Darwin) | |
| printf 'macOS\n' | |
| ;; | |
| Linux) | |
| if [ -r /proc/version ] && grep -qi microsoft /proc/version 2>/dev/null; then | |
| printf 'WSL\n' | |
| else | |
| printf 'Linux\n' | |
| fi | |
| ;; | |
| MINGW*|MSYS*|CYGWIN*) | |
| printf 'Git Bash\n' | |
| ;; | |
| *) | |
| printf '%s\n' "$kernel" | |
| ;; | |
| esac | |
| } | |
| command_path() { | |
| command -v claude 2>/dev/null || true | |
| } | |
| append_if_exists() { | |
| local path="$1" | |
| if [ -e "$path" ] || [ -L "$path" ]; then | |
| existing_paths+=("$path") | |
| fi | |
| } | |
| collect_candidates() { | |
| existing_paths=() | |
| append_if_exists "$HOME/.local/bin/claude" | |
| append_if_exists "$HOME/.local/share/claude" | |
| append_if_exists "$HOME/.claude" | |
| append_if_exists "$HOME/.claude.json" | |
| append_if_exists "$HOME/.claude.json.backup" | |
| append_if_exists "$HOME/.claude-remote-yolo-state.json" | |
| append_if_exists "$HOME/.cache/claude" | |
| append_if_exists "$HOME/.local/state/claude" | |
| append_if_exists "$HOME/Applications/Claude Code URL Handler.app" | |
| if [ "${CLAUDE_CODE_SYSTEM_PATHS:-1}" != "0" ]; then | |
| append_if_exists "/opt/homebrew/bin/claude" | |
| append_if_exists "/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code" | |
| append_if_exists "/usr/local/bin/claude" | |
| append_if_exists "/usr/local/lib/node_modules/@anthropic-ai/claude-code" | |
| fi | |
| } | |
| print_preview() { | |
| local resolved | |
| local i | |
| resolved="$(command_path)" | |
| printf 'Platform: %s\n' "$(detect_platform)" | |
| if [ -n "$resolved" ]; then | |
| printf 'claude command currently resolves to: %s\n' "$resolved" | |
| else | |
| printf 'claude command currently not found in PATH.\n' | |
| fi | |
| printf 'Detected Claude Code paths:\n' | |
| if [ "${#existing_paths[@]}" -eq 0 ]; then | |
| printf ' (none)\n' | |
| return | |
| fi | |
| for ((i = 0; i < ${#existing_paths[@]}; i++)); do | |
| printf ' - %s\n' "${existing_paths[$i]}" | |
| done | |
| } | |
| prompt_user() { | |
| local answer | |
| printf 'Proceed with deletion? [y/N] ' | |
| if ! read -r answer; then | |
| answer="" | |
| fi | |
| case "$answer" in | |
| y|Y) | |
| return 0 | |
| ;; | |
| *) | |
| return 1 | |
| ;; | |
| esac | |
| } | |
| remove_detected_paths() { | |
| local path | |
| local i | |
| removal_failures=() | |
| for ((i = 0; i < ${#existing_paths[@]}; i++)); do | |
| path="${existing_paths[$i]}" | |
| if rm -rf "$path" 2>/dev/null; then | |
| printf 'Removed: %s\n' "$path" | |
| else | |
| printf 'Failed to remove: %s\n' "$path" >&2 | |
| removal_failures+=("$path") | |
| fi | |
| done | |
| } | |
| verify_cleanup() { | |
| local resolved | |
| local i | |
| collect_candidates | |
| resolved="$(command_path)" | |
| if [ -n "$resolved" ]; then | |
| printf 'claude command still resolves to: %s\n' "$resolved" | |
| else | |
| printf 'claude command not found after cleanup.\n' | |
| fi | |
| if [ "${#existing_paths[@]}" -eq 0 ]; then | |
| printf 'No allowed Claude Code paths remain.\n' | |
| else | |
| printf 'Allowed Claude Code paths still present:\n' | |
| for ((i = 0; i < ${#existing_paths[@]}; i++)); do | |
| printf ' - %s\n' "${existing_paths[$i]}" | |
| done | |
| fi | |
| if [ "${#removal_failures[@]}" -gt 0 ]; then | |
| printf 'Some paths could not be removed during cleanup.\n' >&2 | |
| return 1 | |
| fi | |
| if [ -n "$resolved" ] || [ "${#existing_paths[@]}" -gt 0 ]; then | |
| return 1 | |
| fi | |
| return 0 | |
| } | |
| main() { | |
| collect_candidates | |
| print_preview | |
| if [ "${#existing_paths[@]}" -eq 0 ]; then | |
| printf 'No direct-install Claude Code paths were found. Nothing to delete.\n' | |
| exit 0 | |
| fi | |
| if ! prompt_user; then | |
| printf 'Deletion cancelled.\n' | |
| exit 0 | |
| fi | |
| remove_detected_paths | |
| if verify_cleanup; then | |
| exit 0 | |
| fi | |
| exit 1 | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment