-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.sh
More file actions
78 lines (66 loc) · 2.26 KB
/
uninstall.sh
File metadata and controls
78 lines (66 loc) · 2.26 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
#!/usr/bin/env bash
set -euo pipefail
# Opus Guard Uninstaller
# Removes agent files, hook, and settings.json matchers installed by Opus Guard.
# Restores settings.json from backup if available.
CLAUDE_DIR="$HOME/.claude"
AGENTS_DIR="$CLAUDE_DIR/agents"
HOOKS_DIR="$CLAUDE_DIR/hooks"
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
BACKUP_FILE="$CLAUDE_DIR/settings.json.opus-guard-backup"
if [ -t 1 ]; then
GREEN='\033[0;32m'; YELLOW='\033[0;33m'; NC='\033[0m'
else
GREEN=''; YELLOW=''; NC=''
fi
info() { echo -e "${GREEN}[+]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
echo ""
echo " Opus Guard Uninstaller"
echo " ======================"
echo ""
# --- Remove agent files ---
AGENTS=("Explore.md" "researcher.md" "general-purpose.md" "coder.md")
for agent in "${AGENTS[@]}"; do
if [ -f "$AGENTS_DIR/$agent" ]; then
rm "$AGENTS_DIR/$agent"
info "Removed agent: $agent"
fi
done
# --- Remove hook file ---
if [ -f "$HOOKS_DIR/agent-model-guard.js" ]; then
rm "$HOOKS_DIR/agent-model-guard.js"
info "Removed hook: agent-model-guard.js"
fi
# --- Remove matchers from settings.json ---
if [ -f "$SETTINGS_FILE" ] && command -v node &>/dev/null; then
node -e "
const fs = require('fs');
const settings = JSON.parse(fs.readFileSync('$SETTINGS_FILE', 'utf8'));
if (settings.hooks?.PreToolUse) {
const before = settings.hooks.PreToolUse.length;
settings.hooks.PreToolUse = settings.hooks.PreToolUse.filter(entry =>
!entry.hooks?.some(h => h.command?.includes('agent-model-guard'))
);
const removed = before - settings.hooks.PreToolUse.length;
if (settings.hooks.PreToolUse.length === 0) delete settings.hooks.PreToolUse;
if (Object.keys(settings.hooks).length === 0) delete settings.hooks;
fs.writeFileSync('$SETTINGS_FILE', JSON.stringify(settings, null, 2) + '\n');
process.stdout.write(String(removed));
} else {
process.stdout.write('0');
}
" 2>/dev/null | while read -r count; do
if [ "$count" != "0" ]; then
info "Removed $count hook matcher(s) from settings.json"
fi
done
fi
# --- Remove backup ---
if [ -f "$BACKUP_FILE" ]; then
rm "$BACKUP_FILE"
info "Removed settings backup"
fi
echo ""
info "Opus Guard uninstalled. Restart Claude Code to apply changes."
echo ""