-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve E2BIG error with Claude Code API provider (#6910) #6911
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
Conversation
- Remove platform-specific logic that passed system prompt as command-line argument on non-Windows - Always pass both system prompt and messages via stdin to avoid execve limit (~128KiB on Linux) - Update tests to reflect unified behavior across all platforms - Remove unused os import Fixes #6910
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 backward but the bugs are still mine.
| } else { | ||
| stdinData = JSON.stringify(messages) | ||
| } | ||
| // Always pass both system prompt and messages via stdin to avoid E2BIG errors |
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.
Consider adding more context about the E2BIG limits for future maintainers. Something like: 'E2BIG typically occurs around ~128KiB on Linux, varies by system'. This would help explain why we chose this approach over command-line arguments.
| mockExeca.mockReturnValue(createMockProcess()) | ||
|
|
||
| // Test on non-Windows | ||
| // Test on non-Windows (Linux/macOS) |
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.
Is the os module import still needed? Since we're no longer testing platform-specific behavior, the platform mock at lines 20-22 isn't used anymore after unifying the stdin behavior.
| }) | ||
|
|
||
| test("should handle platform-specific stdin behavior", async () => { | ||
| test("should pass both system prompt and messages via stdin for all platforms", 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.
Would it be valuable to add a test case with an extremely large system prompt to ensure we don't regress on the E2BIG issue? We could create a prompt that would have exceeded the command-line limit to verify the stdin approach handles it gracefully.
|
After further investigation, this approach has an unintended side effect. When we send the system prompt via stdin, Claude Code combines its own internal system prompt with ours, rather than replacing it. This is being done on Windows because the system prompt causes problems if sent in the command itself and not via stdin. The current solution sends everything via stdin to avoid E2BIG errors, but this causes Claude Code to append our system prompt to its own, which is not the intended behavior. Since the E2BIG issue appears to be related to custom instructions being too large, we should consider an alternative approach:
This would avoid the E2BIG error while ensuring Claude Code uses only our system prompt, not a combination of both. Closing this PR to explore the alternative solution. |
This PR fixes the E2BIG error that occurs when using the Claude Code API provider with large system prompts.
Problem
The
claude flow installcommand was failing with an E2BIG error when using the Claude Code API provider, while the same operation worked successfully in Cline. This was caused by passing the system prompt as a command-line argument on non-Windows platforms, which could exceed the execve limit (~128KiB on Linux).Solution
Testing
Impact
This change ensures consistent behavior across all platforms and prevents command execution failures when using Claude Code with large system prompts or in environments with many environment variables.
Fixes #6910
Important
Fixes E2BIG error in Claude Code API by passing data via stdin universally, ensuring consistent cross-platform behavior.
run.tsto pass system prompt as command-line argument.run.spec.tsto verify stdin usage for all platforms.run.ts.This description was created by
for 38b6a77. You can customize this summary. It will automatically update as commits are pushed.