File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ import { checkExistKey } from "../../shared/checkExistApiConfig"
5050import { getRouterRemovalMessage , getRouterUnavailableSignInMessage } from "../config/routerRemoval"
5151import { experimentDefault } from "../../shared/experiments"
5252import { Terminal } from "../../integrations/terminal/Terminal"
53+ import { TerminalRegistry } from "../../integrations/terminal/TerminalRegistry"
5354import { openFile } from "../../integrations/misc/open-file"
5455import { openImage , saveImage } from "../../integrations/misc/image-handler"
5556import { selectImages } from "../../integrations/misc/process-images"
@@ -728,6 +729,10 @@ export const webviewMessageHandler = async (
728729 }
729730 } else if ( key === "terminalProfile" ) {
730731 Terminal . setTerminalProfile ( value as string | undefined )
732+ // Discard idle terminals so the next command gets a fresh
733+ // terminal using the new profile's shell instead of reusing
734+ // a stale one from the previous profile.
735+ TerminalRegistry . closeIdleTerminals ( )
731736 } else if ( key === "execaShellPath" ) {
732737 Terminal . setExecaShellPath ( value as string | undefined )
733738 } else if ( key === "mcpEnabled" ) {
Original file line number Diff line number Diff line change @@ -277,6 +277,22 @@ export class TerminalRegistry {
277277 this . disposables = [ ]
278278 }
279279
280+ /**
281+ * Disposes all idle (non-busy) VS Code terminals so they are not reused
282+ * after a shell profile change. Busy terminals are left untouched.
283+ */
284+ public static closeIdleTerminals ( ) : void {
285+ this . terminals = this . terminals . filter ( ( t ) => {
286+ if ( t . busy || ! ( t instanceof Terminal ) ) {
287+ return true
288+ }
289+
290+ t . terminal . dispose ( )
291+ ShellIntegrationManager . zshCleanupTmpDir ( t . id )
292+ return false
293+ } )
294+ }
295+
280296 /**
281297 * Releases all terminals associated with a task.
282298 *
You can’t perform that action at this time.
0 commit comments