Skip to content

Commit 635c1c2

Browse files
committed
fix(terminal): close idle terminals when profile changes
1 parent 2a4cafc commit 635c1c2

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/core/webview/webviewMessageHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { checkExistKey } from "../../shared/checkExistApiConfig"
5050
import { getRouterRemovalMessage, getRouterUnavailableSignInMessage } from "../config/routerRemoval"
5151
import { experimentDefault } from "../../shared/experiments"
5252
import { Terminal } from "../../integrations/terminal/Terminal"
53+
import { TerminalRegistry } from "../../integrations/terminal/TerminalRegistry"
5354
import { openFile } from "../../integrations/misc/open-file"
5455
import { openImage, saveImage } from "../../integrations/misc/image-handler"
5556
import { 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") {

src/integrations/terminal/TerminalRegistry.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*

0 commit comments

Comments
 (0)