anthropics / anthropics/claude-agent-sdk-python

[BUG] Global Claude Code settings override SDK client configuration

未关闭
#45 4 条评论 4 个 reaction 已指派 1 人 已被 @ltawfik 认领 在 GitHub 查看
bug
主要语言
Python
星标
8.1k
派生
1.3k
平均合并
2 天 31 分钟
30 天内合并 PR
1

描述

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.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。