-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskill_disable_hook.py
More file actions
41 lines (31 loc) · 1002 Bytes
/
skill_disable_hook.py
File metadata and controls
41 lines (31 loc) · 1002 Bytes
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
#!/usr/bin/env python3
"""PostToolUse hook on Skill: disable skill after invocation (return to .disabled)."""
import json
import sys
from pathlib import Path
SKILLS_DIR = Path.home() / ".claude/skills"
TRACKER = Path("/tmp/claude_skill_enabled.txt")
def main():
try:
data = json.load(sys.stdin)
except (json.JSONDecodeError, EOFError):
print("{}")
return
# Check if we enabled a skill in PreToolUse
if not TRACKER.exists():
print("{}")
return
skill_name = TRACKER.read_text().strip()
TRACKER.unlink(missing_ok=True)
if not skill_name:
print("{}")
return
enabled = SKILLS_DIR / skill_name / "SKILL.md"
disabled = SKILLS_DIR / skill_name / "SKILL.md.disabled"
if enabled.exists() and not disabled.exists():
enabled.rename(disabled)
print(json.dumps({"systemMessage": f"Skill '{skill_name}' disabled after use."}))
else:
print("{}")
if __name__ == "__main__":
main()