-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.py
More file actions
83 lines (64 loc) · 2.18 KB
/
Copy pathuninstall.py
File metadata and controls
83 lines (64 loc) · 2.18 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
#!/usr/bin/env python3
from __future__ import annotations
import json
from pathlib import Path
CLAUDE_DIR = Path.home() / ".claude"
SETTINGS_PATH = CLAUDE_DIR / "settings.json"
def load_settings() -> dict:
if not SETTINGS_PATH.exists():
return {}
try:
return json.loads(SETTINGS_PATH.read_text(encoding="utf-8"))
except Exception:
return {}
def write_settings(settings: dict) -> None:
SETTINGS_PATH.parent.mkdir(parents=True, exist_ok=True)
SETTINGS_PATH.write_text(json.dumps(settings, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
def remove_userprompt_guard(settings: dict) -> dict:
hooks = settings.get("hooks")
if not isinstance(hooks, dict):
return settings
entries = hooks.get("UserPromptSubmit")
if not isinstance(entries, list):
return settings
new_entries = []
for entry in entries:
hook_list = entry.get("hooks", [])
if not isinstance(hook_list, list):
new_entries.append(entry)
continue
filtered = []
for hook in hook_list:
command = str(hook.get("command", ""))
normalized = command.replace('"', "").replace("'", "")
if hook.get("type") == "command" and "claude_chat_audit.py" in normalized and normalized.strip().endswith("hook-user"):
continue
filtered.append(hook)
if filtered:
updated = dict(entry)
updated["hooks"] = filtered
new_entries.append(updated)
if new_entries:
hooks["UserPromptSubmit"] = new_entries
else:
hooks.pop("UserPromptSubmit", None)
if not hooks:
settings["hooks"] = {}
return settings
def remove_files() -> None:
for path in [
CLAUDE_DIR / "hooks" / "claude_chat_audit.py",
CLAUDE_DIR / "commands" / "audit-chat.md",
]:
try:
path.unlink()
except FileNotFoundError:
pass
def main() -> int:
settings = remove_userprompt_guard(load_settings())
write_settings(settings)
remove_files()
print("Uninstalled Claude UserPrompt Guard.")
return 0
if __name__ == "__main__":
raise SystemExit(main())