-
Notifications
You must be signed in to change notification settings - Fork 503
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
The Claude Agent SDK fails to initialize on Windows with the error:
OSError: [WinError 193] %1 is not a valid Win32 application
This occurs when the SDK attempts to spawn the Claude Code CLI subprocess.
Environment
- OS: Windows 11
- Python: 3.12
- claude-agent-sdk: 0.1.3
- Claude Code CLI: Installed via npm globally
Root Cause
On Windows, npm creates two files when installing the @anthropic-ai/claude-code package:
claude- A POSIX shell script (for Unix/Git Bash)claude.cmd- A Windows batch file
The SDK's _find_cli() method in subprocess_cli.py:62 uses shutil.which("claude"), which returns the path to the bash script. When Python tries to execute this bash script as a subprocess on Windows, it fails because Windows cannot execute shell scripts as Win32 applications.
Steps to Reproduce
import anyio
from claude_agent_sdk import query
async def main():
async for message in query(prompt="What is 2 + 2?"):
print(message)
anyio.run(main)Result:
claude_agent_sdk._errors.CLIConnectionError: Failed to start Claude Code: [WinError 193] %1 is not a valid Win32 application
Expected Behavior
The SDK should successfully detect and use the claude.cmd batch file on Windows, allowing the subprocess to start correctly.
Proposed Solution
Modify the _find_cli() method to:
- Use
claude.cmdon Windows (sys.platform == "win32") - Use
claudeon other platforms - Update fallback location paths to include the
.cmdextension on Windows - Add common Windows npm installation path (
AppData/Roaming/npm)
Additional Context
- The issue is Windows-specific and does not affect Linux/macOS
- Workaround: Users can manually specify the CLI path via
ClaudeAgentOptions(cli_path='C:\path\to\claude.cmd') - Similar issues have been reported in other Python projects that spawn npm-installed CLI tools on Windows
Co-Authored-By: Claude [email protected]
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working