Claude Agent SDK: 80+ second startup time on Windows

Status Fixed / completed
Maintainer reply None cached
Activity 6 comments · opened Jan 1, 2026 · closed Feb 23, 2026

Environment

  • claude-agent-sdk version: 0.1.18
  • Python: 3.11.13
  • Platform: Windows 10/11 (win32)
  • Claude CLI: Bundled with SDK

Problem

The Claude Agent SDK takes ~80 seconds to produce the first message when using the query() function. This makes the SDK nearly unusable for interactive applications.

Reproduction

Minimal test script:

import asyncio
import time
from claude_agent_sdk import query, ClaudeAgentOptions

async def test():
    options = ClaudeAgentOptions(
        mcp_servers={},
        allowed_tools=["Read"],
        cwd=".",
        model="claude-sonnet-4-5-20250929",
        permission_mode="bypassPermissions",
        max_turns=1,
    )
    
    t0 = time.perf_counter()
    async for message in query(prompt="Say 'Hello'", options=options):
        t1 = time.perf_counter()
        print(f"First message at {t1 - t0:.1f}s: {type(message).__name__}")
        break

asyncio.run(test())

Actual Results

======================================================================
  SDK INITIALIZATION TIMING REPORT
  Generated: 2026-01-01T23:06:17.242568
======================================================================

  ENVIRONMENT:
    - claude-agent-sdk: 0.1.18
    - Python: 3.11.13
    - Platform: win32

======================================================================
  TEST 1: query() function (non-interactive)
======================================================================
[0.000s] Starting query()...
[79.511s] First message received: SystemMessage
[83.164s] Message #2: AssistantMessage
          Text: Hello World - SDK test successful!...
[83.215s] Message #3: ResultMessage

  RESPONSE: Hello World - SDK test successful!
  RESULT: Total=84.699s, FirstMsg=79.511s, MsgCount=3

79.5 seconds to first message for a simple "say hello" query.

Expected Results

First message should arrive within 5-10 seconds maximum.

Additional Context

  • This is a clean test without any MCP servers or complex tool configurations
  • The delay appears to be in CLI subprocess startup, not API latency
  • Using ClaudeSDKClient directly shows __aenter__() completes in ~11 seconds, but the scope handling has issues
  • We are building a production application on top of the SDK and this startup time makes it unusable

Questions

  1. Is this expected behavior on Windows?
  2. Are there any configuration options to reduce startup time?
  3. Is there a way to keep a "warm" CLI subprocess that can be reused across queries?

Thank you!

View original on GitHub ↗

6 Comments

github-actions[bot] · 9 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/4615

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

sarukas · 9 months ago
Found 1 possible duplicate issue: 1. [[BUG] Claude SDK: Critical 65+ second delay on first query execution in Node.js/TypeScript environments #4615](https://github.com/anthropics/claude-code/issues/4615) This issue will be automatically closed as a duplicate in 3 days. If your issue is a duplicate, please close it and 👍 the existing issue instead To prevent auto-closure, add a comment or 👎 this comment 🤖 Generated with Claude Code

The other issue is similar, but on MacOS and quite old. Mine is new and shuold be reproducible on windows. This does not occur in Claude Code, just via SDK.

sarukas · 9 months ago

Update: Found SDK timeout configuration

After further investigation, I found the root cause of why pre-initialization doesn't help:

The SDK has an internal 60-second default timeout that fires before our wrapper timeout:

# From claude_agent_sdk/client.py
initialize_timeout_ms = int(
    os.environ.get("CLAUDE_CODE_STREAM_CLOSE_TIMEOUT", "60000")  # Default: 60s
)
initialize_timeout = max(initialize_timeout_ms / 1000.0, 60.0)

Since Windows SDK initialization takes ~80+ seconds, the default 60s timeout causes Control request timeout: initialize errors.

Workaround

Set the environment variable before SDK initialization:

os.environ["CLAUDE_CODE_STREAM_CLOSE_TIMEOUT"] = "180000"  # 180 seconds in ms

Request

Could the SDK either:

  1. Increase the default timeout to accommodate Windows (e.g., 180s default)
  2. Expose this as a ClaudeAgentOptions parameter for easier configuration
  3. Document this env var in the SDK documentation

The current 60s default makes the SDK essentially unusable on Windows without this workaround.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

sarukas · 7 months ago

This issue has dissapeared somewhere along way with the SDK version updates. This can now be closed. Thanks!

github-actions[bot] · 7 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.