diff --git a/src/hooks/claude-code-hooks/config.ts b/src/hooks/claude-code-hooks/config.ts index 60f9bc27..3a03d200 100644 --- a/src/hooks/claude-code-hooks/config.ts +++ b/src/hooks/claude-code-hooks/config.ts @@ -20,7 +20,7 @@ interface RawClaudeHooksConfig { function normalizeHookMatcher(raw: RawHookMatcher): HookMatcher { return { matcher: raw.matcher ?? raw.pattern ?? "*", - hooks: raw.hooks, + hooks: Array.isArray(raw.hooks) ? raw.hooks : [], } } diff --git a/src/hooks/claude-code-hooks/post-tool-use.ts b/src/hooks/claude-code-hooks/post-tool-use.ts index abfcf448..31b88dc0 100644 --- a/src/hooks/claude-code-hooks/post-tool-use.ts +++ b/src/hooks/claude-code-hooks/post-tool-use.ts @@ -91,11 +91,12 @@ export async function executePostToolUseHooks( const startTime = Date.now() - for (const matcher of matchers) { - for (const hook of matcher.hooks) { - if (hook.type !== "command") continue + for (const matcher of matchers) { + if (!matcher.hooks || matcher.hooks.length === 0) continue + for (const hook of matcher.hooks) { + if (hook.type !== "command") continue - if (isHookCommandDisabled("PostToolUse", hook.command, extendedConfig ?? null)) { + if (isHookCommandDisabled("PostToolUse", hook.command, extendedConfig ?? null)) { log("PostToolUse hook command skipped (disabled by config)", { command: hook.command, toolName: ctx.toolName }) continue } diff --git a/src/hooks/claude-code-hooks/pre-compact.ts b/src/hooks/claude-code-hooks/pre-compact.ts index 17a4b58e..e2d87739 100644 --- a/src/hooks/claude-code-hooks/pre-compact.ts +++ b/src/hooks/claude-code-hooks/pre-compact.ts @@ -47,11 +47,12 @@ export async function executePreCompactHooks( let firstHookName: string | undefined const collectedContext: string[] = [] - for (const matcher of matchers) { - for (const hook of matcher.hooks) { - if (hook.type !== "command") continue + for (const matcher of matchers) { + if (!matcher.hooks || matcher.hooks.length === 0) continue + for (const hook of matcher.hooks) { + if (hook.type !== "command") continue - if (isHookCommandDisabled("PreCompact", hook.command, extendedConfig ?? null)) { + if (isHookCommandDisabled("PreCompact", hook.command, extendedConfig ?? null)) { log("PreCompact hook command skipped (disabled by config)", { command: hook.command }) continue } diff --git a/src/hooks/claude-code-hooks/pre-tool-use.ts b/src/hooks/claude-code-hooks/pre-tool-use.ts index ac362a8e..2b5a33c5 100644 --- a/src/hooks/claude-code-hooks/pre-tool-use.ts +++ b/src/hooks/claude-code-hooks/pre-tool-use.ts @@ -74,11 +74,12 @@ export async function executePreToolUseHooks( let firstHookName: string | undefined const inputLines = buildInputLines(ctx.toolInput) - for (const matcher of matchers) { - for (const hook of matcher.hooks) { - if (hook.type !== "command") continue + for (const matcher of matchers) { + if (!matcher.hooks || matcher.hooks.length === 0) continue + for (const hook of matcher.hooks) { + if (hook.type !== "command") continue - if (isHookCommandDisabled("PreToolUse", hook.command, extendedConfig ?? null)) { + if (isHookCommandDisabled("PreToolUse", hook.command, extendedConfig ?? null)) { log("PreToolUse hook command skipped (disabled by config)", { command: hook.command, toolName: ctx.toolName }) continue } diff --git a/src/hooks/claude-code-hooks/stop.ts b/src/hooks/claude-code-hooks/stop.ts index d1e1e8d1..9792eb65 100644 --- a/src/hooks/claude-code-hooks/stop.ts +++ b/src/hooks/claude-code-hooks/stop.ts @@ -65,11 +65,12 @@ export async function executeStopHooks( hook_source: "opencode-plugin", } - for (const matcher of matchers) { - for (const hook of matcher.hooks) { - if (hook.type !== "command") continue + for (const matcher of matchers) { + if (!matcher.hooks || matcher.hooks.length === 0) continue + for (const hook of matcher.hooks) { + if (hook.type !== "command") continue - if (isHookCommandDisabled("Stop", hook.command, extendedConfig ?? null)) { + if (isHookCommandDisabled("Stop", hook.command, extendedConfig ?? null)) { log("Stop hook command skipped (disabled by config)", { command: hook.command }) continue } diff --git a/src/hooks/claude-code-hooks/user-prompt-submit.ts b/src/hooks/claude-code-hooks/user-prompt-submit.ts index b358ef39..1b80a076 100644 --- a/src/hooks/claude-code-hooks/user-prompt-submit.ts +++ b/src/hooks/claude-code-hooks/user-prompt-submit.ts @@ -70,9 +70,10 @@ export async function executeUserPromptSubmitHooks( hook_source: "opencode-plugin", } - for (const matcher of matchers) { - for (const hook of matcher.hooks) { - if (hook.type !== "command") continue + for (const matcher of matchers) { + if (!matcher.hooks || matcher.hooks.length === 0) continue + for (const hook of matcher.hooks) { + if (hook.type !== "command") continue if (isHookCommandDisabled("UserPromptSubmit", hook.command, extendedConfig ?? null)) { log("UserPromptSubmit hook command skipped (disabled by config)", { command: hook.command })