diff --git a/src/main/codex-accounts/runtime-home-service.test.ts b/src/main/codex-accounts/runtime-home-service.test.ts index 36e9ea85a..998f0891a 100644 --- a/src/main/codex-accounts/runtime-home-service.test.ts +++ b/src/main/codex-accounts/runtime-home-service.test.ts @@ -85,6 +85,7 @@ function createSettings(overrides: Partial = {}): GlobalSettings experimentalTerminalDaemon: false, experimentalTerminalDaemonNoticeShown: false, terminalForceHyperlink: true, + terminalWindowsShell: 'powershell.exe', ...overrides } } diff --git a/src/main/codex-accounts/service.test.ts b/src/main/codex-accounts/service.test.ts index b412debf8..bff056a88 100644 --- a/src/main/codex-accounts/service.test.ts +++ b/src/main/codex-accounts/service.test.ts @@ -79,6 +79,7 @@ function createSettings(overrides: Partial = {}): GlobalSettings experimentalTerminalDaemon: false, experimentalTerminalDaemonNoticeShown: false, terminalForceHyperlink: true, + terminalWindowsShell: 'powershell.exe', ...overrides } } diff --git a/src/main/ipc/pty.test.ts b/src/main/ipc/pty.test.ts index b0ccf736b..4f06a6366 100644 --- a/src/main/ipc/pty.test.ts +++ b/src/main/ipc/pty.test.ts @@ -455,6 +455,27 @@ describe('registerPtyHandlers', () => { expect.any(Object) ) }) + + it('uses terminalWindowsShell setting over COMSPEC when provided', () => { + // Why: COMSPEC always points to cmd.exe on stock Windows, so without the + // setting the terminal would ignore the user's shell preference. + process.env.COMSPEC = 'C:\\Windows\\system32\\cmd.exe' + + registerPtyHandlers(mainWindow as never, undefined, undefined, () => ({ + terminalWindowsShell: 'powershell.exe' + } as never)) + handlers.get('pty:spawn')!(null, { cols: 80, rows: 24 }) + + expect(spawnMock).toHaveBeenCalledWith( + 'powershell.exe', + [ + '-NoExit', + '-Command', + 'try { . $PROFILE } catch {}; [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::UTF8' + ], + expect.any(Object) + ) + }) }) it('rejects missing WSL worktree cwd instead of validating only the fallback Windows cwd', async () => { diff --git a/src/main/ipc/pty.ts b/src/main/ipc/pty.ts index 577dd996c..5acab8151 100644 --- a/src/main/ipc/pty.ts +++ b/src/main/ipc/pty.ts @@ -147,6 +147,7 @@ export function registerPtyHandlers( localProvider.configure({ isHistoryEnabled: () => getSettings?.()?.terminalScopeHistoryByWorktree ?? true, isForceHyperlinkEnabled: () => getSettings?.()?.terminalForceHyperlink ?? true, + getWindowsShell: () => getSettings?.()?.terminalWindowsShell, buildSpawnEnv: (id, baseEnv) => { const selectedCodexHomePath = getSelectedCodexHomePath?.() ?? null diff --git a/src/main/providers/local-pty-provider.ts b/src/main/providers/local-pty-provider.ts index 662e2a84d..78129628b 100644 --- a/src/main/providers/local-pty-provider.ts +++ b/src/main/providers/local-pty-provider.ts @@ -98,6 +98,11 @@ export type LocalPtyProviderOptions = { * significant shell-startup slowdown with heavy rc files. When absent, * defaults to the prior behavior (on). */ isForceHyperlinkEnabled?: () => boolean + /** Why: COMSPEC is always cmd.exe on a stock Windows machine, so reading it + * directly would ignore the user's shell preference. This callback lets the + * IPC layer inject the persisted setting without coupling the provider to the + * settings store. Returns undefined when no preference is set. */ + getWindowsShell?: () => string | undefined onSpawned?: (id: string) => void onExit?: (id: string, code: number) => void onData?: (id: string, data: string, timestamp: number) => void @@ -134,7 +139,7 @@ export class LocalPtyProvider implements IPtyProvider { effectiveCwd = getDefaultCwd() validationCwd = cwd } else if (process.platform === 'win32') { - shellPath = process.env.COMSPEC || 'powershell.exe' + shellPath = this.opts.getWindowsShell?.() || process.env.COMSPEC || 'powershell.exe' // Why: use path.win32.basename so backslash-separated Windows paths // are parsed correctly even when tests mock process.platform on Linux CI. const shellBasename = pathWin32.basename(shellPath).toLowerCase() @@ -447,7 +452,7 @@ export class LocalPtyProvider implements IPtyProvider { async getDefaultShell(): Promise { if (process.platform === 'win32') { - return process.env.COMSPEC || 'powershell.exe' + return this.opts.getWindowsShell?.() || process.env.COMSPEC || 'powershell.exe' } return process.env.SHELL || '/bin/zsh' } diff --git a/src/renderer/src/components/settings/TerminalPane.tsx b/src/renderer/src/components/settings/TerminalPane.tsx index 67d2b290f..a086211cc 100644 --- a/src/renderer/src/components/settings/TerminalPane.tsx +++ b/src/renderer/src/components/settings/TerminalPane.tsx @@ -36,7 +36,8 @@ import { TERMINAL_PANE_STYLE_SEARCH_ENTRIES, TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY, TERMINAL_SETUP_SCRIPT_SEARCH_ENTRIES, - TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES + TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES, + TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY } from './terminal-search' import { useDetectedOptionAsAlt } from '@/lib/keyboard-layout/use-effective-mac-option-as-alt' import { detectedCategoryToDefault } from '@/lib/keyboard-layout/detect-option-as-alt' @@ -90,6 +91,49 @@ export function TerminalPane({ scrollbackMode === 'custom' ? 'custom' : isPreset ? `${scrollbackMb}` : 'custom' const visibleSections = [ + isWindows && matchesSettingsSearch(searchQuery, TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY) ? ( +
+ + +
+ {( + [ + { label: 'PowerShell', value: 'powershell.exe' }, + { label: 'Command Prompt', value: 'cmd.exe' } + ] as const + ).map(({ label, value }) => ( + + ))} +
+

+ Shell used when opening a new terminal pane. Takes effect for new terminals. +

+
+
+ ) : null, matchesSettingsSearch(searchQuery, TERMINAL_TYPOGRAPHY_SEARCH_ENTRIES) ? (
diff --git a/src/renderer/src/components/settings/terminal-search.ts b/src/renderer/src/components/settings/terminal-search.ts index 9f02aeb9f..9f8b82671 100644 --- a/src/renderer/src/components/settings/terminal-search.ts +++ b/src/renderer/src/components/settings/terminal-search.ts @@ -175,7 +175,16 @@ export const TERMINAL_SETUP_SCRIPT_SEARCH_ENTRIES: SettingsSearchEntry[] = [ } ] +export const TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY: SettingsSearchEntry[] = [ + { + title: 'Default Shell', + description: 'Choose the default shell for new terminal panes on Windows.', + keywords: ['terminal', 'windows', 'shell', 'powershell', 'cmd', 'command prompt', 'default'] + } +] + export const TERMINAL_WINDOWS_SEARCH_ENTRIES: SettingsSearchEntry[] = [ + ...TERMINAL_WINDOWS_SHELL_SEARCH_ENTRY, { title: 'Right-click to paste', description: @@ -184,7 +193,14 @@ export const TERMINAL_WINDOWS_SEARCH_ENTRIES: SettingsSearchEntry[] = [ } ] -export const TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY = TERMINAL_WINDOWS_SEARCH_ENTRIES +export const TERMINAL_RIGHT_CLICK_TO_PASTE_SEARCH_ENTRY: SettingsSearchEntry[] = [ + { + title: 'Right-click to paste', + description: + 'On Windows, right-click pastes the clipboard into the terminal. Use Ctrl+right-click to open the context menu.', + keywords: ['terminal', 'windows', 'right click', 'paste', 'context menu'] + } +] export function getTerminalPaneSearchEntries(platform: { isWindows: boolean diff --git a/src/shared/constants.ts b/src/shared/constants.ts index fe4615ca2..a147d835c 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -120,6 +120,10 @@ export function getDefaultSettings(homedir: string): GlobalSettings { // box. Other platforms ignore this field because the UI never exposes it, // and Ctrl+right-click still opens the context menu when paste is enabled. terminalRightClickToPaste: true, + // Why: COMSPEC on a stock Windows machine always resolves to cmd.exe, so + // falling back to COMSPEC would silently open CMD instead of PowerShell. + // Defaulting to powershell.exe matches what users expect from a modern IDE. + terminalWindowsShell: 'powershell.exe', // Default false: opt-in only (matches Ghostty's default). Existing users // on upgrade inherit this default via persistence.ts's // { ...defaults.settings, ...parsed.settings } merge, so enabling diff --git a/src/shared/types.ts b/src/shared/types.ts index a7dee579a..1a10c7ba8 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -654,6 +654,11 @@ export type GlobalSettings = { * The setting stays Windows-only so macOS/Linux keep their existing context * menu behavior and users can still reach the menu with Ctrl+right-click. */ terminalRightClickToPaste: boolean + /** Why: COMSPEC always points to cmd.exe on stock Windows, so without an + * explicit setting the terminal would always open CMD instead of the + * user's preferred shell. Defaults to 'powershell.exe' which is the + * modern choice for an IDE context. Only consulted on Windows. */ + terminalWindowsShell: string terminalFocusFollowsMouse: boolean /** Why: mirrors X11 / gnome-terminal "copy on select" UX — making a terminal * selection copies it to the system clipboard automatically, so users can