From 50bfada32205aaea0c51104353980c032ffe2b74 Mon Sep 17 00:00:00 2001 From: Nanook Date: Fri, 10 Apr 2026 17:37:11 +0000 Subject: [PATCH] fix: setting_sources=[] bug (issue #794) Replace truthiness check with explicit is not None check, matching tools handling. When setting_sources is an empty list, pass --setting-sources to disable all setting sources. --- .../_internal/transport/subprocess_cli.py | 7 +++++-- tests/test_transport.py | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py index 4b47f115..bf02cac7 100644 --- a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py @@ -280,8 +280,11 @@ def _build_command(self) -> list[str]: # Agents are always sent via initialize request (matching TypeScript SDK) # No --agents CLI flag needed - if self._options.setting_sources: - cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)]) + if self._options.setting_sources is not None: + if len(self._options.setting_sources) == 0: + cmd.extend(["--setting-sources", ""]) + else: + cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)]) # Add plugin directories if self._options.plugins: diff --git a/tests/test_transport.py b/tests/test_transport.py index b2c40923..6edd19c8 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -436,14 +436,16 @@ def test_build_command_setting_sources_omitted_when_not_provided(self): cmd = transport._build_command() assert "--setting-sources" not in cmd - def test_build_command_setting_sources_omitted_when_empty(self): - """Test that --setting-sources is omitted when setting_sources is empty list.""" + def test_build_command_setting_sources_empty_list_passes_empty_string(self): + """Test that --setting-sources passes empty string when setting_sources is empty list.""" transport = SubprocessCLITransport( prompt="test", options=make_options(setting_sources=[]), ) cmd = transport._build_command() - assert "--setting-sources" not in cmd + assert "--setting-sources" in cmd + idx = cmd.index("--setting-sources") + assert cmd[idx + 1] == "" def test_build_command_setting_sources_included_when_provided(self): """Test that --setting-sources is included when setting_sources has values."""