-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskill_enable_hook.py
More file actions
43 lines (33 loc) · 1.22 KB
/
skill_enable_hook.py
File metadata and controls
43 lines (33 loc) · 1.22 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
#!/usr/bin/env python3
"""PreToolUse hook on Skill: enable a disabled skill before invocation."""
import json
import sys
from pathlib import Path
SKILLS_DIR = Path.home() / ".claude/skills"
CORE = {"s", "convos", "combo", "tab", "caveman", "librarian", "r1a", "recall"}
def main():
try:
data = json.load(sys.stdin)
except (json.JSONDecodeError, EOFError):
print("{}")
return
tool_input = data.get("tool_input", {})
skill_name = tool_input.get("skill", "")
# Strip fully-qualified prefix (e.g., "ms-office-suite:pdf" → "pdf")
if ":" in skill_name:
skill_name = skill_name.split(":")[-1]
if not skill_name or skill_name in CORE:
print("{}")
return
disabled = SKILLS_DIR / skill_name / "SKILL.md.disabled"
enabled = SKILLS_DIR / skill_name / "SKILL.md"
if disabled.exists() and not enabled.exists():
disabled.rename(enabled)
# Track which skill we enabled so PostToolUse can disable it
tracker = Path("/tmp/claude_skill_enabled.txt")
tracker.write_text(skill_name)
print(json.dumps({"systemMessage": f"Skill '{skill_name}' enabled on-demand."}))
else:
print("{}")
if __name__ == "__main__":
main()