Repository navigation
externalTerminal: restore Ctrl+C in Windows external terminals - #350408
Draft
Alexandru Dima (alexdima) wants to merge 1 commit into
Draft
Alexandru Dima (alexdima) wants to merge 1 commit into
Alexandru Dima (alexdima) wants to merge 1 commit into
Conversation
On Windows, `detached: true` starts the child in a new process group, and Windows disables Ctrl+C for every process in that group. Since #201020 the external terminal was spawned that way, so programs started in it ignored Ctrl+C. The terminal still stays open after VS Code exits without it. Fixes #205417 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot stopped reviewing on behalf of
Alexandru Dima (alexdima) due to an error
November 25, 2026 15:59
This branch has not been deployed
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.
Fixes #205417
On Windows, programs started in an external terminal (Open New External Terminal, Ctrl+Shift+C) ignore Ctrl+C, so you can't stop a running
ping -t, Python script or dev server. Ctrl+C at the prompt and Ctrl+Break still work (more details in the duplicate #262468). This regressed in 1.86, and this PR is a one-line fix.Root cause
WindowsExternalTerminalService.spawnTerminalopens the terminal withcmd.exe /c start /wait <terminal>. The .NET debugging Ctrl+C fix (#201020) also made that spawndetached: true:detached: truemakes libuv passDETACHED_PROCESS | CREATE_NEW_PROCESS_GROUPtoCreateProcess(libuv). Node's documentation ofdetacheddoesn't mention this.CREATE_NEW_PROCESS_GROUP, the Win32 documentation says "CTRL+C signals will be disabled for all processes within the new process group", and that the group "includes all processes that are descendants of this root process" (Process Creation Flags).startopens. So the terminal and every program started in it ignore Ctrl+C.Windows Terminal turns Ctrl+C handling back on when it starts (main.cpp), which is why running
wtfrom an affected terminal works around the bug. node-pty does the same for the integrated terminal (conpty.cc).Fix
Spawn the terminal without
detached, as before #201020 (1.85 and earlier). The debugger's external console (runInTerminal) is a separate code path that never useddetached, so the part of #201020 that addressed #81322 (launching throughwt.exe) is unchanged.detachedisn't needed to keep the terminal open. Without it, Node ties only thecmd.exe /c start /waithelper to VS Code's lifetime. libuv's job object lets that helper's children break away, so the terminal thatstartopens stays open when VS Code exits (checked below). Electron creates the helper's console without a window (kHideConsoleWindows), so no extra window should appear; step 2 of How to test checks that.Evidence
I ran
WindowsExternalTerminalService.openTerminalfrom this branch's compiled output, and from the same module with this change reverted (equivalent tomain), with Python as the terminal program (windowsExec). At startup, Python sends its console the event that pressing Ctrl+C sends (GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)) and reports whetherKeyboardInterruptarrived."VS Code" was a Node.js 24 process, started in one of two ways. One was with Ctrl+C handling on and no console, like VS Code started from the Start menu or taskbar (I checked that Explorer doesn't ignore Ctrl+C). The other was detached, the way the
codeCLI starts VS Code. Each combination ran 3 times on Windows 11 (build 26300). The last row covers all 6 runs in each column.maincodeCLIThe runs used an invisible window station, so no windows were shown and window visibility isn't covered.
Repro script
Run it from the root of a built checkout with
node repro-205417.mjs. It needs Python on thePATHand opens a console window for up to two seconds.On
mainit printsCtrl+C reached the program: NO, and with this PRCtrl+C reached the program: yes.Not changed: VS Code started by the
codeCLIThe
codeCLI has started VS Code detached since 2016 (cli.ts). A VS Code started that way ignores Ctrl+C itself, and so does everything it starts, including external terminals. That was already true before 1.86. The same probably happens after Restart to Update, which starts the installer detached, but I haven't checked. Fixing that would mean turning Ctrl+C handling back on in the main process at startup, as Windows Terminal and node-pty do. That needs a native call, so I left it for a follow-up.How to test
codefrom a terminal.ping -t 127.0.0.1and press Ctrl+C. Before this change, ping keeps running and only Ctrl+Break stops it. With this change, ping stops.Validation
node node_modules/mocha/bin/mocha.js test/unit/node/index.ts --delay --ui=tdd --exit --run src/vs/platform/externalTerminal/test/node/externalTerminalService.test.ts(thetest-nodescript, on Node.js 24.22.1): 13 passing. The new test fails whendetached: trueis put back.build/hygiene.ts(Formatter.verifyFormatting) on both changed files: passed.main. CI runs both.