From 9d9f3b3736d5d29e5ebe2173129530a78a63cbf6 Mon Sep 17 00:00:00 2001 From: Echoing Vesper <38582585+EchoingVesper@users.noreply.github.com> Date: Thu, 26 Jun 2025 17:19:42 -0500 Subject: [PATCH 1/3] fix: minimal Claude Code Windows integration fix - Use stdin instead of command-line arguments for input - Fix command-line flags (--print, --input-format stream-json) - Add WSL execution wrapper for Windows This minimal fix addresses the Windows compatibility issue without restructuring the message format or prompt handling. --- src/integrations/claude-code/run.ts | 70 ++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/integrations/claude-code/run.ts b/src/integrations/claude-code/run.ts index 84f1fe0902..3d59d1239d 100644 --- a/src/integrations/claude-code/run.ts +++ b/src/integrations/claude-code/run.ts @@ -109,28 +109,58 @@ const CLAUDE_CODE_TIMEOUT = 600000 // 10 minutes function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions) { const claudePath = path || "claude" - - const args = [ - "-p", - JSON.stringify(messages), - "--system-prompt", - systemPrompt, - "--verbose", - "--output-format", - "stream-json", - "--disallowedTools", - claudeCodeTools, - // Roo Code will handle recursive calls - "--max-turns", - "1", - ] + const isWindows = process.platform === "win32" + + // Prepare input data for stdin + const inputData = { + messages, + systemPrompt + } + + let actualClaudePath = claudePath + let args: string[] + + if (isWindows) { + // Use WSL to execute claude on Windows + actualClaudePath = "wsl.exe" + args = [ + "--", + "claude", + "--print", + "--verbose", + "--input-format", + "stream-json", + "--output-format", + "stream-json", + "--disallowedTools", + claudeCodeTools, + // Roo Code will handle recursive calls + "--max-turns", + "1", + ] + } else { + // Direct execution on Linux/Mac + args = [ + "--print", + "--verbose", + "--input-format", + "stream-json", + "--output-format", + "stream-json", + "--disallowedTools", + claudeCodeTools, + // Roo Code will handle recursive calls + "--max-turns", + "1", + ] + } if (modelId) { args.push("--model", modelId) } - return execa(claudePath, args, { - stdin: "ignore", + const child = execa(actualClaudePath, args, { + stdin: "pipe", stdout: "pipe", stderr: "pipe", env: { @@ -142,6 +172,12 @@ function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions maxBuffer: 1024 * 1024 * 1000, timeout: CLAUDE_CODE_TIMEOUT, }) + + // Send input via stdin + child.stdin?.write(JSON.stringify(inputData)) + child.stdin?.end() + + return child } function parseChunk(data: string, processState: ProcessState) { From 5fbb743d0c0a134939512f452f1d21c6332d83a4 Mon Sep 17 00:00:00 2001 From: Echoing Vesper <38582585+EchoingVesper@users.noreply.github.com> Date: Thu, 26 Jun 2025 18:37:45 -0500 Subject: [PATCH 2/3] fix: correct Claude Code SDK message format - Claude Code requires input in SDKMessage format via stdin. This minimal message transformation is necessary for compatibility. --- src/integrations/claude-code/run.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/integrations/claude-code/run.ts b/src/integrations/claude-code/run.ts index 3d59d1239d..30d2994f1f 100644 --- a/src/integrations/claude-code/run.ts +++ b/src/integrations/claude-code/run.ts @@ -110,16 +110,26 @@ const CLAUDE_CODE_TIMEOUT = 600000 // 10 minutes function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions) { const claudePath = path || "claude" const isWindows = process.platform === "win32" - - // Prepare input data for stdin - const inputData = { + + // Prepare input data for stdin in Claude Code SDK format + // We need to combine system prompt and messages into a single prompt + const prompt = JSON.stringify({ messages, - systemPrompt + systemPrompt, + }) + + const inputData = { + type: "user", + message: { + role: "user", + content: prompt, + }, + session_id: `roo-${Date.now()}-${Math.random().toString(36).substring(7)}`, } - + let actualClaudePath = claudePath let args: string[] - + if (isWindows) { // Use WSL to execute claude on Windows actualClaudePath = "wsl.exe" @@ -172,11 +182,11 @@ function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions maxBuffer: 1024 * 1024 * 1000, timeout: CLAUDE_CODE_TIMEOUT, }) - + // Send input via stdin child.stdin?.write(JSON.stringify(inputData)) child.stdin?.end() - + return child } From 7b838d3edc438b49f5afca64eed30c6480bc3282 Mon Sep 17 00:00:00 2001 From: Echoing Vesper <38582585+EchoingVesper@users.noreply.github.com> Date: Thu, 26 Jun 2025 20:44:54 -0500 Subject: [PATCH 3/3] fix: replace Math.random() with crypto.getRandomValues() for secure session ID generation --- src/integrations/claude-code/run.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/integrations/claude-code/run.ts b/src/integrations/claude-code/run.ts index 30d2994f1f..061678f4b7 100644 --- a/src/integrations/claude-code/run.ts +++ b/src/integrations/claude-code/run.ts @@ -124,7 +124,10 @@ function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions role: "user", content: prompt, }, - session_id: `roo-${Date.now()}-${Math.random().toString(36).substring(7)}`, + session_id: `roo-${Date.now()}-${Array.from(crypto.getRandomValues(new Uint8Array(4))) + .map((b) => b.toString(36)) + .join("") + .substring(0, 7)}`, } let actualClaudePath = claudePath