140

I'm using iTerm for my command line needs, and when I open a tab using Cmd ⌘ + T I want it to open the tab cd'ed to the same location as the tab that was open when I hit Cmd ⌘ + T (instead of opening in my /Users/kramer65).

I searched around the Preferences, but I can't seem to find it. Does anybody know how I can do this? All tips are welcome!

4 Answers 4

194

Select "Reuse previous session's directory" from the preferences of your profile:

Alternatively click on "Advanced Configuration" then "Edit..." so you can set the working directory separately for new windows, new tabs & new split panes

1
  • I tried this and it works but now my aliases that I have in my ~/.zshrc to jump to specific directories are unrecognized. What side effect does the above have?
    – Max
    Commented Oct 20, 2023 at 18:06
48

This is a year old, but I'd like to add a response that isn't so heavy-handed. The accepted answer will open the previous directory every time you open a new tab, which I personally find frustrating. I feel it's easier to always open in the home directory and then open the current directory in a new tab as needed.

To do that, simply run the following command:

open . -a iterm

That will open the current directory (open .) using the application (-a) that most closely matches iterm.

1
  • 1
    I wonder if you could pass a command to that new iterm using the same open syntax. Putting this inside a postactivate for a python venv you could open the iterm and have it ssh to a remote server as part of your workon workflow
    – boatcoder
    Commented Aug 2, 2021 at 17:43
7

To bind a special keybinding to this:

  • go to Settings ( Cmd ⌘ + ,)
  • then keys
  • select the + sign
  • choose a keybinding
  • select the duplicate tab action.
1
  • This results in the 2 tabs mirroring each other. For eg. If I change dir in tab, it will get reflected in the other too
    – pravin
    Commented Sep 22, 2022 at 12:00
1

If you've just set "Reuse previous session's directory" and the change doesn't seem to be taking effect, it's worth noting that the new changes will only apply to tabs / panes that get opened after you've chosen this setting.

For example:

  • Let's say the current setting is: "Home Directory", and you have a tab open (tab #1)
  • You go to "Preferences" and change to "Reuse previous session's directory"
  • If you open a new tab (tab #2) while on tab #1, it will still use the previous settings
  • However, if you open another tab (tab #3) while on Tab 2, it will respect the new configuration
1
  • It seems like it required a full restart in my case. New tabs still opened in my home dir until I restarted iTerm.
    – phette23
    Commented Mar 13, 2023 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .