claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

fix: conditionally add --setting-sources flag for CLI compatibility

Open bniladridas opened this issue 4 months ago • 0 comments

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.

bniladridas avatar Oct 01 '25 16:10 bniladridas