Skip to content

Haiku model fails with exit code 1 through SDK while working via CLI #515

@keychaingit

Description

@keychaingit

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: 0

Model 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

  1. Failure is consistent: Every invocation of Haiku through the SDK fails
  2. Failure timing: Always fails in ~4.5-5.5 seconds
  3. No actual stderr captured: The error message "Check stderr output for details" is hard-coded in subprocess_cli.py:626 and doesn't reflect actual stderr content
  4. 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_error

Suggestions

  1. Capture actual stderr: Instead of hard-coding the stderr message, pass the actual captured stderr output to the ProcessError
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions