Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/claude_agent_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,29 @@ def _build_command(self) -> list[str]:
if self._options.system_prompt is None:
cmd.extend(["--system-prompt", ""])
elif isinstance(self._options.system_prompt, str):
cmd.extend(["--system-prompt", self._options.system_prompt])
# Linux/macOS enforce MAX_ARG_STRLEN (32 * PAGE_SIZE) per argv element.
# A huge --system-prompt string fails at execve with "Argument list too long"
# before any API request. Prefer the file form above that threshold.
prompt = self._options.system_prompt
max_arg_strlen = None
if hasattr(os, "sysconf"):
try:
page = os.sysconf("SC_PAGE_SIZE")
if isinstance(page, int) and page > 0:
max_arg_strlen = 32 * page
except (ValueError, OSError, AttributeError):
max_arg_strlen = None
if max_arg_strlen is not None:
size = len(prompt.encode("utf-8"))
if size >= max_arg_strlen:
raise CLIConnectionError(
f"system_prompt is {size} bytes, which meets/exceeds the OS "
f"per-argument limit of {max_arg_strlen} bytes (MAX_ARG_STRLEN). "
"Pass a file instead, e.g. "
'system_prompt={"type": "file", "path": "/path/to/prompt.txt"} '
"(maps to --system-prompt-file)."
)
cmd.extend(["--system-prompt", prompt])
else:
sp = self._options.system_prompt
if sp.get("type") == "file":
Expand Down