From 3a7749e64d30195cbe834c81ff8dac5a9190798a Mon Sep 17 00:00:00 2001 From: Osamaali313 Date: Sun, 19 Jul 2026 23:27:45 +0300 Subject: [PATCH] Preserve an explicit max_turns=0 when building the CLI command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_build_command` gates the `--max-turns` flag on a truthy check: if self._options.max_turns: cmd.extend(["--max-turns", str(self._options.max_turns)]) so `max_turns=0` is falsy and silently dropped — the flag is omitted and the CLI falls back to its default turn limit, the opposite of what the caller explicitly requested. Every other numeric option in the same method preserves an explicit 0 by checking `is not None`: `max_budget_usd`, `task_budget`, `max_thinking_tokens`, and `effort`. Use the same `is not None` check for `max_turns` so an explicitly-set value is always forwarded. --- src/claude_agent_sdk/_internal/transport/subprocess_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py index faaec2d5..4911e4d2 100644 --- a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py @@ -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: