Terminal Shell Integration in Visual Studio Code (2023)

Visual Studio Code has the ability to integrate with common shells, allowing the terminal to understand more about what's actually happening inside the shell. This additional information enables some useful features such as working directory detection and command detection, decorations, and navigation.

Supported shells:

  • Linux/macOS: bash, pwsh, zsh
  • Windows: pwsh


Automatic script injection

By default, the shell integration script should automatically activate on supported shells launched from VS Code. This is done by injecting arguments and/or environment variables when the shell session launches. This automatic injection can be disabled by setting terminal.integrated.shellIntegration.enabled to false.

This standard, easy way will not work for some advanced use cases like in sub-shells, through a regular ssh session (when not using the Remote - SSH extension) or for some complex shell setups. The recommended way to enable shell integration for those is manual installation.

Note: On Windows, you'll need PowerShell 7 (pwsh) for shell integration support. You can install via https://aka.ms/PSWindows.

Manual installation

To manually install shell integration, the VS Code shell integration script needs to run during your shell's initialization. Where and how to do this depends on the shell and OS you're using. When using manual install it's recommended to set terminal.integrated.shellIntegration.enabled to false, though not mandatory.

Tip: When using the Insiders build, replace code with code-insiders below.


Add the following to your ~/.bashrc file. Run code ~/.bashrc in bash to open the file in VS Code.

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path bash)"


Add the following to your PowerShell profile. Run code $Profile in pwsh to open the file in VS Code.

(Video) vs code shell integration failed to activate [FIXED]

if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --locate-shell-integration-path pwsh)" }


Add the following to your ~/.zshrc file. Run code ~/.zshrc in bash to open the file in VS Code.

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"

Git Bash

⚠️ This is currently experimental and automatic injection is not supported

Add the following to your ~/.bashrc file. Run code ~/.bashrc in Git Bash to open the file in VS Code.

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path bash)"


⚠️ This is currently experimental and automatic injection is not supported

Add the following to your config.fish. Run code $__fish_config_dir/config.fish in fish to open the file in VS Code.

string match -q "$TERM_PROGRAM" "vscode"and . (code --locate-shell-integration-path fish)

Portability versus performance

The recommended approach above to install shell integration relies on executing our CLI to find the path to the shell integration script. This is great as it works cross-platform and also with all install types, provided code in on the $PATH. This currently launches Node.js in order to fetch the path, which can add a small delay to shell startup. To reduce this, you can inline the script above by resolving the path ahead of time and adding it directly into your init script.

# Output the executable's path first:code --locate-shell-integration-path bash# Add the result of the above to the source statement:[[ "$TERM_PROGRAM" == "vscode" ]] && . "/path/to/shell/integration/script.sh"

Command decorations and the overview ruler

One of the things that shell integration enables is the ability to get the exit codes of the commands run within the terminal. Using this information, decorations are added to the left of the line to indicate whether the command succeeded or failed. These decorations also show up in the relatively new overview ruler in the scroll bar, just like in the editor.

Terminal Shell Integration in Visual Studio Code (1)

The decorations can be interacted with to give some contextual actions like re-running the command:

Terminal Shell Integration in Visual Studio Code (2)

(Video) How To Change Default Terminal In VS Code | Change Default Shell Used In Integrated Terminal #VsCode

The command and overview ruler decorations can be configured with the setting terminal.integrated.shellIntegration.decorationsEnabled setting.

Command navigation

The commands detected by shell integration feed into the command navigation feature (Ctrl/Cmd+Up, Ctrl/Cmd+Down) to give it more reliable command positions. This feature allows for quick navigation between commands and selection of their output. Hold Shift as well to select from the current position to the command.

Quick fixes

VS Code scans the output of a command and presents a Quick Fix with actions that have a high likelihood of being what the user will want to do next.

Terminal Shell Integration in Visual Studio Code (3)

Here are some of the built-in Quick Fixes:

  • When it's detected that a port is already being listened to, suggest to kill the process and re-run the previous command.
  • When git push fails due to an upstream not being set, suggest to push with the upstream set.
  • When a git subcommand fails with a similar command error, suggest to use the similar command(s).
  • When git push results in a suggestion to create a GitHub PR, suggest to open the link.

The Quick Fix feature also supports audio cues for additional feedback when a Quick Fix is available.

Run recent command

The Terminal: Run Recent Command command surfaces history from various sources in a Quick Pick, providing similar functionality to a shell's reverse search (Ctrl+R). The sources are the current session's history, previous session history for this shell type and the common shell history file.

Terminal Shell Integration in Visual Studio Code (4)

Some other functionality of the command:

  • By default the search mode is "contiguous search", meaning the search term must exactly match. The button on the right of the search input allows switching to fuzzy search.
  • In the current session section, there is a clipboard icon in the right of the Quick Pick that will open the command output in an editor.
  • Alt can be held to write the text to the terminal without running it.
  • The amount of history stored in the previous session section is determined by the terminal.integrated.shellIntegration.history setting.

There is currently no keybinding assigned by default but you can add your own keyboard shortcut. For example, the below replaces Ctrl+R with runRecentCommand, with Ctrl+Alt+R available to fallback to the shell's regular behavior:

{ "key": "ctrl+r", "command": "workbench.action.terminal.runRecentCommand", "when": "terminalFocus"},// Allow ctrl+r again to go to the next command in the quick pick{ "key": "ctrl+r", "command": "workbench.action.quickOpenNavigateNextInViewPicker", "when": "inQuickOpen && inTerminalRunCommandPicker"},// Fallback to the shell's native ctrl+r{ "key": "ctrl+alt+r", "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u0012"/*^R*/ }, "when": "terminalFocus"},// Have ctrl+c close the quick pick{ "key": "ctrl+c", "command": "workbench.action.closeQuickOpen", "when": "inQuickOpen && inTerminalRunCommandPicker"}

Go to recent directory

Similar to the run recent command feature, the Terminal: Go to Recent Directory command keeps track of directories that have been visited and allows quick filtering and navigating (cd) to them.

Alt can be held to write the text to the terminal without running it.

Current working directory detection

Shell integration tells VS Code what the current working directory of the shell is. This information is not possible to get on Windows without trying to detect the prompt through regex and requires polling on macOS and Linux, which isn't good for performance.

(Video) Setting up Visual Studio Code for PowerShell Development

One of the biggest features this enables is enhanced resolving of links in the terminal. Take a link package.json for example, when the link is activated while shell integration is disabled this will open a search quick pick with package.json as the filter if there are multiple package.json files in the workspace. When shell integration is enabled however, it will open the package.json file in the current folder directly because the current location is known. This allows the output of ls for example to reliably open the correct file.

The current working directory is also used to show the directory in the terminal tab, in the run recent command quick pick and for the "terminal.integrated.splitCwd": "inherited" feature.

Extended PowerShell keybindings

Windows' console API allows for more keybindings than Linux/macOS terminals, since VS Code's terminal emulates the latter even on Windows there are some PowerShell keybindings that aren't possible using the standard means due to lack of VT encoding such as Ctrl+Space. Shell integration allows VS Code to attach a custom keybindings to send a special sequence to PowerShell that then gets handled in the shell integration script and forwarded to the proper key handler.

The following keybindings should work in PowerShell when shell integration is enabled:

  • Ctrl+Space: Defaults to MenuComplete on Windows only
  • Alt+Space: Defaults to SetMark on all platforms
  • Shift+Enter: Defaults to AddLine on all platforms
  • Shift+End: Defaults to SelectLine on all platforms
  • Shift+Home: Defaults to SelectBackwardsLine on all platforms

Supported escape sequences

VS Code supports several custom escape sequences:

VS Code custom sequences 'OSC 633 ; ... ST'

VS Code has a set of custom escape sequences designed to enable the shell integration feature when run in VS Code's terminal. These are used by the built-in scripts but can also be used by any application capable of sending sequences to the terminal, for example the Julia extension uses these to support shell integration in the Julia REPL.

These sequences should be ignored by other terminals, but unless other terminals end up adopting the sequences more widely, it's recommended to check that $TERM_PROGRAM is vscode before writing them.

  • OSC 633 ; A ST - Mark prompt start.

  • OSC 633 ; B ST - Mark prompt end.

  • OSC 633 ; C ST - Mark pre-execution.

  • OSC 633 ; D [; <exitcode>] ST - Mark execution finished with an optional exit code.

  • OSC 633 ; E ; <commandline> ST - Explicitly set the command line.

    The E sequence allows the terminal to reliably get the exact command line interpreted by the shell. When this is not specified, the terminal may fallback to using the A, B and C sequences to get the command, or disable the detection all together if it's unreliable.

    (Video) VSCode Integrate Terminal Launching Externally Fix

    The command line can escape ASCII characters using the \xAB format, where AB are the hexadecimal representation of the character code (case insensitive), and escape the \ character using \\. It's required to escape semi-colon (0x3b) and characters 0x20 and below and this is particularly important for new line and semi-colon.

    Some examples:

    "\" -> "\\""\n" -> "\x0a"";" -> "\x3b"
  • OSC 633 ; P ; <Property>=<Value> ST - Set a property on the terminal, only known properties will be handled.

    Known properties:

    • Cwd - Reports the current working directory to the terminal.
    • IsWindows - Indicates whether the terminal is using a Windows backend like winpty or conpty. This may be used to enable additional heuristics as the positioning of the shell integration sequences are not guaranteed to be correct. Valid values are True and False.

Final Term shell integration

VS Code supports Final Term's shell integration sequences, which allow non-VS Code shell integration scripts to work in VS Code. This results in a somewhat degraded experience as it doesn't support as many features as OSC 633. Here are the specific sequences that are supported:

  • OSC 133 ; A ST - Mark prompt start.
  • OSC 133 ; B ST - Mark prompt end.
  • OSC 133 ; C ST - Mark pre-execution.
  • OSC 133 ; D [; <exitcode>] ST - Mark execution finished with an optional exit code.

SetMark 'OSC 1337 ; SetMark ST'

This sequence adds a mark to the left of the line it was triggered on and also adds an annotation to the scroll bar:

Terminal Shell Integration in Visual Studio Code (5)

These marks integrate with command navigation to make them easy to navigate to via ctrl/cmd+up and ctrl/cmd+down by default.

Common questions

When does automatic injection not work?

There are several cases where automatic injection doesn't work, here are some common cases:

  • $PROMPT_COMMAND is in an unsupported format, changing it to point to a single function is an easy way to work around this. For example:

    prompt() { printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"}PROMPT_COMMAND=prompt
  • Some shell plugins may disable VS Code's shell integration explicitly by unsetting $VSCODE_SHELL_INTEGRATION when they initialize.

Why are command decorations showing when the feature is disabled?

The likely cause of this is that your system has shell integration for another terminal installed that VS Code understands. If you don't want any decorations, you can hide them with the following setting:

"terminal.integrated.shellIntegration.decorationsEnabled": never

Alternatively, you could remove the shell integration script from your shell rc/startup script but you will lose access to command-aware features like command navigation.

(Video) Visual Studio Code - How to change default terminal directory

Why does the command decoration jump around on Windows?

Windows uses an emulated pseudoterminal (pty) backend called ConPTY. It works a little differently to a regular pty because it needs to maintain compatibility with the Windows Console API. One of the impacts of this is the pty handles rendering specially in such a way that the shell integration sequences that identify the commands in the terminal buffer may be misplaced. When the command jumps around it's typically after a command has run, and VS Code's heuristics have kicked in to improve the position of the command decorations.



How do I add an integrated terminal code in Visual Studio? ›

Terminal instances can be added by selecting the + icon on the top-right of the TERMINAL panel, selecting a profile from the terminal dropdown, or by triggering the Ctrl+Shift+` command.

How do I enable integrated terminal in VS Code? ›

Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents. Add a new "terminal. integrated.

How do I run a shell code in Visual Studio? ›

Open Visual Studio Code and press and hold Ctrl + ` to open the terminal. Open the command palette using Ctrl + Shift + P . Type - Select Default Shell .

Why my terminal is not working in VS Code? ›

If your terminal is set to run as administrator only, and you are not launching VS Code as administrator, the terminal will not be able to open. You can either change the default terminal or edit the properties of the terminal exe to not run as administrator.

Does Visual Studio have an integrated terminal? ›

You can open an integrated terminal window in Visual Studio for Mac, starting at the root of your solution.

How do I use bash shell code in Visual Studio? ›

  1. Step 1: Open Terminal in VScode by using the shortcut key Ctrl+~. ...
  2. Step 2: Then, you have to open settings by File->Preferences->Settings or by pressing Ctrl+, . ...
  3. Step 3: On clicking, you will see the settings page. ...
  4. Step 4: And that's all when you will reopen VS Code then you will see that Git Bash has been integrated.
22 Nov 2021

Does Visual Studio have a shell? ›

The Visual Studio Shell enables Visual Studio Partners to build tools and applications on top of the Visual Studio IDE. Using integrated mode, you can release a Visual Studio extension for use by customers who have not installed Visual Studio.

How use VS Code terminal Linux? ›

Integrated Terminal

Run Terminal > New Terminal (Ctrl+`) to open a new terminal instance. You'll start a new instance of the bash shell in WSL, again from VS Code running on Windows. Tip: In the lower left corner of the Status Bar, you can see that you're connected to your WSL: Ubuntu instance.

How do I select a terminal code in Visual Studio? ›

  1. Open Visual Studio Code.
  2. Press CTRL + SHIFT + P to open the Command Palette.
  3. Search for “Terminal: Select Default Profile” (previously “Terminal: Select Default Shell”)
  4. Select your preferred shell. In my case I selected “Git Bash”
24 Dec 2021

How do I run terminal C code for Visual Studio? ›

After clicking the Settings, it shows the image below. In this image, select the extension button to set the settings for the C Compiler. Click on the Extension button and scroll the drop-down box to select the Run Code Configuration. Now scroll the right-side pane and Tick on the Run In Terminal.

Can I use Windows Terminal in VS Code? ›

After restarting VSCode pressing Ctrl + Shift + C opens up a Windows Terminal (with Powershell in my case) instead of the normal console.

How do you run code in terminal instead of output in VS Code? ›

  1. Open VS code.
  2. On the left bottom-corner click on Manage and go into the settings.
  3. In the search settings type code runner, scroll-down and put tick-mark in 'Run In Terminal'.

Why NPM command is not working in VS Code? ›

If you're calling npm from the VSCode terminal, you need to restart VSCode first before trying again. If you still get the error, then try restarting your computer first. The error should be gone after you restart. Now you should be able to install any npm package to your local computer with npm install command.

What is terminal integration? ›

Terminal integration lets you integrate your endpoints with SAM to track the activities of users who use privileged accounts. Terminal integration works only when a user checks out a privileged account password and uses automatic login to log in to the endpoint.

What is shell in IDE? ›

The shell is the program on your computer that reads commands you type in and takes action based on those commands. The shell will take your command and work with the computer's operating system to try to answer your request.

Can we use Linux in VS Code? ›

The Visual Studio Code WSL extension lets you use the Windows Subsystem for Linux (WSL) as your full-time development environment right from VS Code.

How do I connect Visual Studio code to Ubuntu? ›

Follow the steps below to install vscode using Ubuntu Software Center:
  1. Open Ubuntu Software Center. Click the Show Applications button and open the Ubuntu Software Center app. ...
  2. Find Visual Studio Code. Click the Search button, and type vscode in the search bar. ...
  3. Install vscode.
12 May 2022

Does VS Code work on Linux? ›

VS Code runs on macOS, Linux, and Windows.

Is Visual Studio Code good for C? ›

With the addition of extensions, VSCode is a great tool for quickly accessing and editing C++ code, whether you are a beginner or an advanced developer. With the addition of an open source compiler that is native to your platform, you can use VSCode as a complete tool for building your C++ solutions.

Can we use GUI in VS Code? ›

Working with GUI applications in VS Code. You can develop Java GUI applications in Visual Studio Code easily. To achieve that, you need to install the Extension Pack for Java, which includes all the required extensions to develop Java GUI applications.

How do I run the console app in VS Code? ›

Show activity on this post. Navigate to the folder you want to create the console app in. In VSCode, use Ctrl + ` to open the terminal window or go to View and select Integrated Terminal.
Now type the following below:
  1. dotnet new console.
  2. dotnet restore.
  3. dotnet run.

How do I run Powershell as administrator in VS Code? ›

If you're on Windows you can:
  1. Right click the shortcut or app/exe.
  2. Go to properties.
  3. Compatibility tab.
  4. Check "Run this program as an administrator"
8 Jun 2016

How do I add a NuGet code to VS? ›

To find and install a NuGet package with Visual Studio, follow these steps: Load a project in Solution Explorer, and then select Project > Manage NuGet Packages. The NuGet Package Manager window opens. Select the Browse tab to display packages by popularity from the currently selected source (see Package sources).

How do I create a custom terminal in Visual Studio code? ›

Go to Files --> Preferences --> Settings and this will open settings.
As of https://code.visualstudio.com/updates/v1_35 you can now:
  1. select from the pulldown menu directly above the terminal "Select Default Shell"
  2. select the one you like.
  3. click the +
  4. done.

How do you insert a terminal? ›

Insert terminals

Select the desired terminal in the Symbol selection dialog. Place the terminal on the schematic page. In the Properties <...> dialog, enter the device data of the terminal, e.g. the displayed DT, in the Terminal tab.

Does VS Code support NuGet? ›

An extension for Visual Studio Code that lets you easily add or remove . NET Core 1.1+ package references to/from your project's .

Does Visual Studio Code have NuGet? ›

It's used in projects of every type and scope, but its primary focus is not on dotnet development. So there is no native NuGet tooling in Visual Studio Code. Without any modifications to Visual Studio Code, you can still work with NuGet. Just open a shell in its terminal window and issue with the dotnet CLI commands.

How do I enable NuGet in Visual Studio? ›

Json package in Visual Studio, follow these steps:
  1. Select Project > Manage NuGet Packages.
  2. In the NuGet Package Manager page, choose nuget.org as the Package source.
  3. From the Browse tab, search for Newtonsoft. Json, select Newtonsoft. ...
  4. If you're prompted to verify the installation, select OK.
20 Sept 2022

How do I create a custom bash terminal? ›

Customize Git Bash Shell config
  1. Locate the Git installation folder on your computer.
  2. Make a backup of the git-prompt.sh file in Git's etc\profile. ...
  3. With administrator rights, edit the properties in the file named PS1.
  4. Save the git-prompt.sh file.
  5. Open a new Git Bash Shell prompt to see the customized properties display.
24 May 2022

How do I open a directory in terminal VS Code? ›

Great, now to open a folder to VSCode, just type code . and it'll magically open your folder into a new VSCode window!

What are 3 examples of terminals? ›

There are several types of terminals: dumb terminals, smart terminals, and graphics terminals.

What are the 3 terminals? ›

Definition: A transistor is an electronic device that contains three terminals named emitter, base, and collector. The small current at one terminal is used to generate a large current at the remaining terminals.

What is a shell in terminals? ›

What Is Shell? The Shell is the name of the program that runs in the terminal (command line interpreter). It can be also seen as a program that processes commands and returns output because it is like an application running commands.


1. Visual Studio Code Terminals Configuration
(Patrick Butler Monterde)
2. How to INTEGRATE MULTIPLE TERMINALS into Visual Studio Code
3. Using VSCode to write bash scripts
(Scott Shaper)
4. [Windows] How to have a kickass terminal in Visual Studio Code
(Mahmoud Mousa)
5. Use Bash In Visual Studio Code Terminal
6. VS Code — Integrate Git Bash as Default Terminal
(Neutron Dev)
Top Articles
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated: 12/24/2022

Views: 6162

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.