Skip to content

Conversation

SannidhyaSah
Copy link
Collaborator

@SannidhyaSah SannidhyaSah commented Jul 12, 2025

Description

Fixes #5042

This PR enables the Claude Code provider to run natively on Windows by implementing a stdin-based approach for passing both system prompt and messages. This eliminates the Windows command-line length limitation (8191 characters) that was preventing Claude Code from working on Windows systems.

Background

Claude Code was recently added with native Windows support, but the integration in Roo Code was hitting Windows' command-line argument length limitations when passing large system prompts. The previous implementation passed the system prompt as a command-line argument, which would fail on Windows when the prompt exceeded ~8KB.

Changes Made

  • Modified `src/integrations/claude-code/run.ts`: Refactored to always pass both `systemPrompt` and `messages` via stdin as a single JSON object
  • Updated tests in `src/integrations/claude-code/tests/run.spec.ts`: Updated test expectations to reflect the new stdin-based approach
  • Removed platform-specific code: The solution is now platform-agnostic, eliminating the need for Windows-specific workarounds

Technical Details

The key insight was that the Claude Code CLI accepts input via stdin (though this is undocumented). By passing both the system prompt and messages together through stdin, we:

  1. Completely bypass Windows command-line length limitations
  2. Simplify the code by removing platform-specific logic
  3. Make the implementation more robust and future-proof

Testing

  • All existing tests pass
  • Updated tests for stdin-based message passing
  • Manual testing completed:
    • Verified Claude Code provider works on Windows without WSL
    • Tested with large system prompts that previously failed
    • Confirmed functionality remains intact on Linux/macOS

Verification of Acceptance Criteria

  • Claude Code no longer gets stuck at "API Request" on Windows
  • Works natively on Windows without requiring WSL
  • Handles large system prompts without command-line limitations
  • Maintains compatibility with Linux and macOS

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated (if needed)
  • No breaking changes
  • Tests updated to reflect new behavior

Additional Notes

This fix not only resolves the immediate Windows issue but also provides a more elegant solution that works consistently across all platforms. The stdin approach is cleaner and more scalable than trying to work around platform-specific command-line limitations."


Important

Refactor Claude Code provider to use stdin for input, bypassing Windows command-line length limits and simplifying platform-specific logic.

  • Behavior:
    • Refactor runProcess() in run.ts to pass systemPrompt and messages via stdin as JSON, bypassing Windows command-line length limits.
    • Remove --system-prompt from command-line arguments in run.ts.
  • Testing:
    • Update tests in run.spec.ts to verify stdin-based input handling and ensure no --system-prompt in args.
    • Add tests for handling stdin write and access errors gracefully.
  • Misc:
    • Remove platform-specific code, making the solution platform-agnostic.

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

@SannidhyaSah SannidhyaSah requested review from mrubens, cte and jr as code owners July 12, 2025 05:28
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 12, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 12, 2025
daniel-lxs
daniel-lxs previously approved these changes Jul 12, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @SannidhyaSah !

It seems like stdin only accepts user messages:
https://docs.anthropic.com/en/docs/claude-code/sdk#streaming-json-input

I don't think I have seen issues with the way we send the system prompt currently.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 12, 2025
@SannidhyaSah
Copy link
Collaborator Author

SannidhyaSah commented Jul 12, 2025

Thank you @SannidhyaSah !

It seems like stdin only accepts user messages:
https://docs.anthropic.com/en/docs/claude-code/sdk#streaming-json-input

I don't think I have seen issues with the way we send the system prompt currently.

@daniel-lxs the problem was windows only has a limit of 8192 characters that can be sent in the terminal. And that meant the claude code provider wasn't really working as the system prompt wasn't being sent . Our system prompt is 131k charactes. I tinkered with it to make it work and was able to get it running with this approach. Basically it's either this . Or not working at all . For now ..

@SannidhyaSah
Copy link
Collaborator Author

SannidhyaSah commented Jul 12, 2025

image

this was a comparatively simpler task but it was able to do it . did not seem to encounter any errors in this run. it was using the sonnet 4.0 model here . that said .. we should probably test it more. let me know if you guys find anything

@daniel-lxs daniel-lxs dismissed their stale review July 12, 2025 13:35

It seems that Claude Code doesn't support overwriting the system prompt with stdin

@daniel-lxs
Copy link
Collaborator

daniel-lxs commented Jul 12, 2025

Hey! I did some testing on this PR to see how it handles system prompts via stdin.

It works - both the system prompt and messages are processed correctly when passed through stdin, which should help with the Windows command-line length issue. However, I noticed that this approach increases token usage compared to the current implementation.

When comparing token usage between the current main branch (which uses the --system-prompt flag) and this PR (which passes everything through stdin), I saw a clear increase in tokens consumed:

Screenshot_20250712_093846 image

A few concerns beyond the token cost:

  • This behavior is undocumented. The Claude Code docs say stdin is limited to user messages, yet { "systemPrompt": "...", "messages": [...] } seems to work.
  • Neither this PR nor the current implementation uses --input-format=stream-json, which is the only officially documented way to pass input via stdin.
  • It's unclear how the CLI handles this under the hood. The increased token usage suggests it might be duplicating or reprocessing the system prompt.
  • Since this relies on undocumented behavior, it could break in a future Claude Code update without warning.

While this does solve the Windows shell limit, the extra token usage is a significant tradeoff. We might want to explore other options like only enabling this on Windows since it will at least allow Windows users to use Claude Code.

@daniel-lxs daniel-lxs moved this from Triage to PR [Changes Requested] in Roo Code Roadmap Jul 12, 2025
@hannesrudolph hannesrudolph added PR - Changes Requested and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 12, 2025
…ndows

- Add OS detection to use stdin for both system prompt and messages on Windows
- Keep existing behavior on non-Windows platforms (system prompt as arg, messages via stdin)
- Consolidate verbose comments to be more concise
- Add comprehensive test coverage for both platform scenarios
- Resolves Windows command-line length limitations (8191 chars)
@SannidhyaSah SannidhyaSah force-pushed the fix/claude-code-windows-stdin branch from e2e2dd0 to dc7a9c6 Compare July 12, 2025 17:12
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 12, 2025
@blouflashdb
Copy link

Related: anthropics/claude-code#3411

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 14, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR successfully enables Claude Code on Windows by working around the command-line length limitation.

Note: This is a temporary workaround using undocumented stdin behavior for system prompts. Be aware that on Windows, the system prompt may be counted twice in token usage - once from the stdin data and once if Claude Code still processes the default system prompt internally.

Approving as it unblocks Windows users while a more permanent solution can be explored with the Claude Code team.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 14, 2025
@mrubens mrubens merged commit 824c494 into RooCodeInc:main Jul 14, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 14, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 14, 2025
@SannidhyaSah SannidhyaSah deleted the fix/claude-code-windows-stdin branch July 14, 2025 18:32
fxcl added a commit to tameslabs/Roo-Cline that referenced this pull request Jul 16, 2025
* main:
  fix: Resolve confusing auto-approve checkbox states (RooCodeInc#5602)
  fix: prevent empty mode names from being saved (RooCodeInc#5766) (RooCodeInc#5794)
  Format time in ISO 8601 (RooCodeInc#5793)
  fix: resolve DirectoryScanner memory leak and improve file limit handling (RooCodeInc#5785)
  Fix settings dirty check (RooCodeInc#5779)
  feat: increase Ollama API timeout values and extract as constants (RooCodeInc#5778)
  fix: Exclude Terraform and Terragrunt cache directories from checkpoints (RooCodeInc#4601) (RooCodeInc#5750)
  Move less commonly used provider settings into an advanced dropdown (RooCodeInc#5762)
  feat: Add configurable error & repetition limit with unified control (RooCodeInc#5654) (RooCodeInc#5752)
  list-files must include at least the first-level directory contents (RooCodeInc#5303)
  Update evals repo link (RooCodeInc#5758)
  Feature/vertex ai model name conversion (RooCodeInc#5728)
  fix(litellm): handle baseurl with paths correctly (RooCodeInc#5697)
  Add telemetry for todos (RooCodeInc#5746)
  feat: add undo functionality for enhance prompt feature (fixes RooCodeInc#5741) (RooCodeInc#5742)
  Fix max_tokens limit for moonshotai/kimi-k2-instruct on Groq (RooCodeInc#5740)
  Changeset version bump (RooCodeInc#5735)
  Add changeset for v3.23.12 patch release (RooCodeInc#5734)
  Update the max-token calculation in model-params to use the shared logic (RooCodeInc#5720)
  Changeset version bump (RooCodeInc#5719)
  chore: add changeset for v3.23.11 patch release (RooCodeInc#5718)
  Add Kimi K2 model and better support (RooCodeInc#5717)
  Fix: Remove invalid skip-checkout parameter from GitHub Actions workflows (RooCodeInc#5676)
  feat: add Cmd+Shift+. keyboard shortcut for previous mode switching (RooCodeInc#5695)
  Changeset version bump (RooCodeInc#5708)
  chore: add changeset for v3.23.10 patch release (RooCodeInc#5707)
  Add padding to the index model options (RooCodeInc#5706)
  fix: prioritize built-in model dimensions over custom dimensions (RooCodeInc#5705)
  Update CHANGELOG.md
  Changeset version bump (RooCodeInc#5702)
  chore: add changeset for v3.23.9 patch release (RooCodeInc#5701)
  Tweaks to command timeout error (RooCodeInc#5700)
  Update contributors list (RooCodeInc#5639)
  feat: enable Claude Code provider to run natively on Windows (RooCodeInc#5615)
  feat: Add configurable timeout for command execution (RooCodeInc#5668)
  feat: add gemini-embedding-001 model to code-index service (RooCodeInc#5698)
  fix: resolve vector dimension mismatch error when switching embedding models (RooCodeInc#5616) (RooCodeInc#5617)
  fix: [5424] return the cwd in the exec tool's response so that the model is not lost after subsequent calls (RooCodeInc#5667)
  Changeset version bump (RooCodeInc#5670)
  chore: add changeset for v3.23.8 patch release (RooCodeInc#5669)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Claude Code not working on Windows OS ?
5 participants