File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/claude_agent_sdk/_internal/transport Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,28 @@ def _build_command(self) -> list[str]:
335335
336336 # Check if command line is too long (Windows limitation)
337337 cmd_str = " " .join (cmd )
338+ if len (cmd_str ) > _CMD_LENGTH_LIMIT and "--system-prompt" in cmd :
339+ # Handle large --system-prompt by switching to --system-prompt-file
340+ try :
341+ sp_idx = cmd .index ("--system-prompt" )
342+ sp_value = cmd [sp_idx + 1 ]
343+ if len (sp_value ) > _CMD_LENGTH_LIMIT // 2 :
344+ temp_file = tempfile .NamedTemporaryFile (
345+ mode = "w" , suffix = ".txt" , delete = False , encoding = "utf-8"
346+ )
347+ temp_file .write (sp_value )
348+ temp_file .close ()
349+ self ._temp_files .append (temp_file .name )
350+ # Replace --system-prompt with --system-prompt-file
351+ cmd [sp_idx ] = "--system-prompt-file"
352+ cmd [sp_idx + 1 ] = temp_file .name
353+ logger .info (
354+ f"System prompt length ({ len (sp_value )} ) exceeds limit. "
355+ f"Using --system-prompt-file: { temp_file .name } "
356+ )
357+ except (ValueError , IndexError ) as e :
358+ logger .warning (f"Failed to optimize system prompt length: { e } " )
359+
338360 if len (cmd_str ) > _CMD_LENGTH_LIMIT and self ._options .agents :
339361 # Command is too long - use temp file for agents
340362 # Find the --agents argument and replace its value with @filepath
You can’t perform that action at this time.
0 commit comments