Skip to content

[Windows] OSError WinError 193 - SDK fails to detect claude.cmd on Windows #252

@Xyntexx

Description

@Xyntexx

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:

  1. claude - A POSIX shell script (for Unix/Git Bash)
  2. 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:

  1. Use claude.cmd on Windows (sys.platform == "win32")
  2. Use claude on other platforms
  3. Update fallback location paths to include the .cmd extension on Windows
  4. 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

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions