building-hooks
Create event hooks for Claude Code automation
Claude Code hooks enable event-driven automation and policy enforcement. This skill provides expertise in creating hooks that validate tool usage, enforce security policies, and automate workflows triggered by user prompts and tool invocations.
تنزيل ZIP المهارة
رفع في Claude
اذهب إلى Settings → Capabilities → Skills → Upload skill
فعّل وابدأ الاستخدام
اختبرها
استخدام "building-hooks". Create a hook that blocks rm -rf commands before they execute
النتيجة المتوقعة:
- Created hooks.json with PreToolUse event targeting Bash tool
- Validation script blocks destructive commands using grep pattern
- Returns decision: block with reason explaining the restriction
- Exit code 2 ensures the tool is blocked from execution
استخدام "building-hooks". Set up auto-formatting for Python files when I write them
النتيجة المتوقعة:
- Configured PostToolUse hook with matcher: Write
- Created format-script.sh that runs black on *.py files
- Hook returns approve decision with reason after formatting
- User must run chmod +x on the script to enable it
التدقيق الأمني
آمنThis is a documentation and guidance skill for creating Claude Code event hooks. All 339 static findings are FALSE POSITIVES. The flagged patterns are: (1) documentation code blocks in markdown showing example commands, (2) defensive security validation code that BLOCKS dangerous commands, and (3) legitimate validation scripts for JSON schema checking. No actual dangerous commands are executed by this skill. The skill actively promotes security best practices including input validation and command blocking.
عوامل الخطر
⚙️ الأوامر الخارجية (258)
📁 الوصول إلى نظام الملفات (8)
🌐 الوصول إلى الشبكة (1)
درجة الجودة
ماذا يمكنك بناءه
Automate security validation
Create PreToolUse hooks that validate bash commands before execution, blocking dangerous operations.
Build event-driven plugins
Design hooks that trigger formatting, logging, or cleanup actions after Write or Edit operations.
Enforce coding policies
Implement hooks that audit all tool usage, log actions, and block non-compliant operations.
جرّب هذه الموجهات
Create a PreToolUse hook that validates Bash tool commands before execution. The hook should block dangerous commands like rm -rf /, dd if=, and mkfs commands. Return JSON with decision field.
Create a PostToolUse hook that auto-formats Python files with black and JavaScript files with prettier after Write operations. Include file extension checking.
Create a hook configuration that protects /etc, /usr, /boot, and /sys directories from Write and Edit operations. Block any file modifications in these paths.
Design a PostToolUse hook with matcher: * that logs all tool invocations. Capture tool name, parameters, and timestamp in structured JSON.
أفضل الممارسات
- Always validate hook scripts with validate-hooks.py before deployment
- Use specific matchers like Write|Edit instead of wildcards when possible
- Implement input sanitization with regex validation before using parameters
- Test hooks by triggering the expected events before production use
تجنب
- Using eval or command substitution without input validation
- Creating hooks with overly broad matchers like * that catch all tools
- Blocking operations without providing helpful system messages to users
- Forgetting to make hook scripts executable with chmod +x