Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 10, 2025

This PR fixes the E2BIG error that occurs when using the Claude Code API provider with large system prompts.

Problem

The claude flow install command 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

  • Removed platform-specific logic that passed system prompt as command-line argument on non-Windows platforms
  • Now always pass both system prompt and messages via stdin for all platforms
  • This prevents hitting the execve argument size limit that causes E2BIG errors
  • Updated tests to reflect the unified behavior across all platforms

Testing

  • All existing tests pass
  • Updated test suite to verify that both Windows and non-Windows platforms now use the same stdin approach
  • Manually tested with large system prompts that previously triggered E2BIG errors

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.

  • Behavior:
    • Removed platform-specific logic in run.ts to pass system prompt as command-line argument.
    • Now always pass system prompt and messages via stdin to avoid E2BIG errors.
    • Ensures consistent behavior across all platforms.
  • Testing:
    • Updated tests in run.spec.ts to verify stdin usage for all platforms.
    • Manually tested with large system prompts to confirm fix.
  • Error Handling:
    • Enhanced error handling for ENOENT errors with user-friendly messages in run.ts.

This description was created by Ellipsis for 38b6a77. You can customize this summary. It will automatically update as commits are pushed.

- 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 10, 2025 21:54
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 10, 2025
Copy link
Contributor Author

@roomote roomote bot left a 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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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 () => {
Copy link
Contributor Author

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.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 10, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 13, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 13, 2025
@daniel-lxs
Copy link
Member

daniel-lxs commented Aug 14, 2025

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:

  1. Send the base system prompt via the --system-prompt flag (without custom instructions) - this properly replaces Claude Code's default system prompt
  2. Send only the custom instructions and messages via stdin

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.

@daniel-lxs daniel-lxs closed this Aug 14, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 14, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 14, 2025
@daniel-lxs daniel-lxs deleted the feature/fix-claude-code-e2big-error branch August 14, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

E2BIG Error with Claude Code API Provider

4 participants