Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 61 additions & 15 deletions src/integrations/claude-code/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,68 @@

function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions) {
const claudePath = path || "claude"
const isWindows = process.platform === "win32"

const args = [
"-p",
JSON.stringify(messages),
"--system-prompt",
// 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,
"--verbose",
"--output-format",
"stream-json",
"--disallowedTools",
claudeCodeTools,
// Roo Code will handle recursive calls
"--max-turns",
"1",
]
})

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"
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: {
Expand All @@ -142,6 +182,12 @@
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) {
Expand Down