Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/claude_agent_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _build_command(self) -> list[str]:
if effective_allowed_tools:
cmd.extend(["--allowedTools", ",".join(effective_allowed_tools)])

if self._options.max_turns:
if self._options.max_turns is not None:
cmd.extend(["--max-turns", str(self._options.max_turns)])

if self._options.max_budget_usd is not None:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ def test_build_command_with_options(self):
assert "--max-turns" in cmd
assert "5" in cmd

def test_build_command_max_turns_zero(self):
"""max_turns=0 is a caller-supplied value and must be forwarded.

None is the "unset" sentinel; 0 is an explicit cap and should reach the
CLI like the other numeric options (max_budget_usd, task_budget,
max_thinking_tokens all forward 0 via ``is not None``).
"""
transport = SubprocessCLITransport(
prompt="test",
options=make_options(max_turns=0),
)

cmd = transport._build_command()
assert "--max-turns" in cmd
assert cmd[cmd.index("--max-turns") + 1] == "0"

# None still means "unset" — no flag emitted.
transport_unset = SubprocessCLITransport(prompt="test", options=make_options())
assert "--max-turns" not in transport_unset._build_command()

def test_build_command_with_dont_ask_permission_mode(self):
"""Test building CLI command with dontAsk permission mode."""
transport = SubprocessCLITransport(
Expand Down