-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: prevent E2BIG errors and mixed system prompts in Claude Code provider #8120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…vider - 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
@@ -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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good update to the test name! This now accurately reflects that we're testing consistent behavior across all platforms rather than platform-specific behavior.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we expand this comment to be more explicit about the dual purpose? Something like:
const args = ["-p", "--system-prompt", systemPrompt] | |
// Build args - always pass system prompt as flag to ensure Claude Code replaces its default prompt entirely | |
// (avoids mixing prompts) while keeping argv small by sending messages via stdin (avoids E2BIG) |
stdinData = JSON.stringify(messages) | ||
} | ||
// Prepare stdin data: only send messages to avoid E2BIG errors | ||
// System prompt is now always passed via --system-prompt flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great simplification! These comments clearly explain the rationale. Is the os
import on line 7 still needed now that we've removed the platform-specific logic?
Summary
This PR addresses Issue #8117 by fixing E2BIG errors and preventing mixed system prompts when using the Claude Code API provider.
Problem
Users were experiencing two critical issues with the Claude Code provider:
Solution
The fix implements a consistent approach across all platforms:
--system-prompt
flag - This ensures Claude Code replaces its default prompt entirelyChanges
runProcess
function to always use--system-prompt
flag for the base system promptTesting
Impact
This fix ensures:
Fixes #8117
Important
Fixes E2BIG errors and mixed system prompts in Claude Code provider by consistently using
--system-prompt
flag and sending only messages via stdin.runProcess
inrun.ts
now always uses--system-prompt
flag for system prompts, preventing mixed prompts.run.spec.ts
to reflect new behavior, ensuring--system-prompt
is always used and only messages are sent via stdin.createClaudeCodeNotFoundError()
inrun.ts
for better user guidance.This description was created by
for d4dc2eb. You can customize this summary. It will automatically update as commits are pushed.