OS X El Capitan 10.11 Terminal 2.6 won't open new tabs with same working directory

Solution 1:

By default on OS X, Bash is configured to communicate the current working directory to Terminal using escape sequences at each prompt, using the PROMPT_COMMAND environment variable.

Prior to OS X El Capitan 10.11, this code is found in /etc/bashrc. In 10.11 and later, it has been moved to the Terminal-specific /etc/bashrc_Apple_Terminal file and /etc/bashrc executes the appropriate terminal-specific file.

Current versions of Oh My Zsh! have similar code to communicate the working directory to Terminal.

The most likely reason this stopped working is that you changed your configuration. Perhaps you were using Bash before or you had Oh My Zsh installed and now you don't. Another possibility is that you used to have your shell configured to set the terminal window or tab (aka “icon”) title to contain the working directory pathname: as a convenience for older configurations, if the working directory isn't explicitly set but the window or tab title contains a valid local pathname, Terminal will treat it as the current working directory.

Solution 2:

A simple way to ensure that Terminal.app's "New windows/tabs open with: Same Working Directory" option still works with zsh as your login shell is to instruct zsh to communicate changes in the current working directory to Terminal.app via escape sequence. I've done so in my .zshrc with this:

# tell terminal.app about cwd so new tabs open in same dir
tell_terminal_cwd() {
   cwd=$(print -rD $PWD)
   echo -ne "\033]0;${cwd}\007"
}
precmd_functions+=(tell_terminal_cwd)

Terminal.app's instructions on this topic say provide the current working directory as a properly encoded file:// URL including hostname, but I've found that the above works fine and also looks nice in the tab title.