Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .claude/hooks/require-skill-for-path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
"""PreToolUse hook: nudge toward a skill when editing certain paths.

Add (path_regex, message) pairs to RULES to cover new areas as they come up.
"""

import json
import re
import sys


RULES = [
(
re.compile(r"releasenotes/notes/[^/]+\.ya?ml$"),
"Use the `releasenote` skill for this Reno fragment instead of hand-writing it — see docs/releasenotes.rst.",
),
]


def main():
try:
data = json.load(sys.stdin)
except Exception:
return

if data.get("tool_name") not in ("Edit", "Write", "MultiEdit"):
return

path = (data.get("tool_input") or {}).get("file_path", "")
messages = [msg for pattern, msg in RULES if pattern.search(path)]
if not messages:
return

print(
json.dumps(
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"suppressOutput": False,
"additionalContext": "\n".join(messages),
}
}
)
)


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
"deny": []
},
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "python3 .claude/hooks/require-skill-for-path.py"
}
]
}
],
"PostToolUse": [
{
"matcher": "Bash",
Expand Down
Loading