Terminal Shell Integration
AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Terminal Shell Integration View as Markdown Ask in VS Code Ask in VS Code Insiders 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, fish, pwsh, zsh Windows: Git Bash, pwsh Installation 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 Open in VS Code Open in VS Code Insiders 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 : Automatic injection may not work on old versions of the shell, for example older versions of fish do not support the $XDG_DATA_DIRS environment variable which is how injection works. You may still be able to manually install to get it working. Windows Note : VS Code shell integration requires the permission to run PowerShell scripts . If you have exclusive use of your user account on your machine, consider running: if (( Get-ExecutionPolicy -Scope LocalMachine) -eq 'Undefined' -and ( Get-ExecutionPolicy -Scope CurrentUser) -eq 'Undefined' ) { Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser } 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 Open in VS Code Open in VS Code Insiders to false , though not mandatory. Tip: When using the Insiders build , replace code with code-insiders below. bash 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)" fish 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 ) pwsh Add the following to your PowerShell profile . Run code $Profile in pwsh to open the file in VS Code. if ( $env:TERM_PROGRAM -eq "vscode" ) { . " $( code -- locate - shell - integration - path pwsh ) " } zsh Add the following to your ~/.zshrc file.
Run code ~/.zshrc in zsh to open the file in VS Code. [[ " $TERM_PROGRAM " == "vscode" ]] && . "$( code --locate-shell-integration-path zsh)" Git Bash 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)" Portability versus performance The above shell integration installation is cross-platform and compatible with any installation type if code is in the $PATH .
However, this recommended approach starts Node.js to fetch the script path, leading to a slight delay in shell startup. To mitigate this delay, 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" Shell integration quality When using shell integration, it has a "quality" associated with it that declares the capabilities of it. These qualities are determined by how the shell integration script behaves. None : No shell integration is active. Rich : Shell integration is active and command detection is working in an ideal way. Basic : Shell integration is active, but command detection might not support all functionality.
For example, the command run location is detected, but not its exit status. To view the shell integration quality, hover the terminal tab. Optionally, select Show Details on the hover to view more detailed information. IntelliSense IntelliSense in the terminal enables you to receive suggestions for files, folders, commands, command arguments and options. This feature can be enabled or disabled with the terminal.integrated.suggest.enabled Open in VS Code Open in VS Code Insiders setting.
As you type, a list of suggestions will appear. To manually trigger the suggestions, use the ⌃Space (Windows, Linux Ctrl+Space ) keyboard shortcut. Tip Ctrl+Space may be the keybinding to trigger your Input Method Editor (IME) at the OS level. If so, you can rebind the workbench.action.terminal.triggerSuggest command with a custom keybinding or change the OS-level shortcut. By default, Tab inserts the suggestion. Once you navigate the list, Enter inserts the suggestion.
You can configure this behavior with the terminal.integrated.suggest.selectionMode Open in VS Code Open in VS Code Insiders setting. There are various settings to configure how terminal IntelliSense behaves: terminal.integrated.suggest.quickSuggestions Open in VS Code Open in VS Code Insiders : show automatically depending on the content of the command line, as opposed to manually via Ctrl+Space . terminal.integrated.suggest.suggestOnTriggerCharacters Open in VS Code Open in VS Code Insiders : show automatically after a "trigger character" such as - or / . terminal.integrated.suggest.runOnEnter Open in VS Code Open in VS Code Insiders : optionally run the command when Enter is used (not Tab ). terminal.integrated.suggest.windowsExecutableExtensions Open in VS Code Open in VS Code Insiders : the list of extensions that are treated as executables on Windows. terminal.integrated.suggest.providers Open in VS Code Open in VS Code Insiders : provides the ability to disable specific providers, for example extensions may contribute completions you don't want. terminal.integrated.suggest.showStatusBar Open in VS Code Open in VS Code Insiders : show the status bar at the bottom of the IntelliSense popup. terminal.integrated.suggest.cdPath Open in VS Code Open in VS Code Insiders : enable $CDPATH integration. terminal.integrated.suggest.inlineSuggestion Open in VS Code Open in VS Code Insiders : integrate with shell "ghost text" and how to present it. terminal.integrated.suggest.upArrowNavigatesHistory Open in VS Code Open in VS Code Insiders : send up arrow to the shell instead of browsing completions, this is particularly useful on zsh where you can filter and then press up to do a history search with that prefix. terminal.integrated.suggest.selectionMode Open in VS Code Open in VS Code Insiders : how the Intellisense popup is focused which determines what Enter and Tab do. terminal.integrated.suggest.insertTrailingSpace Open in VS Code Open in VS Code Insiders : insert a trailing space and re-trigger completions after accepting.
Global completion caching To improve performance, VS Code aggressively caches globals for a particular shell. When you make changes to shell startup logic that adds commands, manually refresh the cache with the Terminal: Clear Suggest Cached Globals command ( terminal.integrated.suggest.clearCachedGlobals ) if they weren't picked up automatically. Command decorations and the overview ruler One of the things that
The rest of this page is on the live site.