microsoft / microsoft/vscode

`terminalIsOpen` includes hidden extension terminals, making terminal keybindings unreliable

Open
#325,352 0 comments 0 reactions 1 assignee Claimed by @anthonykim1 View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

I would like a context key that distinguishes user visible terminals (panel or editor terminals) from hidden/background terminals created by extensions. Alternatively, `terminalIsOpen` could exclude terminals created with `hideFromUser`, with a separate context key retaining the current all instances behavior.

## Use case

I keep terminals in the editor area and use one shortcut to create/focus/toggle them:

```jsonc
// settings.json
"terminal.integrated.defaultLocation": "editor"
```

```jsonc
// keybindings.json
{
"key": "cmd+2",
"command": "workbench.action.openPreviousRecentlyUsedEditor",
"when": "terminalEditorFocus"
},
{
"key": "cmd+2",
"command": "workbench.action.terminal.focus",
"when": "terminalIsOpen && !terminalEditorFocus"
},
{
"key": "cmd+2",
"command": "workbench.action.createTerminalEditor",
"when": "!terminalIsOpen"
}
```

This works until an extension creates a hidden terminal. Once the visible terminal editor is closed, `terminalIsOpen` remains true even though the user has no terminal open or visible. The next shortcut therefore runs `workbench.action.terminal.focus`, which creates/reveals a terminal in the panel. All subsequent presses continue targeting the panel rather than the configured editor location.

## Deterministic reproduction

1. Add the setting and keybindings above.
2. Open a workspace where an extension creates a hidden/background terminal. One reproducible trigger is activation of the Python extension through Ruff in a Python workspace.
3. Run **Terminal: Create New Terminal in Editor Area**.
4. Close that terminal editor.
5. Verify that no terminal is visible, then press `cmd+2`.

**Actual:** A terminal opens in the bottom panel because the hidden extension terminal keeps `terminalIsOpen` true.

**Desired:** A context key should allow the final keybinding to detect that no *user-visible* terminal exists and create an editor terminal.

## Verification

I tested this with isolated user-data directories on macOS arm64:

- VS Code 1.128.0 (`fc3def6774c76082adf699d366f31a557ce5573f`)
- VS Code Insiders 1.129.0 (`e7b83d54552fa9cb419c63fb24bde66f70addb60`)
- With all extensions disabled, closing the sole terminal editor clears the condition and the shortcut correctly recreates an editor terminal.
- With the Python extension activated through Ruff, the hidden terminal changes the condition and the shortcut opens the panel terminal.
- Disabling `ms-python.python`, or disabling Ruff so that it does not activate Python in this workspace, removes the trigger.

The Python extension's use of hidden terminals for environment acquisition is intentional background work (see microsoft/vscode-python#13071), so this seems better addressed by exposing a more precise core context key than by requiring extensions not to create hidden terminals.

I found #174119 and #174122, which clarify that panel-oriented terminal commands are working as designed. This request is narrower: it is for a context key that lets keybindings avoid calling those commands when only hidden extension terminals exist.

Possible names/semantics could be `terminalVisibleIsOpen`

TLDR: Hidden extension terminals make `terminalIsOpen` true, causing `workbench.action.terminal.focus` to open the (hidden) terminal panel even though `terminal.integrated.defaultLocation` is "editor". I need a context key that represents user-visible terminals only.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.