04-Terminal Shell Integration
04-Terminal Shell Integration
com/docs/terminal/shell-integration
(https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/terminal/shell-integration.md)
Supported shells:
Installation
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 (/docs/remote/ssh)) 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.
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
! (vscode://settings/terminal.integrated.shellIntegration.enabled)terminal.integrated.shellIntegration.enabled
to false , though not mandatory.
Tip: When using the Insiders build (https://code.visualstudio.com/insiders), 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.
fish
Add the following to your config.fish . Run code $__fish_config_dir/config.fish in fish to open the file in
VS Code.
pwsh
zsh
Add the following to your ~/.zshrc file. Run code ~/.zshrc in bash to open the file in VS Code.
Git Bash
Add the following to your ~/.bashrc file. Run code ~/.bashrc in Git Bash to open the file in VS Code.
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.
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.
The decorations can be interacted with to give some contextual actions like re-running the command:
The command and overview ruler decorations can be configured with the
! (vscode://settings/
terminal.integrated.shellIntegration.decorationsEnabled)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. To select from the current position to the command, you can also hold down Shift ,
pressing Shift+Ctrl/Cmd+Up and Shift+Ctrl/Cmd+Down .
Command guide
The command guide is a bar that shows up beside a command and its output when hovered. This helps more
quickly identify the command and also is a way to verify that shell integration is working properly.
You can customize the color of the command guide by using Color Themes. To toggle the command guide,
configure the
! (vscode://settings/
terminal.integrated.shellIntegration.showCommandGuide)terminal.integrated.shellIntegration.showCommandGuide
setting.
Sticky scroll
The sticky scroll feature will "stick" the command that is partially showing at the top of the terminal, making it
much easier to see what command that output belongs to. Clicking on the sticky scroll component will scroll to the
command's location in the terminal buffer.
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.
• 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.
• When a General or cmd-not-found PowerShell feedback provider triggers, suggest each suggestion.
The Quick Fix feature also supports accessibility signals (/docs/editor/accessibility#_accessibility-signals) for
additional feedback when a Quick Fix is available.
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.
• 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.
• The pin action in the right of the Quick Pick can pin the command to the top of the list.
• 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
! (vscode://settings/
terminal.integrated.shellIntegration.history)terminal.integrated.shellIntegration.history
setting.
The default keyboard shortcut for this command is Ctrl+Alt+R . However, when accessibility mode is on these are
reversed; Ctrl+R runs a recent command and Ctrl+Alt+R sends Ctrl+R to the shell.
The keyboard shortcuts can be flipped when accessibility mode is off with the following keyboard shortcuts:
{ Copy
"key": "ctrl+r",
"command": "workbench.action.terminal.runRecentCommand",
"when": "terminalFocus"
},
{
"key": "ctrl+alt+r",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0012"/*^R*/ },
"when": "terminalFocus"
}
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.
The default keyboard shortcut for this command is ⌘G as it behaves similar to the Go to Line/Column command
in the editor. Ctrl+G can be send to the shell with Ctrl+Alt+G .
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.
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.
Windows' console API allows for more keyboard shortcuts than Linux/macOS terminals, since VS Code's terminal
emulates the latter even on Windows there are some PowerShell keyboard shortcuts 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 keyboard shortcuts 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 keyboard shortcuts should work in PowerShell when shell integration is enabled:
Experimental IntelliSense for PowerShell shows a completion list when typing in PowerShell, similar to the editor
experience. Behind the scenes, this functionality is powered by the PowerShell session's native completion API, so
context-aware completions like variables are available.
PowerShell IntelliSense shows completions like Get-Alias, Get-ChildItem, for example when typing Get-
You can enable the experimental IntelliSense for PowerShell with the
! (vscode://settings/terminal.integrated.suggest.enabled)terminal.integrated.suggest.enabled setting.
Enhanced accessibility
The information that shell integration provides to VS Code is used to improve accessibility in the terminal (/docs/
editor/accessibility#_terminal-accessibility). Some examples of enhancements are:
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 ; D [; <exitcode>] ST - Mark execution finished with an optional exit code.
• OSC 633 ; E ; <commandline> [; <nonce] ST - Explicitly set the command line with an optional nonce.
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.
The optional nonce can be used to verify the sequence came from the shell integration script to prevent
command spoofing. When the nonce is verified successfully, some protections before using the commands
will be removed for an improved user experience.
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:
• OSC 633 ; P ; <Property>=<Value> ST - Set a property on the terminal, only known properties will be
handled.
Known properties:
• OSC 1337 ; CurrentDir=<Cwd> S - Sets the current working directory of the terminal, similar to OSC 633
; P ; Cwd=<Cwd> ST .
• OSC 1337 ; SetMark ST - Adds a mark to the left of the line it was triggered on and also adds an
annotation to the scroll bar:
These marks integrate with command navigation to make them easy to navigate to via ⌘↑ and ⌘↓ .
Common questions
prompt() { Copy
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.
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.
Yes No
02/06/2025
Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)
Request features(https://go.microsoft.com/fwlink/?LinkID=533482)
Report issues(https://www.github.com/Microsoft/vscode/issues)
Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)
(https://
www.microsoft.com)
(https://go.microsoft.com/fwlink/?LinkID=533687)
(https://github.com/microsoft/vscode) (https://www.youtube.com/@code)
Support (https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-
b000-4cfb-2c318cad363d)
Privacy (https://go.microsoft.com/fwlink/?LinkId=521839)
Terms of Use (https://www.microsoft.com/legal/terms-of-use) License (/License)