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

[BUG] Global Claude Code settings override SDK client configuration

Open tim-watcha opened this issue 6 months ago • 1 comments

Image Image Image

Bug Description

The global Claude Code settings are overriding the configuration options set in the Python SDK client, causing unexpected behavior and significantly higher costs.

Steps to Reproduce

  1. Set up global Claude Code configuration with:
    • Model: Opus
    • MCP servers configured
  2. Create a Python SDK client with specific options:
    • Model: Sonnet (as shown in first image)
    • No MCP servers intended
  3. Execute code using the SDK client

Expected Behavior

The SDK client should use only the configuration options explicitly set in the client initialization, ignoring global Claude Code settings.

Actual Behavior

  • The SDK client inherits MCP servers from global Claude Code settings (visible in second image)
  • Despite setting model to "sonnet" in the SDK client, it actually uses "Opus" from global settings (confirmed by API usage in third image)

Confirmation of the Bug

Further evidence that global settings override SDK settings: After changing the global Claude Code model setting from Opus to Sonnet, the SDK client then started using Sonnet instead of Opus, even though the SDK client code remained unchanged. This definitively proves that the SDK is reading from global Claude Code settings rather than respecting its own configuration.

Impact

This is a critical issue that results in:

  • Unexpected high costs: I was charged ~$100 instead of expected ~$20 due to unintended Opus usage
  • Configuration confusion: SDK settings are silently ignored
  • Unpredictable behavior: The actual model/tools used don't match the configured settings
  • Unreliable cost control: Developers cannot predict which model will be used based on their code

Additional Context

The API key shown in the third image was created specifically for testing this issue. This behavior makes it impossible to reliably control costs and model selection when using the SDK in environments where Claude Code is also installed.

tim-watcha avatar Jun 27 '25 05:06 tim-watcha

Additional Observation

I noticed another issue: As shown in the screenshots, the tools array includes MCP servers from global Claude Code settings. During SDK execution, Claude actually tries to use these MCP tools but fails with "user permission not granted" errors.

tim-watcha avatar Jun 27 '25 06:06 tim-watcha