Repository navigation
fix(transport): say which prompt is too long when the OS refuses to start the CLI - #1581
Open
ofri-peretz wants to merge 1 commit into
Open
ofri-peretz wants to merge 1 commit into
ofri-peretz wants to merge 1 commit into
Conversation
…tart the CLI
A system_prompt string (or custom prompt, or preset append text) is
passed to the CLI as one argument. Linux caps one argument at 131072
bytes (E2BIG) and Windows caps the whole command line at 32,767
characters (WinError 206), so a long prompt fails before the CLI starts.
The error named only the CLI path, and on Windows it became
CLINotFoundError ("Claude Code not found").
When the OS refuses with either error and the longest argument is an
inline prompt, raise CLIConnectionError naming system_prompt, its size,
the limits, and the {"type": "file", "path": ...} form. Document the
file form and the limit on ClaudeAgentOptions.system_prompt.
Fixes anthropics#1096
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
system_promptstring is passed to the CLI as one command-line argument. When it is too long, the OS refuses to start the CLI and the caller gets an error that names only the CLI path (#1096):CLIConnectionError: Failed to start Claude Code: [Errno 7] Argument list too long, at 131,072 bytes (MAX_ARG_STRLEN).CLINotFoundError: Claude Code not found at ..., which is wrong.CreateProcesscaps the whole command line at 32,767 characters and raises WinError 206, which is aFileNotFoundError. That case was reported in the issue comments.The fix is option (1) + (3) from the issue.
What changes:
E2BIGor WinError 206 and the longest argument is an inline prompt (--system-promptor--append-system-prompt),connect()raisesCLIConnectionError. The error namessystem_prompt(or itsappendtext), the size in bytes, both platform limits, andsystem_prompt={"type": "file", "path": ...}, and keeps the OS error at the end.ClaudeAgentOptions.system_promptdocstring now lists thefileform and the command-line limit.What does not:
E2BIGwhere something else is the long argument, gives exactly the error it gave before.Tests (
tests/test_transport.py, withanyio.open_processpatched to raise):strprompt withE2BIGnamessystem_prompt, the size and the file form.CLIConnectionError, notCLINotFoundError.appendtext that is too long gets the hint.E2BIGwith a short prompt keeps the generic message.The first three fail on
mainand all four pass with this change. Locally:pytest tests/(1,759 passed),ruff check,ruff format --check,mypy src/ scripts/.#1097 makes a similar pre-spawn check, but it has had conflicts with
mainsince July and no review. #1101 and #1104 spill to a temp file instead.Fixes #1096
🤖 Generated with Claude Code