Skip to content

Conversation

@Xyntexx
Copy link

@Xyntexx Xyntexx commented Oct 14, 2025

Fixes #252

Summary

Fixes the issue where the SDK fails to start on Windows with OSError: [WinError 193] %1 is not a valid Win32 application.

Problem

On Windows, npm creates both claude (bash script) and claude.cmd (batch file). The SDK was using shutil.which("claude"), which returns the bash script that cannot be executed as a Win32 application on Windows.

Changes

  • Modified _find_cli() in subprocess_cli.py to use claude.cmd on Windows instead of claude
  • Updated fallback locations to include .cmd extension on Windows platforms
  • Added common Windows npm installation path (AppData/Roaming/npm)

Testing

  • ✅ Tested on Windows 11 with Python 3.12 and claude-agent-sdk 0.1.3
  • ✅ SDK successfully initializes and executes queries after the fix
  • ✅ No impact on Linux/macOS behavior (continues to use claude)

Implementation Details

The fix detects the platform using sys.platform == "win32" and conditionally:

  • Searches for claude.cmd on Windows, claude elsewhere
  • Uses platform-specific fallback paths

Co-Authored-By: Claude [email protected]

On Windows, npm creates both 'claude' (a bash script) and 'claude.cmd' (a batch file).
The SDK was using shutil.which('claude'), which returns the bash script that cannot be
executed as a Win32 application, causing OSError: [WinError 193] %1 is not a valid Win32 application.

This fix:
- Uses 'claude.cmd' on Windows and 'claude' on other platforms
- Updates fallback location paths to include .cmd extension on Windows
- Adds common Windows npm installation path (AppData/Roaming/npm)

Tested on Windows 11 with Python 3.12 and claude-agent-sdk 0.1.3

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants