fix: conditionally add --setting-sources flag for CLI compatibility #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The SDK was always adding the
--setting-sources
flag to the Claude Code CLI command, even whensetting_sources
wasNone
or empty. This caused compatibility issues with newer versions of the Claude Code CLI that don't recognize this flag, resulting in execution failures.Problem
In
src/claude_agent_sdk/_internal/transport/subprocess_cli.py
, the_build_command
method always included:cmd.extend(["--setting-sources", sources_value])
This caused errors like:
Solution
Modified the code to conditionally add the
--setting-sources
flag only whensetting_sources
actually has values:Changes
src/claude_agent_sdk/_internal/transport/subprocess_cli.py
setting_sources
is truthyTesting
Impact
This fix resolves compatibility issues with newer Claude Code CLI versions while maintaining backward compatibility for users who specify setting sources.
Fixes compatibility issue with Claude Code CLI versions that don't support the
--setting-sources
flag.