"""Merge (or remove) the AKOS SessionStart hook into ~/.claude/settings.json without disturbing other settings/hooks.""" import json, os, shutil, sys, time p = os.path.expanduser("~/.claude/settings.json") cfg = json.load(open(p)) if os.path.exists(p) else {} hooks = cfg.setdefault("hooks", {}) lst = hooks.setdefault("SessionStart", []) lst[:] = [h for h in lst if not any("akos" in (x.get("command") or "") and "session_start.sh" in (x.get("command") or "") for x in h.get("hooks", []))] if sys.argv[1] == "--add": lst.append({"hooks": [{"type": "command", "command": sys.argv[2], "statusMessage": "AKOS: loading API knowledge context"}]}) if not lst: hooks.pop("SessionStart", None) if not hooks: cfg.pop("hooks", None) if os.path.exists(p): shutil.copy(p, p + f".bak-akos-{time.strftime('%Y%m%d-%H%M%S')}") os.makedirs(os.path.dirname(p), exist_ok=True) json.dump(cfg, open(p, "w"), indent=2) print("settings.json updated (backup kept)" if sys.argv[1] == "--add" else "AKOS hook removed")