SPB Git

spb/akos

Public
1010 B · 19 lines python
1"""Merge (or remove) the AKOS SessionStart hook into ~/.claude/settings.json without disturbing other settings/hooks."""2import json, os, shutil, sys, time3p = os.path.expanduser("~/.claude/settings.json")4cfg = json.load(open(p)) if os.path.exists(p) else {}5hooks = cfg.setdefault("hooks", {})6lst = hooks.setdefault("SessionStart", [])7lst[:] = [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", []))]8if sys.argv[1] == "--add":9    lst.append({"hooks": [{"type": "command", "command": sys.argv[2], "statusMessage": "AKOS: loading API knowledge context"}]})10if not lst:11    hooks.pop("SessionStart", None)12if not hooks:13    cfg.pop("hooks", None)14if os.path.exists(p):15    shutil.copy(p, p + f".bak-akos-{time.strftime('%Y%m%d-%H%M%S')}")16os.makedirs(os.path.dirname(p), exist_ok=True)17json.dump(cfg, open(p, "w"), indent=2)18print("settings.json updated (backup kept)" if sys.argv[1] == "--add" else "AKOS hook removed")19
Files · c744bcc51af6f1462b2f0d25ff87b7354eea4551
Menu

Theme