hooks-management
Create and Manage Claude Code Hooks
Managing Claude Code hooks requires understanding event-driven automation patterns. This skill provides guided workflows and comprehensive documentation for creating, updating, configuring, and troubleshooting hooks for any event type.
تنزيل ZIP المهارة
رفع في Claude
اذهب إلى Settings → Capabilities → Skills → Upload skill
فعّل وابدأ الاستخدام
اختبرها
استخدام "hooks-management". Create a new hook that validates JSON input on the PreToolUse event
النتيجة المتوقعة:
- Hook created at: .claude/hooks/validate-json.py
- Configuration to add to .claude/settings.local.json:
- {
- "hooks": {
- "PreToolUse": [
- {
- "matcher": "*",
- "hooks": [
- { "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate-json.py" }
- ]
- }
- ]
- }
- }
- Test command: echo '{"tool_name": "Write", "tool_input": {}}' | python .claude/hooks/validate-json.py
استخدام "hooks-management". Why is my hook not executing on the UserPromptSubmit event?
النتيجة المتوقعة:
- Checking hook configuration...
- 1. Verify the hook is registered in .claude/settings.local.json
- 2. Ensure the event name matches exactly: "UserPromptSubmit"
- 3. Test with echo: echo '{"prompt": "/test"}' | python .claude/hooks/your-hook.py
- 4. Check that the script has execute permissions
- 5. Verify exit code is 0 for successful execution
التدقيق الأمني
آمنStatic scanner flagged patterns in documentation markdown files. After manual review, all findings are FALSE POSITIVES. The skill contains only documentation, task workflows, and reference materials for legitimate Claude Code hooks. No actual malicious code or exploit patterns exist.
عوامل الخطر
⚙️ الأوامر الخارجية (3)
📁 الوصول إلى نظام الملفات (2)
🔑 متغيرات البيئة (1)
درجة الجودة
ماذا يمكنك بناءه
Build Custom Event Handlers
Create hooks that respond to specific Claude Code events like PreToolUse, PostToolUse, Stop, or UserPromptSubmit. Automate validation, logging, or enforcement of project policies.
Implement Security and Validation Hooks
Create hooks that validate commands before execution, block dangerous operations, log security events, and enforce project security policies automatically.
Enforce Development Workflows
Build hooks that enforce TDD workflows, track phase completion, validate plans before implementation, and ensure consistent development practices across teams.
جرّب هذه الموجهات
Create a new Claude Code hook that runs on the Stop event. The hook should validate that all tasks in the plan are complete before allowing Claude to stop.
Update the session_start.py hook to also load user preferences from a config file and set them in the shared cache.
The post_tool_use hook is not executing correctly. Test it using the echo method to diagnose the issue.
Add a security validation module to the pre_tool_use hook that blocks commands containing dangerous patterns like rm -rf or direct path access to /etc.
أفضل الممارسات
- Always test hooks using echo piped to stdin before deployment - never create temporary test files
- Use Python over shell scripts when possible for better error handling and cross-platform compatibility
- Implement idempotent operations so running hooks multiple times produces the same result
- Return appropriate exit codes: 0 to allow, 2 to block, other non-zero for non-blocking errors
تجنب
- Never hardcode credentials or secrets in hook scripts
- Never create hooks that can cause infinite loops or hang indefinitely
- Never bypass security validations or access controls
- Never write complex logic in hooks - keep them simple and focused on single responsibilities