Skip to content

Commit 3a2181c

Browse files
fix(shell): default to PowerShell on Windows when no terminal profile is set (#82)
getShell() fell through to COMSPEC (cmd.exe) when VS Code had no explicit Windows terminal profile, so the system prompt advertised cmd.exe even though the integrated terminal actually launches PowerShell (VS Code's modern default). Return Windows PowerShell from getWindowsShellFromVSCode() in that case so the prompt and rules match the real shell. Explicitly configured cmd/WSL/custom profiles are unaffected. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3bd1a80 commit 3a2181c

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/utils/__tests__/shell.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,27 @@ describe("Shell Detection Tests", () => {
173173
expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe")
174174
})
175175

176-
it("respects userInfo() if no VS Code config is available and shell is allowed", () => {
176+
it("defaults to Windows PowerShell when VS Code has no configured profile", () => {
177+
// Modern VS Code launches PowerShell by default on Windows (issue #82), so
178+
// getShell() should report PowerShell rather than falling through to cmd.exe.
177179
vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any
178180
vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } as any)
179181

180-
expect(getShell()).toBe("C:\\Program Files\\PowerShell\\7\\pwsh.exe")
182+
expect(getShell()).toBe("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe")
181183
})
182184

183-
it("falls back to safe shell when userInfo() returns non-allowlisted shell", () => {
184-
vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any
185-
vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Custom\\PowerShell.exe" } as any)
185+
it("falls back to safe shell when the configured profile path is non-allowlisted", () => {
186+
mockVsCodeConfig("windows", "Custom", {
187+
Custom: { path: "C:\\Custom\\evil.exe" },
188+
})
186189

187190
expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe")
188191
})
189192

190-
it("falls back to safe shell when COMSPEC is non-allowlisted", () => {
191-
vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any
192-
process.env.COMSPEC = "D:\\CustomCmd\\cmd.exe"
193+
it("uses cmd.exe when a Command Prompt profile is explicitly configured", () => {
194+
mockVsCodeConfig("windows", "Command Prompt", {
195+
"Command Prompt": { path: "C:\\Windows\\System32\\cmd.exe" },
196+
})
193197

194198
expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe")
195199
})

src/utils/shell.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ function normalizeShellPath(path: string | string[] | undefined): string | null
188188
function getWindowsShellFromVSCode(): string | null {
189189
const { defaultProfileName, profiles } = getWindowsTerminalConfig()
190190
if (!defaultProfileName) {
191-
return null
191+
// No explicit Windows terminal profile is configured. VS Code's built-in
192+
// default on modern Windows is PowerShell (not cmd.exe), and that is the
193+
// shell the integrated terminal actually launches. Mirror it here so the
194+
// system prompt advertises the real shell instead of falling through to
195+
// COMSPEC (cmd.exe). Windows PowerShell is always present, so it is a safe
196+
// allowlisted default. See issue #82.
197+
return SHELL_PATHS.POWERSHELL_LEGACY
192198
}
193199

194200
const profile = profiles[defaultProfileName]

0 commit comments

Comments
 (0)