From 7ba2fbdabc8ac99658f6503fcaad4fc426decbe4 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:53:25 +0000 Subject: [PATCH] fix: restore Claude tool call ID normalization from upstream The normalizeMessages function in transform.ts was missing a block that normalizes tool call IDs for Claude models. This block exists in the upstream OpenCode repo but was inadvertently removed in our fork. The normalization replaces any characters that are not alphanumeric, underscore, or hyphen with underscores in toolCallId fields. This prevents Claude from rejecting messages with tool call IDs containing invalid characters. --- packages/opencode/src/provider/transform.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 7f6c44b858..a4fc64f22f 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -72,6 +72,23 @@ export namespace ProviderTransform { .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "") } + if (model.api.id.includes("claude")) { + return msgs.map((msg) => { + if ((msg.role === "assistant" || msg.role === "tool") && Array.isArray(msg.content)) { + msg.content = msg.content.map((part) => { + if ((part.type === "tool-call" || part.type === "tool-result") && "toolCallId" in part) { + return { + ...part, + toolCallId: part.toolCallId.replace(/[^a-zA-Z0-9_-]/g, "_"), + } + } + return part + }) + } + return msg + }) + } + if ( model.providerID === "mistral" || model.api.id.toLowerCase().includes("mistral") ||