From 7a96a167e61e231820f544b75b75f06fcc44e1b7 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 18 Mar 2026 14:18:49 +0900 Subject: [PATCH] perf(claude-code-hooks): defer config loading until after disabled check Move loadClaudeHooksConfig and loadPluginExtendedConfig after isHookDisabled check in both tool-execute-before and tool-execute-after handlers to skip 5 file reads per tool call when hooks are disabled (C1) --- .../claude-code-hooks/handlers/tool-execute-after-handler.ts | 5 +++-- .../handlers/tool-execute-before-handler.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hooks/claude-code-hooks/handlers/tool-execute-after-handler.ts b/src/hooks/claude-code-hooks/handlers/tool-execute-after-handler.ts index c9adf45e8..fa37ea8b7 100644 --- a/src/hooks/claude-code-hooks/handlers/tool-execute-after-handler.ts +++ b/src/hooks/claude-code-hooks/handlers/tool-execute-after-handler.ts @@ -79,8 +79,6 @@ export function createToolExecuteAfterHandler(ctx: PluginInput, config: PluginCo return } - const claudeConfig = await loadClaudeHooksConfig() - const extendedConfig = await loadPluginExtendedConfig() const cachedInput = getToolInput(input.sessionID, input.tool, input.callID) || {} @@ -96,6 +94,9 @@ export function createToolExecuteAfterHandler(ctx: PluginInput, config: PluginCo return } + const claudeConfig = await loadClaudeHooksConfig() + const extendedConfig = await loadPluginExtendedConfig() + const postClient: PostToolUseClient = { session: { messages: (opts) => ctx.client.session.messages(opts), diff --git a/src/hooks/claude-code-hooks/handlers/tool-execute-before-handler.ts b/src/hooks/claude-code-hooks/handlers/tool-execute-before-handler.ts index 164c52682..412cc2c23 100644 --- a/src/hooks/claude-code-hooks/handlers/tool-execute-before-handler.ts +++ b/src/hooks/claude-code-hooks/handlers/tool-execute-before-handler.ts @@ -43,8 +43,6 @@ export function createToolExecuteBeforeHandler(ctx: PluginInput, config: PluginC log("todowrite: parsed todos string to array", { sessionID: input.sessionID }) } - const claudeConfig = await loadClaudeHooksConfig() - const extendedConfig = await loadPluginExtendedConfig() appendTranscriptEntry(input.sessionID, { type: "tool_use", @@ -59,6 +57,9 @@ export function createToolExecuteBeforeHandler(ctx: PluginInput, config: PluginC return } + const claudeConfig = await loadClaudeHooksConfig() + const extendedConfig = await loadPluginExtendedConfig() + const preCtx: PreToolUseContext = { sessionId: input.sessionID, toolName: input.tool,