From bb375b78ca8d770aaab8bce80d0a4e25fe4a24a8 Mon Sep 17 00:00:00 2001 From: CandiedUniverse <132302818+candieduniverse@users.noreply.github.com> Date: Thu, 13 Nov 2025 16:14:13 -0800 Subject: [PATCH] fix(hooks): Prevent PreToolUse hook from running before attempt_completion tool (#7450) --- src/core/task/tools/handlers/AttemptCompletionHandler.ts | 2 +- src/core/task/tools/utils/ToolHookUtils.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/task/tools/handlers/AttemptCompletionHandler.ts b/src/core/task/tools/handlers/AttemptCompletionHandler.ts index f4fc8e47..57d13b24 100644 --- a/src/core/task/tools/handlers/AttemptCompletionHandler.ts +++ b/src/core/task/tools/handlers/AttemptCompletionHandler.ts @@ -93,7 +93,7 @@ export class AttemptCompletionHandler implements IToolHandler, IPartialBlockHand } // Remove any partial completion_result message that may exist - // PreToolUse hook inserts messages after the partial, so we need to search backwards to find it + // Search backwards since other messages may have been inserted after the partial const clineMessages = config.messageState.getClineMessages() const partialCompletionIndex = findLastIndex( clineMessages, diff --git a/src/core/task/tools/utils/ToolHookUtils.ts b/src/core/task/tools/utils/ToolHookUtils.ts index c8fd6e40..aab97fc9 100644 --- a/src/core/task/tools/utils/ToolHookUtils.ts +++ b/src/core/task/tools/utils/ToolHookUtils.ts @@ -25,6 +25,10 @@ export class ToolHookUtils { return true // Hooks disabled, continue execution } + if (block.name == "attempt_completion") { + return true // Skip this hook + } + // Import the hook executor dynamically const { executeHook } = await import("@core/hooks/hook-executor")