Terminal displays directory of previous SSH location even when not running SSH
Taken wholesale from this SuperUser.com question and answer...

The issue is that the shell on the remote host is configured to send an escape sequence to set the terminal window title. This is a fairly common setup. The solutions mentioned in the blog post you linked to are correct.

The simplest and most direct solution is to configure that same remote shell to reset the window title when it logs out. e.g., if the remote shell is bash, put this in ~/.bash_logout:

printf '\e]0;\a'


Alternatively, if you'd like to have your local shell update the window title with something useful, anyway, then do that. When the ssh connection ends, the local shell will set the window title to something else instead of leaving the stale value. e.g. put this in ~/.bashrc:

PS1='\[\e]1;\s\$ \W\a\e]2;\u@\h\a\]'"$PS1"


This puts the user and host name in the window title (which is typically what remote shells are configured to do), and also sets the tab title to show the shell name and type (normal user or root) and current working directory.