Skip to content

Conversation

bniladridas
Copy link

Summary

The SDK was always adding the --setting-sources flag to the Claude Code CLI command, even when setting_sources was None 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:

error: unknown option '--setting-sources'
Fatal error in message reader: Command failed with exit code 1

Solution

Modified the code to conditionally add the --setting-sources flag only when setting_sources actually has values:

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

Changes

  • File: src/claude_agent_sdk/_internal/transport/subprocess_cli.py
  • Lines: 174-176 (3 insertions, 6 deletions)
  • Logic: Flag only added when setting_sources is truthy

Testing

  • ✅ All 110 tests pass
  • ✅ Linting, formatting, and type checking pass
  • ✅ Verified compatibility with Python 3.10+
  • ✅ No breaking changes to existing functionality

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.

The SDK was always adding the --setting-sources flag even when setting_sources
was None or empty, causing compatibility issues with newer Claude Code CLI
versions that don't recognize this flag.

This change makes the flag conditional - it's only added when setting_sources
actually has values to specify.

Fixes anthropics#186
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.

1 participant