VS Code Open Terminal: How to Launch a Shell Command Prompt in Visual Studio Code
Press Ctrl+Shift+ (Windows/Linux) or Cmd+Shift+ (macOS) to instantly open the integrated terminal, or programmatically invoke the workbench.action.terminal.new command ID.
The VS Code open terminal functionality is central to the editor's workflow, enabling developers to execute shell commands without leaving the IDE. This feature is implemented in the Microsoft VS Code repository through a sophisticated terminal contribution system that exposes both UI commands and extension APIs.
Understanding the VS Code Open Terminal Architecture
The integrated terminal in VS Code is implemented as a workbench contribution located in src/vs/workbench/contrib/terminal/. When you trigger a VS Code open terminal action, the system resolves the command ID workbench.action.terminal.new registered in src/vs/workbench/contrib/terminal/browser/terminalActions.ts (lines 1214-1224).
This command delegates to ITerminalService.createTerminal, which spawns the shell process based on the selected profile and renders it in the terminal view. The architecture separates concerns between UI actions (terminalActions.ts), menu contributions (terminalMenus.ts), and the low-level terminal service (terminalService.ts).
Method 1: Keyboard Shortcuts for VS Code Open Terminal
Default Keybindings
The fastest way to perform a VS Code open terminal action is using the default keyboard shortcut:
- Windows/Linux: `Ctrl+Shift+``
- macOS: `Cmd+Shift+``
These shortcuts dispatch the workbench.action.terminal.new command, creating a new terminal instance with the default shell profile.
Customizing Your Shortcut
You can override these bindings in keybindings.json:
{
"key": "ctrl+alt+t",
"command": "workbench.action.terminal.new"
}
Method 2: Programmatic VS Code Open Terminal via Extension API
Extension developers can trigger the VS Code open terminal functionality through two primary APIs.
Creating a Terminal with createTerminal()
The vscode.window.createTerminal() method provides full control over terminal creation. This API is exposed in src/vs/workbench/api/common/extHostExtensionApi.ts and mirrors the internal ITerminalService.createTerminal implementation.
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand('myExtension.openShell', () => {
// Create terminal with specific options
const terminal = vscode.window.createTerminal({
name: 'Build Terminal',
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath
});
// Reveal the terminal in the panel
terminal.show();
// Optional: execute initial command
terminal.sendText('npm run build', true);
});
context.subscriptions.push(disposable);
}
Executing the Built-in Command
For simpler use cases, execute the registered command directly:
// Opens terminal using the same path as UI shortcuts
await vscode.commands.executeCommand('workbench.action.terminal.new');
This approach uses the command registration found in terminalActions.ts at lines 1214-1224, ensuring identical behavior to the keyboard shortcut.
Method 3: UI-Based VS Code Open Terminal Actions
Command Palette
Access the VS Code open terminal action through the Command Palette (Ctrl+Shift+P or Cmd+Shift+P):
- Type "Terminal: New Terminal"
- Select the command mapped to
workbench.action.terminal.new
Menu and Context Menu Items
The Terminal menu (Terminal → New Terminal) and the + button in the Terminal panel both dispatch the workbench.action.terminal.new command. These UI elements are wired in src/vs/workbench/contrib/terminal/browser/terminalMenus.ts, which contributes the action to the panel context menu and the main menu bar.
Advanced VS Code Open Terminal Configurations
Specifying Shell Profiles
Control which shell opens by setting the default profile or specifying it per-terminal:
// Use a specific profile (e.g., PowerShell on Windows)
const terminal = vscode.window.createTerminal({
name: 'PowerShell',
shellPath: 'powershell.exe'
});
The default profile selection logic resides in the terminal configuration service, referenced by ITerminalService when creating new instances.
Terminal Location (Panel vs Editor)
By default, VS Code open terminal actions place the terminal in the bottom panel. You can open terminals in the editor area:
const terminal = vscode.window.createTerminal({
name: 'Editor Terminal',
location: { viewColumn: vscode.ViewColumn.Beside }
});
terminal.show();
This corresponds to the TerminalLocation.Editor enum value handled internally in terminalActions.ts for the "Create Terminal in Editor Area" command.
Sending Text to the Terminal
After opening, interact programmatically:
const term = vscode.window.createTerminal();
term.show();
term.sendText('git status', true); // true = execute immediately
The sendText method forwards input to the underlying PTY, matching the behavior of the Run Selected Text action defined in terminalActions.ts.
Key Source Files for VS Code Open Terminal Implementation
Understanding the implementation helps debug terminal behavior and develop extensions:
src/vs/workbench/contrib/terminal/browser/terminalActions.ts– Registers theworkbench.action.terminal.newcommand (lines 1214-1224) and other terminal-related actions.src/vs/workbench/contrib/terminal/common/terminal.ts– Declares theTerminalCommandIdenum andITerminalServiceinterface used across the terminal system.src/vs/workbench/contrib/terminal/browser/terminalMenus.ts– Contributes terminal commands to the UI menus and panel context menus.src/vs/platform/terminal/common/terminalService.ts– Low-level service responsible for spawning shell processes and managing PTY instances.src/vs/workbench/api/common/extHostExtensionApi.ts– Exposes thevscode.window.createTerminalAPI to extensions.
These files together implement the open terminal workflow: UI → command registration → ITerminalService.createTerminal → PTY launch → terminal view rendering.
Summary
- Use keyboard shortcuts (
Ctrl+Shift+`` orCmd+Shift+``) for instant access to the integrated terminal via theworkbench.action.terminal.newcommand. - Call
vscode.window.createTerminal()from extensions to programmatically open terminals with custom names, working directories, or shell paths. - Execute
workbench.action.terminal.newdirectly usingvscode.commands.executeCommand()to trigger the same behavior as UI shortcuts. - Control terminal placement using the
locationoption to open shells in the panel (default) or editor area. - Reference
terminalActions.ts(lines 1214-1224) for the core command registration andITerminalServicefor the underlying implementation.
Frequently Asked Questions
What is the command ID for opening a terminal in VS Code?
The command ID is workbench.action.terminal.new. This ID is registered in src/vs/workbench/contrib/terminal/browser/terminalActions.ts (lines 1214-1224) and is bound to the default keyboard shortcut Ctrl+Shift+`` (Windows/Linux) or Cmd+Shift+`` (macOS). You can invoke this ID programmatically using vscode.commands.executeCommand('workbench.action.terminal.new').
How do I open a terminal in VS Code using the Extension API?
Use the vscode.window.createTerminal() method, which is exposed in src/vs/workbench/api/common/extHostExtensionApi.ts. This returns a Terminal object that you must call .show() on to reveal. You can pass options like name, cwd, and shellPath to customize the shell environment. This API mirrors the internal ITerminalService.createTerminal implementation used by the core command.
Can I open a terminal in the editor area instead of the bottom panel?
Yes. When calling vscode.window.createTerminal(), pass the location option with { viewColumn: vscode.ViewColumn.Beside } or vscode.ViewColumn.One to open the terminal in the editor area. This corresponds to the internal TerminalLocation.Editor enum value handled in terminalActions.ts. By default, terminals open in TerminalLocation.Panel (the bottom panel).
Where is the terminal implementation located in the VS Code source code?
The primary implementation resides in src/vs/workbench/contrib/terminal/. Key files include terminalActions.ts (registers the workbench.action.terminal.new command), terminalMenus.ts (wires commands to UI menus), and common/terminal.ts (defines ITerminalService and TerminalCommandId). The low-level PTY spawning logic lives in src/vs/platform/terminal/common/terminalService.ts, while the extension API surface is exposed in src/vs/workbench/api/common/extHostExtensionApi.ts.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →