Skip to content

setting_sources=[] (empty list) silently ignored — global settings always loaded #802

@RunOrVeith

Description

@RunOrVeith

Summary

ClaudeAgentOptions(setting_sources=[]) has no effect because the SDK checks the list with a truthiness test (if self._options.setting_sources:). An empty list is falsy in Python, so --setting-sources is never passed to the CLI, and the CLI falls back to loading all setting sources (user, project, local).

Affected file

claude_agent_sdk/_internal/transport/subprocess_cli.py, line 283:

if self._options.setting_sources:  # [] is falsy → branch never executes
    cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)])

Expected behavior

setting_sources=[] should pass --setting-sources "" (or equivalent) to the CLI to disable all setting sources, consistent with the type annotation list[SettingSource] | None where None means "use default" and [] means "no sources".

Actual behavior

setting_sources=[] is treated identically to setting_sources=None: the CLI flag is not passed, so all setting sources load (including account-level claude.ai MCP integrations from the user settings).

Workaround

Use a non-empty list that excludes the sources you don't want, e.g. setting_sources=["local"], which is truthy and passes --setting-sources local to the CLI.

Suggested fix

Change the truthiness check to an explicit None check:

if self._options.setting_sources is not None:
    cmd.extend(["--setting-sources", ",".join(self._options.setting_sources)])

This distinguishes None ("use CLI default") from [] ("no sources").

🤖 Generated with Claude Code

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