Skip to content

Fix: omit --setting-sources flag when setting_sources is empty or unset#778

Merged
qing-ant merged 1 commit intomainfrom
fix/empty-setting-sources-cli-flag
Mar 30, 2026
Merged

Fix: omit --setting-sources flag when setting_sources is empty or unset#778
qing-ant merged 1 commit intomainfrom
fix/empty-setting-sources-cli-flag

Conversation

@qing-ant
Copy link
Copy Markdown
Contributor

@qing-ant qing-ant commented Mar 30, 2026

Summary

When setting_sources was not provided (None) or was an empty list, the SDK always passed --setting-sources "" to the CLI. The empty string argument causes the CLI argument parser to consume the next flag (e.g. --permission-mode) as the --setting-sources value, producing:

Error processing --setting-sources: Invalid setting source: --permission-mode.
Valid options are: user, project, local

This blocked all default SDK usage without an explicit setting_sources workaround.

Fix

Only add --setting-sources when setting_sources is a non-empty list, matching the pattern used by other array-typed flags (allowed_tools, disallowed_tools, betas).

Before:

sources_value = (
    ",".join(self._options.setting_sources)
    if self._options.setting_sources is not None
    else ""
)
cmd.extend(["--setting-sources", sources_value])  # always emitted

After:

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

Testing

  • Added 3 unit tests verifying the fix:
    • test_build_command_setting_sources_omitted_when_not_provided — no setting_sources → no --setting-sources flag
    • test_build_command_setting_sources_omitted_when_empty — empty [] → no --setting-sources flag
    • test_build_command_setting_sources_included_when_provided["user", "project"]--setting-sources user,project
  • All 427 existing tests pass
  • Lint clean

Fixes anthropics/claude-agent-sdk-typescript#252

@qing-ant qing-ant enabled auto-merge (squash) March 30, 2026 18:42
@qing-ant qing-ant force-pushed the fix/empty-setting-sources-cli-flag branch 2 times, most recently from b32e173 to 7bdaba0 Compare March 30, 2026 18:49
@qing-ant qing-ant force-pushed the fix/empty-setting-sources-cli-flag branch from 384c747 to d5ad8ca Compare March 30, 2026 19:22
@qing-ant qing-ant merged commit ab9bcab into main Mar 30, 2026
10 checks passed
@qing-ant qing-ant deleted the fix/empty-setting-sources-cli-flag branch March 30, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Empty settingSources array causes --setting-sources "" to consume next CLI flag

2 participants