fix(pty): prefer pwsh.exe over powershell.exe in BuildCmdLine wrapper#68
Open
AThraen wants to merge 1 commit into
Open
fix(pty): prefer pwsh.exe over powershell.exe in BuildCmdLine wrapper#68AThraen wants to merge 1 commit into
AThraen wants to merge 1 commit into
Conversation
Bare commands that aren't in the passthrough list get wrapped in '<shell>.exe -NoExit -Command <cmd>' so the shell can set up the Win32 console environment before launching the target process (Electron/Node SEA apps like claude.exe crash with STATUS_DLL_INIT_FAILED when launched directly inside a ConPTY). Before this change the wrapper was always powershell.exe (Windows PowerShell 5.1). Modern users define profile functions in the PowerShell 7 (pwsh) profile at ~/Documents/PowerShell/, which 5.1 never sees — so commands like 'claudelocal' / 'claudework' failed with "command not recognized" when entered as bare session commands. The wrapper is now resolved once per process: pwsh.exe when present on PATH, falling back to powershell.exe (always present on Windows). Also adds 'nu' (nushell) and 'fish' to the passthrough list so those shells aren't double-wrapped when used directly. BuildCmdLine is bumped from private to internal and gains an overload that accepts the wrapper shell name explicitly, so the behaviour can be unit-tested without depending on whether pwsh.exe happens to be installed on the test runner. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PseudoTerminal.BuildCmdLinenow wraps non-passthrough commands inpwsh.exe -NoExit -Command …when pwsh is on PATH, falling back topowershell.exeotherwise.nu(nushell) andfishto the passthrough shell list so they aren't double-wrapped when used as a session command.PseudoTerminalBuildCmdLineTestscovering the passthrough list, the pwsh wrap, and the powershell.exe fallback.Why
Users who define PowerShell functions in their PowerShell 7 profile (
~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1) couldn't invoke them as bare session commands. Example: a functionclaudelocallets you call Claude Code with a local AI account, but typingclaudelocalin the New Session dialog failed because the wrapper usedpowershell.exe(Windows PowerShell 5.1), which loads a different profile (~/Documents/WindowsPowerShell/…) where the function isn't defined.Preferring
pwsh.exematches where modern users actually put their profile customisations, while keeping a safe fallback for machines where pwsh isn't installed.Test plan
dotnet test tests/CodeShellManager.Tests/— 224 passed, 0 failed (18 new tests inPseudoTerminalBuildCmdLineTests)dotnet build src/CodeShellManager/CodeShellManager.csproj— 0 errorsclaudelocal) as the command on a machine with pwsh installed — function resolves and runs🤖 Generated with Claude Code