diff --git a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py index 7ec8ebe..9910fd7 100644 --- a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py @@ -212,14 +212,7 @@ class SubprocessCLITransport(Transport): # Flag with value cmd.extend([f"--{flag}", str(value)]) - # Add prompt handling based on mode - if self._is_streaming: - # Streaming mode: use --input-format stream-json - cmd.extend(["--input-format", "stream-json"]) - else: - # String mode: use --print with the prompt - cmd.extend(["--print", "--", str(self._prompt)]) - + # Add options that must come before prompt delimiter if self._options.max_thinking_tokens is not None: cmd.extend( ["--max-thinking-tokens", str(self._options.max_thinking_tokens)] @@ -230,9 +223,22 @@ class SubprocessCLITransport(Transport): ["--first-turn-tool-choice", json.dumps(self._options.first_turn_tool_choice)] ) + if self._options.final_turn_tool_choice is not None: + cmd.extend( + ["--final-turn-tool-choice", json.dumps(self._options.final_turn_tool_choice)] + ) + if self._options.ensure_tool_usage: cmd.append("--ensure-tool-usage") + # Add prompt handling based on mode (must come last for --print mode) + if self._is_streaming: + # Streaming mode: use --input-format stream-json + cmd.extend(["--input-format", "stream-json"]) + else: + # String mode: use --print with the prompt + cmd.extend(["--print", "--", str(self._prompt)]) + # Check if command line is too long (Windows limitation) cmd_str = " ".join(cmd) if len(cmd_str) > _CMD_LENGTH_LIMIT and self._options.agents: diff --git a/src/claude_agent_sdk/types.py b/src/claude_agent_sdk/types.py index 08f285e..2a46042 100644 --- a/src/claude_agent_sdk/types.py +++ b/src/claude_agent_sdk/types.py @@ -562,6 +562,8 @@ class ClaudeAgentOptions: max_thinking_tokens: int | None = None # Tool choice for first turn only first_turn_tool_choice: ToolChoice | None = None + # Tool choice for final turn before ending + final_turn_tool_choice: ToolChoice | None = None # Ensure at least one tool is used before conversation ends ensure_tool_usage: bool = False