-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: handle PowerShell scripts (.ps1) on Windows for Claude Code integration #7395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…gration - Detect .ps1 files on Windows and execute them through PowerShell - Add proper PowerShell invocation with bypass execution policy - Improve error messages for PowerShell-specific failures - Add comprehensive tests for PowerShell script handling Fixes #7393
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code because apparently I trust no one, not even myself.
| // Check if this is a PowerShell script error on Windows | ||
| const isWindows = os.platform() === "win32" | ||
| const isPowerShellScript = isWindows && claudePath.toLowerCase().endsWith(".ps1") | ||
| if (isPowerShellScript && error.message?.includes("powershell.exe")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice there's duplicate logic here and in lines 75-82 for detecting PowerShell script errors. Could we extract this into a helper function like isPowerShellNotFoundError() to avoid repetition?
| if (isPowerShellScript) { | ||
| // For PowerShell scripts on Windows, execute through PowerShell | ||
| executablePath = "powershell.exe" | ||
| args = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", claudePath, "-p"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentional that we're passing the script path directly to PowerShell without any validation? While execa should handle most escaping, could we add a quick check to ensure the path doesn't contain potentially dangerous characters like semicolons or backticks that might be interpreted by PowerShell?
| const options = { | ||
| systemPrompt: "You are a helpful assistant", | ||
| messages: [{ role: "user" as const, content: "Hello" }], | ||
| path: "C:\\Program Files\\Claude\\claude.PS1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Would it be worth adding a test case for PowerShell scripts with spaces in the path? This is common on Windows (e.g., "C:\Program Files..."). I see we test uppercase .PS1 but not paths with spaces.
|
|
||
| if (isPowerShellScript) { | ||
| // For PowerShell scripts on Windows, execute through PowerShell | ||
| executablePath = "powershell.exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell Core (pwsh.exe) is becoming more common on Windows. Should we consider trying pwsh.exe as a fallback if powershell.exe is not found? This could improve compatibility with newer Windows installations.
Summary
This PR fixes an issue where Roo Code fails to execute Claude Code when it's installed as a PowerShell script (.ps1 file) on Windows.
Problem
Users on Windows who install Claude Code through PowerShell (e.g., via fnm or other Node.js version managers) receive a .ps1 script instead of a binary executable. When Roo Code tries to execute this script directly, it fails with an error because PowerShell scripts cannot be executed as regular binaries.
Solution
.ps1on Windowspowershell.exewith appropriate flags:-NoProfile: Skip loading PowerShell profiles for security-ExecutionPolicy Bypass: Allow script execution for this specific invocation only-File: Specify the script file to executeTesting
Security Considerations
-NoProfileto prevent loading potentially malicious PowerShell profiles-ExecutionPolicy Bypassis scoped only to the specific script executionFixes #7393
Important
Fixes execution of PowerShell scripts on Windows for Claude Code by using
powershell.exewith specific flags and adds comprehensive tests..ps1scripts on Windows and executes them viapowershell.exewith-NoProfile,-ExecutionPolicy Bypass, and-Fileflags inrun.ts..ps1executables.run-powershell.spec.tswith 10 test cases for PowerShell script execution, error handling, and parameter passing..ps1and non-.ps1files on Windows and other platforms.-NoProfileand-ExecutionPolicy Bypassto mitigate security risks.This description was created by
for 3979d90. You can customize this summary. It will automatically update as commits are pushed.