-
Notifications
You must be signed in to change notification settings - Fork 613
Closed
Description
Bug Report: Haiku model fails with exit code 1 through SDK while working via CLI
Summary
The claude-haiku-4-5-20241022 model consistently fails with "Command failed with exit code 1" when invoked through the Claude Agent SDK, while the same model works correctly when invoked directly via the bundled CLI.
Environment
- claude-agent-sdk version: 0.1.21
- Bundled CLI version: 2.1.15
- Python version: 3.10
- Platform: Linux (WSL2)
- OS: Ubuntu on Windows 11
Steps to Reproduce
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def test_haiku():
options = ClaudeAgentOptions(
model="claude-haiku-4-5-20241022",
max_turns=1,
allowed_tools=["Read", "Grep", "Glob"],
permission_mode="acceptEdits",
)
async for message in query(prompt="Reply with: hello", options=options):
print(message)
asyncio.run(test_haiku())Expected Behavior
The query should succeed and return a response from Haiku.
Actual Behavior
The SDK throws an exception after ~5 seconds:
[claude_agent_sdk._internal.query] ERROR: Fatal error in message reader: Command failed with exit code 1 (exit code: 1)
Error output: Check stderr output for details
Verification that CLI Works
The same query works when run directly via the bundled CLI:
/path/to/venv/lib/python3.10/site-packages/claude_agent_sdk/_bundled/claude \
--print -- "Reply with: hello" \
--max-turns 1 \
--model claude-haiku-4-5-20241022 \
--output-format stream-json
# Output: "Hello! How can I help you today?"
# Exit code: 0Model Comparison
| Model | Via CLI | Via SDK |
|---|---|---|
| claude-opus-4-5-20251101 | ✅ Works | ✅ Works |
| claude-sonnet-4-20250514 | ✅ Works | ✅ Works |
| claude-haiku-4-5-20241022 | ✅ Works | ❌ Fails |
Additional Context
- Failure is consistent: Every invocation of Haiku through the SDK fails
- Failure timing: Always fails in ~4.5-5.5 seconds
- No actual stderr captured: The error message "Check stderr output for details" is hard-coded in
subprocess_cli.py:626and doesn't reflect actual stderr content - Retry doesn't help: Multiple retries with delays all fail identically
Related Code
The error originates from subprocess_cli.py:
# Line 622-628
if returncode is not None and returncode != 0:
self._exit_error = ProcessError(
f"Command failed with exit code {returncode}",
exit_code=returncode,
stderr="Check stderr output for details", # Hard-coded, not actual stderr
)
raise self._exit_errorSuggestions
- Capture actual stderr: Instead of hard-coding the stderr message, pass the actual captured stderr output to the ProcessError
- Investigate Haiku-specific handling: There may be something in the SDK's command building or subprocess handling that's incompatible with Haiku
Workaround
Use claude-sonnet-4-20250514 instead of Haiku for SDK invocations.
Impact
This blocks using Haiku for cost-optimized workflows where simpler tasks could use a cheaper model. Our multi-agent consensus system had to switch evaluator agents from Haiku to Sonnet, increasing API costs by ~3x for those calls.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels