Skip to content

fix(inference): keep Claude CLI prompts out of Windows argv - #5103

Merged
senamakel merged 2 commits into
tinyhumansai:mainfrom
samrusani:codex/5044-windows-claude-argv
Jul 22, 2026
Merged

senamakel merged 2 commits into
tinyhumansai:mainfrom
samrusani:codex/5044-windows-claude-argv

Conversation

@samrusani

@samrusani samrusani commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Keep Claude Code harness prompts out of Windows argv by using --append-system-prompt-file in the existing per-turn scratch directory.
  • Pipe Claude Agent SDK requests through stdin in non-interactive mode instead of passing the full request as a positional argument.
  • Preserve and log the underlying OS spawn error, with regression coverage for >32 KB prompts, stdin EOF delivery, and missing executables.

Problem

Both Claude CLI providers place the harness prompt in argv. Windows flattens argv into a command line capped at 32,767 UTF-16 code units, so sufficiently large harness prompts fail in CreateProcess before Claude starts. The Agent SDK path also returned only the outer anyhow context, hiding the useful OS error from the journal log.

Solution

The Claude Code driver writes a non-empty appended system prompt into its private per-turn temp directory and passes the path through Claude's supported --append-system-prompt-file flag. The temp directory remains alive for the turn and is cleaned up automatically.

The Agent SDK provider keeps its existing composed [SYSTEM] request format but sends those bytes through piped stdin. It explicitly closes and drops stdin so Claude receives EOF before output is read. Spawn failures are logged with the source io::Error, and the returned message includes that source while retaining the anyhow chain.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage >= 80% - verified by the passing Rust Core Coverage (cargo-llvm-cov) and PR CI Gate checks on commit 863ecda5dd78d15fea40499b1745f7eb0e755951.
  • Coverage matrix updated - N/A: behavior-only provider transport fix; no feature row added, removed, or renamed.
  • All affected feature IDs from the matrix are listed in the PR description under ## Related - N/A: no coverage-matrix feature ID applies.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • Manual smoke checklist updated if this touches release-cut surfaces - N/A: no release-cut surface changed.
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

Windows desktop users can spawn both Claude CLI providers with harness prompts larger than the platform command-line limit. macOS and Linux use the same bounded-argv transports. Prompt contents remain transient and are not logged; Claude Code's file lives only in the existing per-turn private temp directory.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

Commit & Branch

  • Branch: codex/5044-windows-claude-argv
  • Commit SHA: 863ecda5dd78d15fea40499b1745f7eb0e755951

Validation Run

  • pnpm --filter openhuman-app format:check (pre-push hook)
  • pnpm typecheck (pre-push hook)
  • Focused tests: Agent SDK subprocess tests, 7 passed; Claude Code driver tests, 9 passed
  • Rust fmt/check (if changed): cargo fmt --all -- --check; cargo check --lib; cargo clippy -p openhuman -- -D warnings
  • Tauri fmt/check (if changed): N/A - no Tauri Rust files changed

Focused Cargo commands were run with temporary patch overrides pointing to the exact gitlink revisions tinycortex@9a0603a and tinyflows@e5327de, because this local working tree retained newer submodule checkouts from earlier work.

Validation Blocked

  • N/A: local cargo-llvm-cov is unavailable, but the authoritative Rust Core Coverage (cargo-llvm-cov) and aggregate PR CI Gate checks passed on the current commit.

Behavior Changes

  • Intended behavior change: deliver large Claude prompts outside argv and include the OS source in Agent SDK spawn failures
  • User-visible effect: Claude CLI turns no longer fail at Windows' 32,767-character process creation limit

Parity Contract

  • Legacy behavior preserved: system and user message composition, model/output/budget flags, NDJSON parsing, and Claude Code scratch-directory cleanup
  • Guard/fallback/dispatch parity checks: empty system prompts add no file flag; plain messages and budget flags are preserved; missing binaries retain the source error

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None found in the final live search
  • Canonical PR: This PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved Claude integration by sending full requests (including optional system prompts) via standard input rather than command-line arguments, avoiding argument-length limits.
    • Updated Claude Code turn handling to store non-empty system prompts in a per-turn file and pass a reference, not the raw prompt in argv.
    • Improved error reporting when the Claude process fails to start.
    • Whitespace-only system prompts are now ignored.
  • Tests
    • Added coverage for stdin-based delivery, prompt-file behavior, argument/budget propagation, and spawn/piping error handling.

@samrusani
samrusani requested a review from a team July 21, 2026 20:48
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Both Claude providers now avoid command-line size limits by delivering system prompts through subprocess stdin or per-turn files. Invocation construction, budget flags, spawn error context, and regression tests were updated.

Changes

Claude prompt transport

Layer / File(s) Summary
SDK stdin request transport
src/openhuman/inference/provider/claude_agent_sdk/subprocess.rs
Requests are assembled with optional system wrappers and budget flags, written through piped stdin, and tested with large prompts and preserved spawn errors.
Claude Code prompt file transport
src/openhuman/inference/provider/claude_code/driver.rs
Nonblank system prompts are written to per-turn scratch files and passed using --append-system-prompt-file; blank prompts add no arguments, with write failures propagated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant chat_with_system
  participant build_invocation
  participant claude_cli
  chat_with_system->>build_invocation: construct args and stdin payload
  build_invocation-->>chat_with_system: return invocation
  chat_with_system->>claude_cli: spawn with piped stdin
  chat_with_system->>claude_cli: write request and shut down stdin
  claude_cli-->>chat_with_system: return CLI output
Loading

Poem

A rabbit packed prompts in a stdin-bound stream,
While scratch files kept argv trim and clean.
Big messages hopped past limits with cheer,
Spawn errors kept their sources near.
“Nibble on tests—this fix is serene!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR routes large prompts out of argv via stdin/files, adds regression tests, and preserves spawn errors as requested.
Out of Scope Changes check ✅ Passed The changes stay focused on Claude CLI prompt delivery and spawn-error handling; no unrelated code appears introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: moving Claude CLI prompts out of Windows argv to avoid command-line limits.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openhuman/inference/provider/claude_code/driver.rs`:
- Around line 189-207: Update append_system_prompt_args and its call site to add
grep-friendly diagnostics for the prompt-file flow: log when a non-empty prompt
enters the file-write branch, log successful file creation, and log the write
error with the target path before propagating it. Do not log the prompt contents
or other sensitive data, and preserve the existing empty-prompt behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2abf3b90-1322-43fd-879e-2218da2e4d9a

📥 Commits

Reviewing files that changed from the base of the PR and between 40852cd and bee053c.

📒 Files selected for processing (2)
  • src/openhuman/inference/provider/claude_agent_sdk/subprocess.rs
  • src/openhuman/inference/provider/claude_code/driver.rs

@senamakel
senamakel merged commit 31fca02 into tinyhumansai:main Jul 22, 2026
28 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants