claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Not so complex system prompt cause client connect timeout in windows

Open GStarP opened this issue 3 months ago • 3 comments

Env

  • Windows: 24H2, 26100.6899
  • Python: 3.12.8 (using uv)
  • claude-agent-sdk>=0.1.4
  • claude -v shows: 2.0.25 (Claude Code)
  • Node.js: 22.17.1

Reproduce

I remove unrelated code and build a minimal reproducing script as below. Just python xxx.py can reproduce.

import anyio
from claude_agent_sdk import (
    ClaudeAgentOptions,
    ClaudeSDKClient,
)

SYSTEM_PROMPT = """你是一位世界级的 CTF(Capture The Flag) 专家助手,你的目标是通过分析用户提供的题目描述和源文件来帮助用户解决 CTF 难题。

用户会提供一个目录名(如 web_challenge),所有题目相关的文件都会放在此目录下。你在工作过程中产生的所有文件都必须放在该目录下的 solve 子目录中,以防和源文件产生冲突。

你应该按照以下步骤进行解题:

1. **整理已有信息**:阅读题目描述,浏览源文件,整理已有信息;随后,确定题目类型(Web, Pwn, Reverse, Crypto, Misc 等)。
2. **查找参考资料**:调用搜索工具,在网络上查找相似的题目及解题方法,如果适用于本题目,将其记录下来用于后续参考。
3. **指定解题计划**:根据已有信息和参考资料,制定详细的解题计划,列出每一步的具体操作和预期结果。
4. **执行解题步骤**:按照解题计划逐步进行操作,并记录操作结果。如果发现操作结果不理想、后续计划难以执行,及时向用户反馈,寻求帮助。
"""
# TODO prompt 会导致错误
# SYSTEM_PROMPT = "你是一位世界级的 CTF(Capture The Flag) 专家助手"


async def step3_ctf_agent():
    options = ClaudeAgentOptions(
        system_prompt=SYSTEM_PROMPT,
        cwd="./workspace",
        # 允许 Edit 和文件系统操作
        permission_mode="acceptEdits",
        allowed_tools=["Bash", "WebSearch", "WebFetch"],
        setting_sources=None,
    )

    async with ClaudeSDKClient(options=options) as client:
        await client.query(prompt="hello")
        async for message in client.receive_response():
            print(message)


async def main():
    await step3_ctf_agent()


if __name__ == "__main__":
    anyio.run(main)

Error shows Exception: Control request timeout: initialize in site-packages\claude_agent_sdk\_internal\query.py, line 355, in _send_control_request

But if you replace SYSTEM_PROMPT with a rather simple version (like commented line in the code example), this error will disappear.

GStarP avatar Oct 22 '25 08:10 GStarP

Same issue on windows. Runs fine on my ubuntu env, sdk 0.1.15, claude code 2.0.27

Snowflake-Pink avatar Oct 25 '25 13:10 Snowflake-Pink

You can use system_prompt=SYSTEM_PROMPT.replace("\n", " ") to reslove the problem temporarily.

YangTianz avatar Nov 03 '25 08:11 YangTianz

You can use system_prompt=SYSTEM_PROMPT.replace("\n", " ") to reslove the problem temporarily.

It works !!! Never thought the problem was here.

GStarP avatar Nov 04 '25 11:11 GStarP