mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: prevent E2BIG errors and mixed system prompts in Claude Code provider
- Always pass base system prompt via --system-prompt flag on all platforms - Send only messages via stdin to avoid E2BIG errors - Ensures Claude Code replaces its default prompt instead of merging - Fixes issues with large custom instructions causing argument size limits Fixes #8117
This commit is contained in:
parent
87b45def18
commit
d4dc2eb9b9
2 changed files with 13 additions and 26 deletions
|
|
@ -139,7 +139,7 @@ describe("runClaudeCode", () => {
|
|||
expect(typeof result[Symbol.asyncIterator]).toBe("function")
|
||||
})
|
||||
|
||||
test("should handle platform-specific stdin behavior", async () => {
|
||||
test("should always pass system prompt via flag and messages via stdin", async () => {
|
||||
const { runClaudeCode } = await import("../run")
|
||||
const messages = [{ role: "user" as const, content: "Hello world!" }]
|
||||
const systemPrompt = "You are a helpful assistant"
|
||||
|
|
@ -158,12 +158,13 @@ describe("runClaudeCode", () => {
|
|||
results.push(chunk)
|
||||
}
|
||||
|
||||
// On Windows, should NOT have --system-prompt in args
|
||||
// On Windows, should now ALWAYS have --system-prompt in args
|
||||
const [, args] = mockExeca.mock.calls[0]
|
||||
expect(args).not.toContain("--system-prompt")
|
||||
expect(args).toContain("--system-prompt")
|
||||
expect(args).toContain(systemPrompt)
|
||||
|
||||
// Should pass both system prompt and messages via stdin
|
||||
const expectedStdinData = JSON.stringify({ systemPrompt, messages })
|
||||
// Should only pass messages via stdin (no longer includes system prompt)
|
||||
const expectedStdinData = JSON.stringify(messages)
|
||||
expect(mockStdin.write).toHaveBeenCalledWith(expectedStdinData, "utf8", expect.any(Function))
|
||||
|
||||
// Reset mocks for non-Windows test
|
||||
|
|
@ -179,12 +180,12 @@ describe("runClaudeCode", () => {
|
|||
results2.push(chunk)
|
||||
}
|
||||
|
||||
// On non-Windows, should have --system-prompt in args
|
||||
// On non-Windows, should also have --system-prompt in args
|
||||
const [, args2] = mockExeca.mock.calls[0]
|
||||
expect(args2).toContain("--system-prompt")
|
||||
expect(args2).toContain(systemPrompt)
|
||||
|
||||
// Should only pass messages via stdin
|
||||
// Should only pass messages via stdin (consistent across platforms)
|
||||
expect(mockStdin.write).toHaveBeenCalledWith(JSON.stringify(messages), "utf8", expect.any(Function))
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -154,15 +154,9 @@ function runProcess({
|
|||
maxOutputTokens,
|
||||
}: ClaudeCodeOptions & { maxOutputTokens?: number }) {
|
||||
const claudePath = path || "claude"
|
||||
const isWindows = os.platform() === "win32"
|
||||
|
||||
// Build args based on platform
|
||||
const args = ["-p"]
|
||||
|
||||
// Pass system prompt as flag on non-Windows, via stdin on Windows (avoids cmd length limits)
|
||||
if (!isWindows) {
|
||||
args.push("--system-prompt", systemPrompt)
|
||||
}
|
||||
// Build args - always pass system prompt as flag to avoid mixing with Claude Code's default
|
||||
const args = ["-p", "--system-prompt", systemPrompt]
|
||||
|
||||
args.push(
|
||||
"--verbose",
|
||||
|
|
@ -196,17 +190,9 @@ function runProcess({
|
|||
timeout: CLAUDE_CODE_TIMEOUT,
|
||||
})
|
||||
|
||||
// Prepare stdin data: Windows gets both system prompt & messages (avoids 8191 char limit),
|
||||
// other platforms get messages only (avoids Linux E2BIG error from ~128KiB execve limit)
|
||||
let stdinData: string
|
||||
if (isWindows) {
|
||||
stdinData = JSON.stringify({
|
||||
systemPrompt,
|
||||
messages,
|
||||
})
|
||||
} else {
|
||||
stdinData = JSON.stringify(messages)
|
||||
}
|
||||
// Prepare stdin data: only send messages to avoid E2BIG errors
|
||||
// System prompt is now always passed via --system-prompt flag
|
||||
const stdinData = JSON.stringify(messages)
|
||||
|
||||
// Use setImmediate to ensure process is spawned before writing (prevents stdin race conditions)
|
||||
setImmediate(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue