[BUG] Python SDK: `system_prompt` parameter causes `model` parameter to be ignored
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Description
When using claude-agent-sdk with ClaudeSDKClient, specifying any non-None value for system_prompt causes the model parameter to be ignored, resulting in the SDK defaulting to Claude 3.5 Sonnet instead of using the specified model (e.g., Opus 4.1).
Environment
- claude-agent-sdk version: [latest as of January 2025]
- Python version: 3.13
- Claude CLI installed via npm
- Operating System: Linux
Reproduction Steps
Working Code (Uses Opus 4.1 correctly)
import asyncio
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
async def main():
options = ClaudeAgentOptions(
model="claude-opus-4-1-20250805"
# Note: No system_prompt specified
)
async with ClaudeSDKClient(options=options) as client:
await client.query("What model are you and what version?")
async for msg in client.receive_response():
print(msg)
asyncio.run(main())
Output:
I'm Claude, powered by the Opus 4.1 model. Specifically, my model ID is claude-opus-4-1-20250805
Broken Code (Ignores model, uses Sonnet 3.5)
import asyncio
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
async def main():
options = ClaudeAgentOptions(
model="claude-opus-4-1-20250805",
system_prompt="You are a helpful assistant" # Adding this breaks model selection
)
async with ClaudeSDKClient(options=options) as client:
await client.query("What model are you and what version?")
async for msg in client.receive_response():
print(msg)
asyncio.run(main())
Output:
I'm Claude 3.5 Sonnet, Anthropic's AI assistant, running within the Claude Code CLI interface
Test Matrix
| system_prompt value | Model Used | Result |
|-------------------|------------|---------|
| Not specified | Opus 4.1 | ✅ Works |
| None | Opus 4.1 | ✅ Works |
| "" (empty string) | Sonnet 3.5 | ❌ Bug |
| " " (single space) | API Error | ❌ Error: "text content blocks must contain non-whitespace text" |
| "You are a helpful assistant" | Sonnet 3.5 | ❌ Bug |
Expected Behavior
The model parameter should be respected regardless of whether system_prompt is provided. The SDK should use the specified model (e.g., claude-opus-4-1-20250805) even when a system prompt is included.
Actual Behavior
When any non-None value is provided for system_prompt, the SDK ignores the model parameter and defaults to Claude 3.5 Sonnet.
Workaround
Either:
- Don't include
system_promptin ClaudeAgentOptions when a specific model is required - Explicitly set
system_prompt=None - Include system instructions in the first user message instead
Impact
This bug prevents users from using specific models (like Opus 4.1) with system prompts, which is a common use case for maintaining consistent agent behavior across sessions.
Additional Notes
- The issue appears to be in how the CLI processes the combination of
--modeland--system-promptflags - This affects both streaming mode (
ClaudeSDKClient) and other SDK usage patterns - The bug is consistent and reproducible
Suggested Fix
The SDK should ensure that the model parameter is always passed to the CLI regardless of other parameters, or should throw an error if there's an intentional incompatibility between system_prompt and model selection.
What Should Happen?
Model selection should be respected.
Error Messages/Logs
Steps to Reproduce
See 'what's wrong' section
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.8
Platform
Other
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗