Feature Request: Option to open new tabs in the same directory as the current tab #1925

Closed
opened 2026-01-30 22:42:03 +00:00 by claunia · 15 comments
Owner

Originally created by @dallonf on GitHub (Jun 22, 2019).

Summary of the new feature/enhancement

Very often when I'm working on a project, I want to open multiple tabs in the same directory. For example, for a web React project, I might want one tab for npm start, another for npm test --watch, and probably keep another around for various console commands I want to run (like git). It'd be very convenient to cd into my project directory and then just hit Ctrl-T a few times to open up more tabs in that project directory.

Instead, each tab current seems to be opened in the normal "startingDirectory", which is %USERPROFILE% by default, so you have to cd into the desired working directory for every new tab.

Originally created by @dallonf on GitHub (Jun 22, 2019). # Summary of the new feature/enhancement Very often when I'm working on a project, I want to open multiple tabs in the same directory. For example, for a web React project, I might want one tab for `npm start`, another for `npm test --watch`, and probably keep another around for various console commands I want to run (like `git`). It'd be very convenient to `cd` into my project directory and then just hit Ctrl-T a few times to open up more tabs in that project directory. Instead, each tab current seems to be opened in the normal "startingDirectory", which is `%USERPROFILE%` by default, so you have to `cd` into the desired working directory for every new tab.
Author
Owner

@DHowett-MSFT commented on GitHub (Jun 24, 2019):

This is a "hard problem".. Technically, Terminal can't know the working directory of the process hosted inside it. This will be easier with #1131, but still "hard" for shells that don't actually set the working directory. PowerShell, for example, doesn't set the working directory!

@DHowett-MSFT commented on GitHub (Jun 24, 2019): This is a "hard problem".. Technically, Terminal can't know the working directory of the process hosted inside it. This will be easier with #1131, but still "hard" for shells that don't actually _set_ the working directory. PowerShell, for example, doesn't set the working directory!
Author
Owner

@Jaykul commented on GitHub (Jun 26, 2019):

Yeah, I always set the working directory in my PowerShell prompt function, because I can't understand why it doesn't do that on it's own ...

But certainly it's tricky or impossible when some tabs are going to be purely remote (e.g. azshell).

Maybe a solution would be to have a command line that could be run to start a new tab, and which would therefore know which directory it was running in?

@Jaykul commented on GitHub (Jun 26, 2019): Yeah, I always set the working directory in my PowerShell prompt function, because I can't understand why it doesn't do that on it's own ... But certainly it's tricky or impossible when some tabs are going to be purely remote (e.g. [azshell](/yangl900/azshell)). Maybe a solution would be to have a command line that could be run to start a new tab, and which would therefore know which directory it was running in?
Author
Owner

@DHowett-MSFT commented on GitHub (Jun 27, 2019):

On account of this one isn't possible in the general sense (for all types of connections, and all types of applications), I'm going to close it out. Sorry.

@DHowett-MSFT commented on GitHub (Jun 27, 2019): On account of this one isn't possible in the general sense (for all types of connections, and all types of applications), I'm going to close it out. Sorry.
Author
Owner

@jarrodek commented on GitHub (Aug 6, 2019):

This is disappointing. As a person with Linux background staring a new tab in a directory of previously selected tab is a normal thing. When working on a project I often need 2-3 tabs running stuff from the project. For a developer UX I would reconsider how to incorporate this behavior.
I am trying to switch from Ubuntu to Windows for some time now and the only blocker left is usable console which is at leas as good as Bash. I don't feel that current release is as close.

@jarrodek commented on GitHub (Aug 6, 2019): This is disappointing. As a person with Linux background staring a new tab in a directory of previously selected tab is a normal thing. When working on a project I often need 2-3 tabs running stuff from the project. For a developer UX I would reconsider how to incorporate this behavior. I am trying to switch from Ubuntu to Windows for some time now and the only blocker left is usable console which is at leas as good as Bash. I don't feel that current release is as close.
Author
Owner

@FXschwartz commented on GitHub (Aug 20, 2019):

Same as @jarrodek I'm coming from a Linux background trying to make the 100% switch to Windows.

Really the only thing that was keeping me from it was the console. This new console is so far incredible and makes me super excited for the future of developing on Windows.

Being able to

  1. Open a console
  2. Go to the working project directory
  3. Duplicate tab (with directory path) multiple times

is something I do multiple times daily.

Obviously, not a deal-breaker but would be absolutely incredible to have.

@FXschwartz commented on GitHub (Aug 20, 2019): Same as @jarrodek I'm coming from a Linux background trying to make the 100% switch to Windows. Really the only thing that was keeping me from it was the console. This new console is so far incredible and makes me super excited for the future of developing on Windows. Being able to 1. Open a console 2. Go to the working project directory 3. Duplicate tab (with directory path) multiple times is something I do multiple times daily. Obviously, not a deal-breaker but would be absolutely incredible to have.
Author
Owner

@dallonf commented on GitHub (Aug 20, 2019):

What are some ways this could work in a narrow use case? I'm personally fine if I can't duplicate an ssh tab or something like that, but for the common case of having a cmd/PowerShell/WSL terminal open and just wanting another one, it'd be very useful.

@dallonf commented on GitHub (Aug 20, 2019): What are some ways this could work in a narrow use case? I'm personally fine if I can't duplicate an ssh tab or something like that, but for the common case of having a cmd/PowerShell/WSL terminal open and just wanting another one, it'd be very useful.
Author
Owner

@davidhewitt commented on GitHub (Oct 4, 2019):

Also coming from a linux background, it's very helpful to be able to quickly open console tabs in the same directory. (It's disruptive to thinking to have to cd to some folder far from the terminal default when you want to briefly run a new command while some other long-lived command is running in your existing terminal.)

I understand it can't work in all cases, but I'd love to contribute a PR where the existing ctrl+shift+d shortcut can preserve the working directory in cases where Terminal can detect the working directory.

Only blocker to me submitting that PR is it doesn't seem obvious to me how to inspect the current working directory of a child process using the Windows APIs (equivalent of Linux's /proc/<PID>/cwd)! If anyone is able to suggest a method to me for that bit, I would happily do the rest.

@davidhewitt commented on GitHub (Oct 4, 2019): Also coming from a linux background, it's very helpful to be able to quickly open console tabs in the same directory. (It's disruptive to thinking to have to `cd` to some folder far from the terminal default when you want to briefly run a new command while some other long-lived command is running in your existing terminal.) I understand it can't work in all cases, but I'd love to contribute a PR where the existing `ctrl+shift+d` shortcut can preserve the working directory in cases where Terminal can detect the working directory. Only blocker to me submitting that PR is it doesn't seem obvious to me how to inspect the current working directory of a child process using the Windows APIs (equivalent of Linux's `/proc/<PID>/cwd`)! If anyone is able to suggest a method to me for that bit, I would happily do the rest.
Author
Owner

@zadjii-msft commented on GitHub (Oct 4, 2019):

I'd certainly review a PR that enabled this :)

I remain worried that this will not work more often than it will work, but if we have a prototype, then it'll certainly be easier to make the call.

Unfortunately, I don't really know how to get the working dir of another process myself. Presumably there must be a way... @DHowett-MSFT thoughts?

@zadjii-msft commented on GitHub (Oct 4, 2019): I'd certainly review a PR that enabled this :) I remain worried that this will not work more often than it will work, but if we have a prototype, then it'll certainly be easier to make the call. Unfortunately, I don't really know how to get the working dir of another process myself. Presumably there must be a way... @DHowett-MSFT thoughts?
Author
Owner

@rigwild commented on GitHub (Apr 6, 2020):

Any news on this ? This feature would be really useful.

@rigwild commented on GitHub (Apr 6, 2020): Any news on this ? This feature would be really useful.
Author
Owner

@zadjii-msft commented on GitHub (Apr 8, 2020):

@rigwild I'd follow #3158 - that issue actually has a bit more detail on how such a feature might actually be possible to implement, so we've been using that one to track this feature.

@zadjii-msft commented on GitHub (Apr 8, 2020): @rigwild I'd follow #3158 - that issue actually has a bit more detail on how such a feature might actually be possible to implement, so we've been using that one to track this feature.
Author
Owner

@slon872 commented on GitHub (Feb 1, 2021):

Suppose I run wt nt command from Windows Terminal.
Child wt process can determine current directory and environment.
Can it communicate with parent wt to open new tab in it instead of launching new terminal?

@slon872 commented on GitHub (Feb 1, 2021): Suppose I run `wt nt` command from Windows Terminal. Child wt process can determine current directory and environment. Can it communicate with parent wt to open new tab in it instead of launching new terminal?
Author
Owner

@zadjii-msft commented on GitHub (Feb 1, 2021):

@slon872 You might be interested in #4472, #5000, #8135, and #8898.

@zadjii-msft commented on GitHub (Feb 1, 2021): @slon872 You might be interested in #4472, #5000, #8135, and #8898.
Author
Owner

@zadjii-msft commented on GitHub (May 18, 2021):

@davidhiber Oh man, you'd be so interested in #8933. Feel free to continue the discussion in that thread.

@zadjii-msft commented on GitHub (May 18, 2021): @davidhiber Oh man, you'd be so interested in #8933. Feel free to continue the discussion in that thread.
Author
Owner

@michaldudak commented on GitHub (Jun 23, 2021):

Could it be achieved by allowing to run custom code in the 'source' tab to find out the CWD in a way specific to the shell? This could be specified per profile, so each shell could have its own method of determining the working directory.

@michaldudak commented on GitHub (Jun 23, 2021): Could it be achieved by allowing to run custom code in the 'source' tab to find out the CWD in a way specific to the shell? This could be specified per profile, so each shell could have its own method of determining the working directory.
Author
Owner

@leon-strong commented on GitHub (Oct 8, 2021):

For those coming here after the fact this acheived pretty much what i wanted (ctrl-shift-d to work as expected):

Add this to your .bashrc

export PROMPT_COMMAND='printf "\e]9;9;%s\e\" "$(wslpath -m "$PWD")"'

@leon-strong commented on GitHub (Oct 8, 2021): For those coming here after the fact this acheived pretty much what i wanted (ctrl-shift-d to work as expected): Add this to your .bashrc export PROMPT_COMMAND='printf "\e]9;9;%s\e\\" "$(wslpath -m "$PWD")"'
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#1925