Skip to content

Open new terminal tab in same directory as existing tab (OSC 7?) #3158

Closed

Description

Description of the new feature/enhancement

Have the option (or default) of a new terminal tab opening in the current directory of the window of which you hit the hotkey to open a new tab. This is the standard way most linux terminals work and is most handy. I often work in a directory where I need to launch multiple seperate processes, its a pain to CD back into the directory each time.

Proposed technical implementation details (optional)

Hit the new tab hotkey, the new terminal should then be in the same folder as the previouse.


maintainer edit: Before commenting, make sure to check out

Tutorial: Opening a tab or pane in the same directory in Windows Terminal

This is largely something configurable today, this issue is just tracking another way of configuring this

Activity

  1. added
    Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.
    on Oct 11, 2019
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Oct 11, 2019
  3. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Oct 11, 2019
  4. egmontkob commented on Oct 11, 2019

    @egmontkob

    There's a "standard" escape sequence (OSC 7 ; URI ST) to set the terminal emulator's belief about the current directory. It originates from macOS Terminal.app, and was later adopted by some other ones, including GNOME Terminal and as far as I know Konsole too.

    Another possible approach is to do some OS-specific hacks to examine the inner state of the child process (or even further down to descendents).

    Yet another possibility is to mix the two, e.g. go to the directory set via OSC 7 if it was ever emitted, otherwise dig into the process.

    The advantage of the OSC 7 approach is that it's clever regarding when to and when not to follow a child process. E.g. you start another nested subshell, it'll be the subdirectory of that subshell that's taken into account because that one also emits this sequence. However, launch an app that internally changes directory (e.g. make) and it – luckily – won't be make's internal subdir that's used.

    The disadvantage of OSC 7 is that it requires cooperation from the shell, or other apps that matter.

  5. DHowett-MSFT commented on Oct 14, 2019

    @DHowett-MSFT
    Contributor

    I've been rejecting this feature request for as long as this project has been open-source, and I never learned about OSC 7. This is very exciting.

    I'm not happy to crawl through the process tree to dig up the leafmost process's CWD, but I am extremely happy to support OSC 7.

  6. changed the title [-]Open new terminal tab is same directory as previouse[/-] [+]Open new terminal tab in same directory as existing tab[/+] on Oct 14, 2019
  7. changed the title [-]Open new terminal tab in same directory as existing tab[/-] [+]Open new terminal tab in same directory as existing tab (OSC 7?)[/+] on Oct 14, 2019
  8. added
    Area-SettingsIssues related to settings and customizability, for console or terminal
    Area-VTVirtual Terminal sequence support
    Product-ConptyFor console issues specifically related to conpty
    Product-PowershellIssues in the modern command interpreter, Powershell.exe.
    and removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Oct 23, 2019
  9. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Oct 23, 2019
  10. davidhewitt commented on Nov 15, 2019

    @davidhewitt

    FYI I asked about OSC 7 handling for Alacritty, which eventually led to this issue being created in the "Terminal WG" on gitlab: https://gitlab.freedesktop.org/terminal-wg/specifications/issues/20

    There's not been much movement on that ticket, but you may be interested to follow it. Especially if you guys have any opinions regarding what a "formal" specification for OSC 7 might look like.

  11. 189 remaining items

  12. nacitar commented on Apr 7, 2025

    @nacitar

    thanks for the hint, @nacitar

    I've tried w/o wslpath like:

    printf "\e]9;9;%s\e\\" "$PWD"
    

    it didn't work unfortunately:

    Image

    what do you mean exactly with remove the starting directory bit too?

    In your windows terminal settings:

                "startingDirectory": "~"
    

    I can confirm that mine works without that present and using PWD directly like I suggested. My guess is that is overriding it.

    ... also make sure you're using duplicateTab

  13. 0anton commented on Apr 8, 2025

    @0anton

    Thank you a lot Jacob McIntosh (@nacitar)!

    I'm unsure what has worked at the end, but this combination "does the needful":

    I had to ensure I'm using duplicate pane: action

            {
                "command": 
                {
                    "action": "splitPane",
                    "split": "auto",
                    "splitMode": "duplicate"
                },
                "id": "User.splitPane.A6751878"
            },
    

    Simplified PROMPT_COMMAND version with just $PWD works actually fine, so I've started using it:

    $ echo $PROMPT_COMMAND
    printf "\e]9;9;%s\e\\" "$PWD"
    

    startingDirectory set to "current dir":

       {
                    "colorScheme": "One Half Dark",
                    "commandline": "wsl.exe -d Ubuntu-24.04",
                    "guid": "{acbafd15-cbbb-5bb3-8a61-bed446ff4b83}",
                    "hidden": false,
                    "name": "Ubuntu 24.04 LTS 1",
                    "opacity": 95,
                    "startingDirectory": "~",
                    "useAcrylic": false
                }
    

    With all this I indeed can duplicate tab to the same dir, which saves a lot of time to me! Resolved to me.

  14. hktkqj commented on Apr 9, 2025

    @hktkqj

    For those struggling to duplicate/split WSL tabs in same diretory, please ensure that the startup command line for the distribution profile uses wsl -d <distro> instead of ubuntu2204.exe like executable, as for some reason this affects the passing of the CWD.

  15. working-name commented on Apr 19, 2025

    @working-name

    For those struggling to duplicate/split WSL tabs in same diretory, please ensure that the startup command line for the distribution profile uses wsl -d <distro> instead of ubuntu2204.exe like executable, as for some reason this affects the passing of the CWD.

    Right, or this default junk somehow generated:

    C:\Windows\system32\wsl.exe --distribution-id {4ad8391d-7793-4fea-90d6-767b6df60ba0} --cd ~
    

    Remove --cd ~, that forces to always cd into the linux user's home folder.

    Thanks Anton Golubev (@0anton)

  16. pavangayakwad commented on May 3, 2025

    @pavangayakwad

    This is a commonsense and the most useful UX, really disappointed to see that it is not implemented till date. I just also wish Terminal remember its previous state when re-opened.

  17. shanselman commented on Jan 31, 2026

    @shanselman
    Member
  18. added a commit that references this issue on Mar 30, 2026
    4ce79d7
  19. added a commit that references this issue on Apr 3, 2026
    7f5185e
  20. JoshuaKasa commented on May 15, 2026

    @JoshuaKasa

    Hi! I've just came across this thread and started working on it, I will link the PR once I'm done working with it!

  21. zadjii-msft commented on May 15, 2026

    @zadjii-msft
    Member

    Tommaso Santamaria (@JoshuaKasa) what approach are you taking?
    FWIW OSC 7 support merged ~1 month ago, and OSC9;9 merged years ago. If you have something else valuable to contribute in this space, I'd be highly curious

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-SettingsIssues related to settings and customizability, for console or terminalArea-VTVirtual Terminal sequence supportIn-PRThis issue has a related PRIssue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Needs-Tag-FixDoesn't match tag requirementsProduct-ConptyFor console issues specifically related to conptyProduct-PowershellIssues in the modern command interpreter, Powershell.exe.Product-TerminalThe new Windows Terminal.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions