Merge pull request #1584 from code-yeongyu/fix/441-matcher-hooks-undefined

fix(hooks): add defensive null check for matcher.hooks to prevent Windows crash (#441)
This commit is contained in:
YeonGyu-Kim 2026-02-07 20:01:28 +09:00 committed by GitHub
commit 1cb8f8bee6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 25 additions and 20 deletions

View File

@ -20,7 +20,7 @@ interface RawClaudeHooksConfig {
function normalizeHookMatcher(raw: RawHookMatcher): HookMatcher { function normalizeHookMatcher(raw: RawHookMatcher): HookMatcher {
return { return {
matcher: raw.matcher ?? raw.pattern ?? "*", matcher: raw.matcher ?? raw.pattern ?? "*",
hooks: raw.hooks, hooks: Array.isArray(raw.hooks) ? raw.hooks : [],
} }
} }

View File

@ -92,6 +92,7 @@ export async function executePostToolUseHooks(
const startTime = Date.now() const startTime = Date.now()
for (const matcher of matchers) { for (const matcher of matchers) {
if (!matcher.hooks || matcher.hooks.length === 0) continue
for (const hook of matcher.hooks) { for (const hook of matcher.hooks) {
if (hook.type !== "command") continue if (hook.type !== "command") continue

View File

@ -48,6 +48,7 @@ export async function executePreCompactHooks(
const collectedContext: string[] = [] const collectedContext: string[] = []
for (const matcher of matchers) { for (const matcher of matchers) {
if (!matcher.hooks || matcher.hooks.length === 0) continue
for (const hook of matcher.hooks) { for (const hook of matcher.hooks) {
if (hook.type !== "command") continue if (hook.type !== "command") continue

View File

@ -75,6 +75,7 @@ export async function executePreToolUseHooks(
const inputLines = buildInputLines(ctx.toolInput) const inputLines = buildInputLines(ctx.toolInput)
for (const matcher of matchers) { for (const matcher of matchers) {
if (!matcher.hooks || matcher.hooks.length === 0) continue
for (const hook of matcher.hooks) { for (const hook of matcher.hooks) {
if (hook.type !== "command") continue if (hook.type !== "command") continue

View File

@ -66,6 +66,7 @@ export async function executeStopHooks(
} }
for (const matcher of matchers) { for (const matcher of matchers) {
if (!matcher.hooks || matcher.hooks.length === 0) continue
for (const hook of matcher.hooks) { for (const hook of matcher.hooks) {
if (hook.type !== "command") continue if (hook.type !== "command") continue

View File

@ -71,6 +71,7 @@ export async function executeUserPromptSubmitHooks(
} }
for (const matcher of matchers) { for (const matcher of matchers) {
if (!matcher.hooks || matcher.hooks.length === 0) continue
for (const hook of matcher.hooks) { for (const hook of matcher.hooks) {
if (hook.type !== "command") continue if (hook.type !== "command") continue