-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve E2BIG error by passing large prompts via stdin to Claude CLI #5186
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
… CLI - Pass messages via stdin instead of command line arguments to avoid Linux argument length limits - Add --input-format text flag to claude CLI command - Update execa configuration to use stdin pipe - Fix corresponding unit tests with proper async iterator mocking - Resolves spawn E2BIG errors when using very large conversation histories
- Use setImmediate to ensure process is spawned before writing to stdin - Add proper error handling for stdin write operations - Add tests for error scenarios - Update existing tests to handle async behavior properly
|
This doesn't work for me. I tested it with the same prompt that caused me to create #5064, and I get this error. This is also the exact same error I was running into while trying to make my own PR in a very like way. It relates to part of the system prompt getting misinterpreted.
The part of the system prompt that contains this string. SEARCH\n:start_line: (required) The line number of original content where the search block starts.\n-------\n[exact content to find including whitespace]\n=======\n[new content to replace with]\n>>>>>>> REPLACE\n\n |
The --input-format text flag was causing the Claude CLI to misinterpret the JSON content passed via stdin, leading to errors like 'unknown option -------' when the system prompt contained dashes. Removing this flag allows the CLI to properly handle the JSON input via stdin.
|
I've pushed a fix that should address the reported issue. The problem was that the When the system prompt contained certain characters (like Changes made:
The Claude CLI appears to handle JSON input via stdin correctly without needing to specify an input format. This should resolve the issue while maintaining the fix for the original E2BIG error. Please test this with your original prompt that was causing the issue and let me know if it works correctly now. For reference, these are the only required parameters when using |
daniel-lxs
left a comment
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.
Thank you @Fovty for your contribution!
LGTM
|
Same issue with the latest commit. I can see your Beginning of error: End of error: |
|
I can confirm removing the system prompt makes the error go away, and it worked. So the problem to solve is how to format the system prompt properly. I am surprised the system prompt worked in the first place, but there is some under the hood issue with I also suspect that you are kicking the can with the Here are the biggest files in one of my projects: |
… CLI (#5186) * fix: resolve E2BIG error by passing large prompts via stdin to Claude CLI - Pass messages via stdin instead of command line arguments to avoid Linux argument length limits - Add --input-format text flag to claude CLI command - Update execa configuration to use stdin pipe - Fix corresponding unit tests with proper async iterator mocking - Resolves spawn E2BIG errors when using very large conversation histories * fix: address race condition and improve error handling - Use setImmediate to ensure process is spawned before writing to stdin - Add proper error handling for stdin write operations - Add tests for error scenarios - Update existing tests to handle async behavior properly * fix: remove --input-format text flag to prevent CLI parsing errors The --input-format text flag was causing the Claude CLI to misinterpret the JSON content passed via stdin, leading to errors like 'unknown option -------' when the system prompt contained dashes. Removing this flag allows the CLI to properly handle the JSON input via stdin. --------- Co-authored-by: Daniel Riccio <[email protected]>
fix: resolve E2BIG error by passing large prompts via stdin to Claude CLI
Related GitHub Issue
Closes: #5064
Closes: #5097
Description
This PR fixes the
spawn E2BIGerror that occurs when users interact with Claude CLI through Roo Code with large conversation histories or extensive context. The error happens because Linux imposes a per-argument limit (~128 KiB) on command-line arguments passed toexecve()system calls.Key implementation details:
src/integrations/claude-code/run.ts: Replaced command-line argument passing with stdin streaming for large message payloadssrc/integrations/claude-code/__tests__/run.spec.ts: Fixed async iterator mocking to properly test stdin functionalityTechnical approach:
JSON.stringify(messages)from args array to avoid argument length limits--input-format textflag to enable stdin message readingexecawithstdin: "pipe"and stream messages as JSONchild.stdin.end()Test Procedure
Unit Testing:
src/directory:cd src && npm test src/integrations/claude-code/__tests__/run.spec.tsManual Testing (if accessible):
spawn E2BIGerrors occurEnvironment Requirements:
Pre-Submission Checklist
Documentation Updates
This is an internal bug fix that doesn't change user-facing APIs or require documentation updates. The fix is transparent to end users.
Additional Notes
Get in Touch
@Fovty
Important
Fix E2BIG error in Claude CLI by passing large prompts via stdin, updating
run.tsand tests inrun.spec.ts.run.tsto avoid E2BIG error with large prompts.--input-format textflag to Claude CLI command.execawithstdin: "pipe".run.spec.tsto mock stdin behavior and verify new implementation.JSON.stringify(messages)from command-line arguments inrun.ts.child.stdin.end()inrun.ts.This description was created by
for eee0c20. You can customize this summary. It will automatically update as commits are pushed.