diff --git a/.changeset/early-coins-fall.md b/.changeset/early-coins-fall.md new file mode 100644 index 00000000..c95b361b --- /dev/null +++ b/.changeset/early-coins-fall.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Prevents adding multiple tool results by adding existence check diff --git a/src/core/task/tools/utils/ToolResultUtils.ts b/src/core/task/tools/utils/ToolResultUtils.ts index 3feef3b5..0d26562b 100644 --- a/src/core/task/tools/utils/ToolResultUtils.ts +++ b/src/core/task/tools/utils/ToolResultUtils.ts @@ -3,6 +3,7 @@ import { ToolUse } from "@core/assistant-message" import { formatResponse } from "@core/prompts/responses" import { ToolResponse } from "@core/task" import { processFilesIntoText } from "@/integrations/misc/extract-text" +import { Logger } from "@/services/logging/Logger" import { ClineAsk } from "@/shared/ExtensionMessage" import type { ToolExecutorCoordinator } from "../ToolExecutorCoordinator" import { TaskConfig } from "../types/TaskConfig" @@ -38,6 +39,14 @@ export class ToolResultUtils { // Get tool_use_id from map, or use "cline" as fallback for backward compatibility const toolUseId = toolUseIdMap?.get(block.name) || "cline" + // If we have already added a tool result for this tool use, skip adding another one + if ( + userMessageContent.some((item) => item.type === "tool_result" && item.tool_use_id === toolUseId && item.content) + ) { + Logger.warn(`ToolResultUtils: Tool result for tool_use_id ${toolUseId} already exists. Skipping duplicate.`) + return + } + // Create ToolResultBlockParam with description and result userMessageContent.push(ToolResultUtils.createToolResultBlock(`${description} Result:\n${resultText}`, toolUseId)) } else {