Skip to content

Commit 5fbb743

Browse files
committed
fix: correct Claude Code SDK message format - Claude Code requires input in SDKMessage format via stdin. This minimal message transformation is necessary for compatibility.
1 parent 9d9f3b3 commit 5fbb743

File tree

1 file changed

+18
-8
lines changed
  • src/integrations/claude-code

1 file changed

+18
-8
lines changed

src/integrations/claude-code/run.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,26 @@ const CLAUDE_CODE_TIMEOUT = 600000 // 10 minutes
110110
function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions) {
111111
const claudePath = path || "claude"
112112
const isWindows = process.platform === "win32"
113-
114-
// Prepare input data for stdin
115-
const inputData = {
113+
114+
// Prepare input data for stdin in Claude Code SDK format
115+
// We need to combine system prompt and messages into a single prompt
116+
const prompt = JSON.stringify({
116117
messages,
117-
systemPrompt
118+
systemPrompt,
119+
})
120+
121+
const inputData = {
122+
type: "user",
123+
message: {
124+
role: "user",
125+
content: prompt,
126+
},
127+
session_id: `roo-${Date.now()}-${Math.random().toString(36).substring(7)}`,
118128
}
119-
129+
120130
let actualClaudePath = claudePath
121131
let args: string[]
122-
132+
123133
if (isWindows) {
124134
// Use WSL to execute claude on Windows
125135
actualClaudePath = "wsl.exe"
@@ -172,11 +182,11 @@ function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions
172182
maxBuffer: 1024 * 1024 * 1000,
173183
timeout: CLAUDE_CODE_TIMEOUT,
174184
})
175-
185+
176186
// Send input via stdin
177187
child.stdin?.write(JSON.stringify(inputData))
178188
child.stdin?.end()
179-
189+
180190
return child
181191
}
182192

0 commit comments

Comments
 (0)