-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.sh
More file actions
307 lines (274 loc) · 9.67 KB
/
Copy pathuninstall.sh
File metadata and controls
307 lines (274 loc) · 9.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/usr/bin/env bash
# ============================================================================
# Claude Code Enhancement Kit -- Uninstaller
# ============================================================================
# Removes files installed by install.sh or install-win.sh.
# Uses the manifest file to know exactly what was installed.
# NEVER removes user's custom CLAUDE.md, settings, or memory.
#
# Usage: bash uninstall.sh (interactive, asks confirmation)
# bash uninstall.sh --yes (skip confirmation)
# bash uninstall.sh --dry-run (show what would be removed)
# ============================================================================
set -euo pipefail
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
CLAUDE_DIR="$HOME/.claude"
BIN_DIR="$HOME/.local/bin"
MANIFEST_FILE="$CLAUDE_DIR/.installed-manifest"
CONFIRM=false
DRY_RUN=false
REMOVED_COUNT=0
KEPT_COUNT=0
MISSING_COUNT=0
# ---------------------------------------------------------------------------
# Colors
# ---------------------------------------------------------------------------
if [[ -t 1 ]]; then
BOLD=$'\033[1m'
DIM=$'\033[2m'
RESET=$'\033[0m'
RED=$'\033[31m'
GREEN=$'\033[32m'
YELLOW=$'\033[33m'
BLUE=$'\033[34m'
MAGENTA=$'\033[35m'
CYAN=$'\033[36m'
else
BOLD="" DIM="" RESET=""
RED="" GREEN="" YELLOW="" BLUE="" MAGENTA="" CYAN=""
fi
info() { echo " ${BLUE}[INFO]${RESET} $*"; }
ok() { echo " ${GREEN}[ OK]${RESET} $*"; }
warn() { echo " ${YELLOW}[WARN]${RESET} $*"; }
fail() { echo " ${RED}[FAIL]${RESET} $*"; }
skip() { echo " ${DIM}[KEEP]${RESET} $*"; }
step() { echo ""; echo " ${MAGENTA}${BOLD}--- $* ---${RESET}"; }
# ---------------------------------------------------------------------------
# Parse arguments
# ---------------------------------------------------------------------------
for arg in "$@"; do
case "$arg" in
--yes|-y) CONFIRM=true ;;
--dry-run) DRY_RUN=true ;;
--help|-h)
echo "Usage: bash uninstall.sh [--yes] [--dry-run] [--help]"
echo ""
echo " --yes Skip confirmation prompt"
echo " --dry-run Show what would be removed without changing anything"
echo " --help Show this help message"
exit 0
;;
*) fail "Unknown argument: $arg"; exit 1 ;;
esac
done
# ---------------------------------------------------------------------------
# Protected files -- NEVER remove these
# ---------------------------------------------------------------------------
PROTECTED_PATTERNS=(
"*/CLAUDE.md"
"*/.claude/settings.json"
"*/.claude/settings.local.json"
"*/.claude/history.jsonl"
"*/.claude/agent-memory/*"
"*/.claude/memory/*"
"*/.claude/contexts/*"
"*/.claude/projects/*"
"*/.claude/cache/*"
"*/.claude/downloads/*"
"*/.claude/hooks/*"
"*/.claude/homunculus/*"
"*/.claude/file-history/*"
"*/.claude/backups/*"
)
is_protected() {
local file="$1"
for pattern in "${PROTECTED_PATTERNS[@]}"; do
# shellcheck disable=SC2254
case "$file" in
$pattern) return 0 ;;
esac
done
return 1
}
# ---------------------------------------------------------------------------
# Collect files to remove
# ---------------------------------------------------------------------------
collect_removable_files() {
local -a files=()
if [[ -f "$MANIFEST_FILE" ]]; then
while IFS= read -r line; do
# Skip comments and empty lines
[[ "$line" =~ ^#.*$ ]] && continue
[[ -z "$line" ]] && continue
files+=("$line")
done < "$MANIFEST_FILE"
fi
# Also scan known installed directories for files from the kit
local known_dirs=(
"$CLAUDE_DIR/library"
"$CLAUDE_DIR/rules"
"$CLAUDE_DIR/skills"
"$CLAUDE_DIR/agents"
"$CLAUDE_DIR/templates"
)
# Shortcut files
for name in claudeskip zero lulu codex; do
[[ -f "$BIN_DIR/$name" ]] && files+=("$BIN_DIR/$name")
[[ -f "$BIN_DIR/${name}.bat" ]] && files+=("$BIN_DIR/${name}.bat")
done
# Deduplicate
printf '%s\n' "${files[@]}" | sort -u
}
# ---------------------------------------------------------------------------
# Preview what will be removed
# ---------------------------------------------------------------------------
preview_removal() {
step "Files that will be removed"
local has_files=false
while IFS= read -r file; do
[[ -z "$file" ]] && continue
has_files=true
if is_protected "$file"; then
skip "$file (protected)"
KEPT_COUNT=$((KEPT_COUNT + 1))
elif [[ -f "$file" ]]; then
info "$file"
else
echo " ${DIM}[GONE]${RESET} $file (already removed)"
MISSING_COUNT=$((MISSING_COUNT + 1))
fi
done < <(collect_removable_files)
if [[ "$has_files" == false ]]; then
warn "No installed files found"
warn "Nothing to uninstall"
exit 0
fi
step "Files that will be preserved"
skip "CLAUDE.md (your custom configuration)"
skip "settings.json (your preferences)"
skip "history.jsonl (session history)"
skip "agent-memory/ (persistent memory)"
skip "projects/ (project-level memory)"
skip "hooks/ (custom hooks)"
skip "cache/, downloads/, backups/"
}
# ---------------------------------------------------------------------------
# Remove files
# ---------------------------------------------------------------------------
remove_files() {
step "Removing installed files"
while IFS= read -r file; do
[[ -z "$file" ]] && continue
if is_protected "$file"; then
skip "$file (protected)"
KEPT_COUNT=$((KEPT_COUNT + 1))
continue
fi
if [[ ! -f "$file" ]]; then
MISSING_COUNT=$((MISSING_COUNT + 1))
continue
fi
if [[ "$DRY_RUN" == true ]]; then
info "Would remove: $file"
else
rm -f "$file"
ok "Removed: $(basename "$file")"
REMOVED_COUNT=$((REMOVED_COUNT + 1))
fi
done < <(collect_removable_files)
# Clean up empty directories left behind
if [[ "$DRY_RUN" != true ]]; then
step "Cleaning empty directories"
for dir in "$CLAUDE_DIR/library" "$CLAUDE_DIR/templates"; do
if [[ -d "$dir" ]]; then
# Remove directory only if empty (recursively)
find "$dir" -type d -empty -delete 2>/dev/null || true
if [[ ! -d "$dir" ]]; then
ok "Removed empty: $dir"
fi
fi
done
fi
# Remove manifest itself
if [[ "$DRY_RUN" != true ]] && [[ -f "$MANIFEST_FILE" ]]; then
rm -f "$MANIFEST_FILE"
ok "Removed manifest"
fi
}
# ---------------------------------------------------------------------------
# Remove MCP servers
# ---------------------------------------------------------------------------
remove_mcp_servers() {
step "Removing MCP servers"
if ! command -v claude &>/dev/null; then
warn "claude CLI not found -- skipping MCP removal"
return
fi
for name in memory sequential-thinking context7 playwright; do
if [[ "$DRY_RUN" == true ]]; then
info "Would remove MCP server: $name"
else
if claude mcp remove "$name" 2>/dev/null; then
ok "Removed MCP: $name"
else
warn "MCP '$name' may not exist or failed to remove"
fi
fi
done
}
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
show_summary() {
echo ""
echo "${CYAN}${BOLD} ============================================================"
echo " Uninstall Summary"
echo " ============================================================${RESET}"
echo ""
if [[ "$DRY_RUN" == true ]]; then
echo " ${YELLOW}DRY RUN -- no files were actually removed${RESET}"
else
echo " ${RED}Removed:${RESET} $REMOVED_COUNT files"
fi
echo " ${GREEN}Kept:${RESET} $KEPT_COUNT files (protected)"
echo " ${DIM}Missing:${RESET} $MISSING_COUNT files (already gone)"
echo ""
echo " Your CLAUDE.md, settings, and memory are untouched."
echo ""
if [[ "$DRY_RUN" != true ]]; then
echo " To reinstall: ${GREEN}bash install.sh${RESET}"
echo ""
fi
}
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
main() {
echo ""
echo "${CYAN}${BOLD}"
echo " ============================================================"
echo " Claude Code Enhancement Kit -- Uninstaller"
echo " ============================================================"
echo "${RESET}"
if [[ "$DRY_RUN" == true ]]; then
echo " ${YELLOW}${BOLD}DRY RUN MODE -- no changes will be made${RESET}"
echo ""
fi
preview_removal
if [[ "$DRY_RUN" != true ]] && [[ "$CONFIRM" != true ]]; then
echo ""
echo -n " ${YELLOW}Proceed with uninstall?${RESET} [y/N] "
read -r response
if [[ "$response" != "y" && "$response" != "Y" ]]; then
echo ""
info "Cancelled. Nothing was removed."
exit 0
fi
fi
remove_files
remove_mcp_servers
show_summary
}
main "$@"