mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-01-30 12:32:02 +00:00
The hook scripts used absolute imports like `from hookify.core.config_loader` but when installed, the plugin lives in a cache directory with a hash name, not in a directory named `hookify/`. Python couldn't resolve the package. Changed to local imports (`from core.X`) which work because PLUGIN_ROOT is added to sys.path. Also simplified the sys.path setup. Fixes: https://github.com/anthropics/claude-code/issues/14267 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.4 KiB
Python
Executable File
55 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""UserPromptSubmit hook executor for hookify plugin.
|
|
|
|
This script is called by Claude Code when user submits a prompt.
|
|
It reads .claude/hookify.*.local.md files and evaluates rules.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import json
|
|
|
|
# Add plugin root to Python path for imports
|
|
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
|
|
if PLUGIN_ROOT and PLUGIN_ROOT not in sys.path:
|
|
sys.path.insert(0, PLUGIN_ROOT)
|
|
|
|
try:
|
|
from core.config_loader import load_rules
|
|
from core.rule_engine import RuleEngine
|
|
except ImportError as e:
|
|
error_msg = {"systemMessage": f"Hookify import error: {e}"}
|
|
print(json.dumps(error_msg), file=sys.stdout)
|
|
sys.exit(0)
|
|
|
|
|
|
def main():
|
|
"""Main entry point for UserPromptSubmit hook."""
|
|
try:
|
|
# Read input from stdin
|
|
input_data = json.load(sys.stdin)
|
|
|
|
# Load user prompt rules
|
|
rules = load_rules(event='prompt')
|
|
|
|
# Evaluate rules
|
|
engine = RuleEngine()
|
|
result = engine.evaluate_rules(rules, input_data)
|
|
|
|
# Always output JSON (even if empty)
|
|
print(json.dumps(result), file=sys.stdout)
|
|
|
|
except Exception as e:
|
|
error_output = {
|
|
"systemMessage": f"Hookify error: {str(e)}"
|
|
}
|
|
print(json.dumps(error_output), file=sys.stdout)
|
|
|
|
finally:
|
|
# ALWAYS exit 0
|
|
sys.exit(0)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|