* Dispatch all PreToolUse hooks for a tool. * Returns { blocked, blockMessage, script } — first exit-2 stops dispatch.
(sandbox, toolName, toolInput)
| 106 | * Dispatch all PreToolUse hooks for a tool. |
| 107 | * Returns { blocked, blockMessage, script } — first exit-2 stops dispatch. |
| 108 | */ |
| 109 | function preToolUse(sandbox, toolName, toolInput) { |
| 110 | const scripts = getHooksForEvent(sandbox, 'PreToolUse', toolName); |
| 111 | for (const scriptPath of scripts) { |
| 112 | const r = spawnSync('node', [scriptPath], { |
| 113 | input: JSON.stringify({ tool_name: toolName, tool_input: toolInput }), |
| 114 | cwd: sandbox, |
| 115 | env: { ...process.env, CLAUDE_PROJECT_DIR: sandbox, CLAUDE_PLUGIN_DATA: path.join(sandbox, '.claude') }, |
| 116 | encoding: 'utf8', |
| 117 | timeout: 10000, |
| 118 | }); |
| 119 | if ((r.status ?? -1) === 2) { |
| 120 | return { blocked: true, blockMessage: r.stdout || '', script: path.basename(scriptPath) }; |
| 121 | } |
| 122 | } |
| 123 | return { blocked: false }; |
| 124 | } |
| 125 | |
| 126 | /** |
no test coverage detected