Skip to content

setting_sources=[] silently ignored due to truthiness check in _build_command #794

@joshwilhelmi

Description

@joshwilhelmi

Bug Description

In subprocess_cli.py, the _build_command method uses a truthiness check for setting_sources:

if self._options.setting_sources:  # line 283
    cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)])

Since [] is falsy in Python, passing setting_sources=[] never sends --setting-sources to the CLI subprocess. The intent of setting_sources=[] is "load no setting sources", but it silently does nothing — the CLI falls back to loading all default sources.

Expected Behavior

setting_sources=[] should pass --setting-sources "" to the CLI, disabling all setting sources.

Comparison with tools handling

This is the same class of bug as #634 (allowed_tools=[]), which was fixed. The tools field correctly uses an is not None check:

if self._options.tools is not None:  # Correct: distinguishes None from []
    tools = self._options.tools
    if isinstance(tools, list):
        if len(tools) == 0:
            cmd.extend(["--tools", ""])

But setting_sources still uses a truthiness check, making an empty list indistinguishable from "not set".

Suggested Fix

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)])

Workaround

Pass setting_sources=[""] (a list containing an empty string) to force the flag through the truthiness check. This produces --setting-sources "" which the CLI interprets as no sources.

Versions

  • claude-agent-sdk 0.1.45
  • Python 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions