In the Terminal preferences you can find an option to open new windows and tabs in the current working directory. Yet there's a message that says that programs notify Terminal about the current working directory using scape sequences, which I don't know what it means. But the Terminal itself is not doing this, as I would like to create a new tab when I press ⌘+T to open at the same working directory (not ~/). I found this post but it doesn't address this. Here you have a figure with the options:enter image description here


So I found the problem with the Terminal and I'm posting the answer hoping it can help others. The problem was in the definition of the PROMPT_COMMAND environmental variable. I changed its definition from

export PROMPT_COMMAND='history -n;'



appending at the end of the existing PROMPT_COMMAND instead and this solved the problem.

  • 3
    Right. The contents of PROMPT_COMMAND is executed by the shell every time the prompt is displayed. The Terminal behavior you're looking for depends upon that variable being set to a function called update_terminal_cwd, which outputs your current working directory as a URL in a manner that is intercepted by Terminal so that it knows where you are. You were overwriting that setting. – Mark Reed Sep 12 '14 at 13:56
  • 1
    Thanks, this solved my problem! I do have a question about your bash: What does the extra "+$PROMPT_COMMAND ;" part do? I get errors when I use this syntax... <blockquote> > $ echo $PROMPT_COMMAND > update_terminal_cwd; ; spwd > -bash: PROMPT_COMMAND: line 1: syntax error near unexpected token ;' > -bash: PROMPT_COMMAND: line 1: update_terminal_cwd; ; spwd' > $ </blockquote> I had to change this to: > export PROMPT_COMMAND="$PROMPT_COMMAND <extra stuff>" – Ian Will Sep 29 '15 at 15:11
  • (Sorry about the poor formatting, stack exchange does not make this easy!) – Ian Will Sep 29 '15 at 15:16
  • Note: export is unnecessary and undesirable with shell variables—variables that are specific to the shell's behavior and not used by other programs invoked from the shell. There's no need to export shell variables, because interactive sub-shells will execute the startup script, and it is generally undesirable to export variables to programs run from the shell unless you intend for them to use it. – Chris Page Dec 11 '15 at 0:51
  • This results in a syntax error and does not fix the issue. – James Dec 21 '15 at 20:08

Well Terminal will certainly open a new tab or window in the current directory if you are at the prompt in bash all things working well.

I'm running Terminal version 2.4 on 10.9.4 and it works perfectly for both new tabs and windows.

If it doesn't then something is upsetting things. Try moving your .profile, .bash_profile and .bashrc out of the way in case something in them is upsetting bash.

Once you've discovered which file is causing the problem then you can discover which part is the problem using a "halving method". Cut the file approximately in half and move that half back. That will tell you which half is doing it. Repeat with the cutting in half and moving until you have it down to a few lines or so you can then ask your question again.

  • I'd also check .bash_profile file. – Mateusz Szlosek Sep 11 '14 at 11:30
  • You're right, something is upsetting the Terminal, because if I rename my .bash_profile to another file, everything works fine. Any ideas on what would be happening within .bash_profile? My file is quite large. – aaragon Sep 11 '14 at 11:31
  • @aaragon maybe check for cd commands: cat ~/.bash_profile | grep cd – Mateusz Szlosek Sep 11 '14 at 13:25
  • This is the result: $ cat ~/.bashrc | grep cd # automatically correct mistyped directory names on cd shopt -s cdspell # If set, an argument to the cd builtin command that is not a directory is assumed to be the name of a variable whose value is the directory to change to shopt -s cdable_vars alias ..='cd ../' # Go back 1 directory level alias cd..='cd ../' # Go back 1 directory level (for fast typers) alias ...='cd ../../' # Go back 2 directory levels alias ~="cd ~" # ~: Go Home – aaragon Sep 11 '14 at 13:30
  • 2
    I'm assuming you didn't write your entire .bash_profile file yourself carefully over many years so I suggest you take the file and cut it down to only the things you understand completely and really need until the Terminal app behaves. Then slowly add stuff back that you might like to have until it breaks again. This is basic profile and login file debugging. – Tony Williams Sep 11 '14 at 13:49

I have noticed that this kind of behaviour also reproduces, when having whitespaces in your hostname.

$ sudo scutil --set HostName 'no-whitespace-name' fixes this issue.

You must log in to answer this question.

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