$npx -y skills add NeoLabHQ/context-engineering-kit --skill create-hookCreate and configure git hooks with intelligent project analysis, suggestions, and automated testing
| 1 | # Create Hook Command |
| 2 | |
| 3 | Analyze the project, suggest practical hooks, and create them with proper testing. |
| 4 | |
| 5 | ## Your Task (/create-hook) |
| 6 | |
| 7 | 1. **Analyze environment** - Detect tooling and existing hooks |
| 8 | 2. **Suggest hooks** - Based on your project configuration |
| 9 | 3. **Configure hook** - Ask targeted questions and create the script |
| 10 | 4. **Test & validate** - Ensure the hook works correctly |
| 11 | |
| 12 | ## Your Workflow |
| 13 | |
| 14 | ### 1. Environment Analysis & Suggestions |
| 15 | |
| 16 | Automatically detect the project tooling and suggest relevant hooks: |
| 17 | |
| 18 | **When TypeScript is detected (`tsconfig.json`):** |
| 19 | |
| 20 | - PostToolUse hook: "Type-check files after editing" |
| 21 | - PreToolUse hook: "Block edits with type errors" |
| 22 | |
| 23 | **When Prettier is detected (`.prettierrc`, `prettier.config.js`):** |
| 24 | |
| 25 | - PostToolUse hook: "Auto-format files after editing" |
| 26 | - PreToolUse hook: "Require formatted code" |
| 27 | |
| 28 | **When ESLint is detected (`.eslintrc.*`):** |
| 29 | |
| 30 | - PostToolUse hook: "Lint and auto-fix after editing" |
| 31 | - PreToolUse hook: "Block commits with linting errors" |
| 32 | |
| 33 | **When package.json has scripts:** |
| 34 | |
| 35 | - `test` script → "Run tests before commits" |
| 36 | - `build` script → "Validate build before commits" |
| 37 | |
| 38 | **When a git repository is detected:** |
| 39 | |
| 40 | - PreToolUse/Bash hook: "Prevent commits with secrets" |
| 41 | - PostToolUse hook: "Security scan on file changes" |
| 42 | |
| 43 | **Decision Tree:** |
| 44 | |
| 45 | ``` |
| 46 | Project has TypeScript? → Suggest type checking hooks |
| 47 | Project has formatter? → Suggest formatting hooks |
| 48 | Project has tests? → Suggest test validation hooks |
| 49 | Security sensitive? → Suggest security hooks |
| 50 | + Scan for additional patterns and suggest custom hooks based on: |
| 51 | - Custom scripts in package.json |
| 52 | - Unique file patterns or extensions |
| 53 | - Development workflow indicators |
| 54 | - Project-specific tooling configurations |
| 55 | ``` |
| 56 | |
| 57 | ### 2. Hook Configuration |
| 58 | |
| 59 | Start by asking: **"What should this hook do?"** and offer relevant suggestions from your analysis. |
| 60 | |
| 61 | Then understand the context from the user's description and **only ask about details you're unsure about**: |
| 62 | |
| 63 | 1. **Trigger timing**: When should it run? |
| 64 | - `PreToolUse`: Before file operations (can block) |
| 65 | - `PostToolUse`: After file operations (feedback/fixes) |
| 66 | - `UserPromptSubmit`: Before processing requests |
| 67 | - Other event types as needed |
| 68 | |
| 69 | 2. **Tool matcher**: Which tools should trigger it? (`Write`, `Edit`, `Bash`, `*` etc) |
| 70 | |
| 71 | 3. **Scope**: `global`, `project`, or `project-local` |
| 72 | |
| 73 | 4. **Response approach**: |
| 74 | - **Exit codes only**: Simple (exit 0 = success, exit 2 = block in PreToolUse) |
| 75 | - **JSON response**: Advanced control (blocking, context, decisions) |
| 76 | - Guide based on complexity: simple pass/fail → exit codes, rich feedback → JSON |
| 77 | |
| 78 | 5. **Blocking behavior** (if relevant): "Should this stop operations when issues are found?" |
| 79 | - PreToolUse: Can block operations (security, validation) |
| 80 | - PostToolUse: Usually provide feedback only |
| 81 | |
| 82 | 6. **Claude integration** (CRITICAL): "Should Claude Code automatically see and fix issues this hook detects?" |
| 83 | - If YES: Use `additionalContext` for error communication |
| 84 | - If NO: Use `suppressOutput: true` for silent operation |
| 85 | |
| 86 | 7. **Context pollution**: "Should successful operations be silent to avoid noise?" |
| 87 | - Recommend YES for formatting, routine checks |
| 88 | - Recommend NO for security alerts, critical errors |
| 89 | |
| 90 | 8. **File filtering**: "What file types should this hook process?" |
| 91 | |
| 92 | ### 3. Hook Creation |
| 93 | |
| 94 | You should: |
| 95 | |
| 96 | - **Create hooks directory**: `~/.claude/hooks/` or `.claude/hooks/` based on scope |
| 97 | - **Generate script**: Create hook script with: |
| 98 | - Proper shebang and executable permissions |
| 99 | - Project-specific commands (use detected config paths) |
| 100 | - Comments explaining the hook's purpose |
| 101 | - **Update settings**: Add hook configuration to appropriate settings.json |
| 102 | - **Use absolute paths**: Avoid relative paths to scripts and executables. Use `$CLAUDE_PROJECT_DIR` to reference project root |
| 103 | - **Offer validation**: Ask if the user wants you to test the hook |
| 104 | |
| 105 | **Key Implementation Standards:** |
| 106 | |
| 107 | - Read JSON from stdin (never use argv) |
| 108 | - Use top-level `additionalContext`/`systemMessage` for Claude communication |
| 109 | - Include `suppressOutput: true` for successful operations |
| 110 | - Provide specific error counts and actionable feedback |
| 111 | - Focus on changed files rather than entire codebase |
| 112 | - Support common development workflows |
| 113 | |
| 114 | **⚠️ CRITICAL: Input/Output Format** |
| 115 | |
| 116 | This is where most hook implementations fail. Pay extra attention to: |
| 117 | |
| 118 | - **Input**: Reading JSON from stdin correctly (not argv) |
| 119 | - **Output**: Using correct top-level JSON structure for Claude communication |
| 120 | - **Documentation**: Consulting official docs for exact schemas when in doubt |
| 121 | |
| 122 | ### 4. Testing & Validation |
| 123 | |
| 124 | **CRITICAL: Test both happy and sad paths:** |
| 125 | |
| 126 | **Happy Path Testing:** |
| 127 | |
| 128 | 1. **Test expected success scenario** - Create conditions where hook should pass |
| 129 | - _Examples_: TypeScript (valid |