Skip to content

Windows Terminal same-directory navigation

Windows Terminal same-directory navigation allows users to open new tabs or panes that automatically inherit the current working directory of the active session, rather than starting in the default location.^[windows.md]

This behavior is achieved by configuring the shell's prompt function to emit specific ANSI escape codes that the terminal recognizes.^[windows.md]

Configuration

To enable this feature, the shell's prompt logic must be modified to print the current path using the escape sequence \e]9;9;%s\e\\ (where %s is the path).^[windows.md]

Bash (Git for Windows / WSL)

In a .bash_profile or .bashrc file, add the following logic to the PROMPT_COMMAND:

PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'printf "\e]9;9;%s\e\\" "$(wslpath -w "$PWD")"'
^[windows.md]

PowerShell

Create or modify the Profile.ps1 (e.g., in C:\Program Files\PowerShell\7) to include the escape sequence within the prompt function:

function prompt {
  $loc = Get-Location
  $prompt += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)"
  # ... other prompt logic
}
^[windows.md]

Sources

^[windows.md]

  • [[Windows Terminal]]
  • [[PowerShell]]
  • [[Bash]]