I recently switched to iTerm2 from the default Terminal app and have a usability issue.

On Terminal, the working directory you are in shows up on the title bar along with the process and pixel size. For example, when you click on Window to switch between different Terminal sessions, you'd see: working_directory - process - pixel_size.

On iTerm2, unfortunately only the process shows in the title bar. So if I'm working in multiple iTerm2 windows on different directories, I can't easily differentiate which is which when I click on Window to choose one. I know I can easily switch between iTerm2 windows once I select one, but I'd like to identify exactly which window I want right away. (By the way, I use Witch, and Command-tabbing doesn't help either because here again only the process shows up on the list).

Any suggestions? I looked through all the preferences and didn't see anything. Creating profiles isn't exactly what I'm after--I'd just like to see the current working directory in iTerm2 window titles.

7 Answers 7


With the \033]0;TEXT\007 escape sequence.

Example of use in Bash: echo -ne "\033]0;$PWD\007"

Which you could add to your $PROMPT_COMMAND if you use Bash, or otherwise attach to you PS1 so it gets re-evaluated often.

Example: export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'

  • 1
    This works. Just to be pedantic, add the export line listed above to your ~/.bashrc file.
    – Spencer
    Commented May 10, 2013 at 14:50
  • This is awesome. Thanks so much; this helped me understand that the answer is really about bash programming and has nothing to do with iTerm vs Terminal. As a follow up for anyone else, please see faqs.org/docs/Linux-mini/Xterm-Title.html#s3 and linfo.org/echo.html. Thanks again!
    – whiny_nil
    Commented May 12, 2013 at 20:30
  • 8
    and to get just the last segment of the path echo -ne "\033]0;${PWD##*/}\007" (with thanks to github.com/barryclark/bashstrap for showing the way)
    – Anentropic
    Commented Dec 23, 2013 at 0:05
  • 1
    @Spencer: There is no reason to export the PROMPT_COMMAND shell variable, and in general one should not export a shell variable unless you have a specific need to share the variable with every program run by the shell. By default, variables that are used by the shell should not be exported; only export variables that are meant to be transmitted to other processes. ~/.bashrc will be run by every interactive shell, so they don't need to inherit the variables set by this script.
    – Chris Page
    Commented Dec 7, 2015 at 9:41
  • 1
    @kapoko Because your prompt setting on the remote shell doesn't set the window title. Fix that. Commented Aug 16, 2023 at 19:41

If you're using zsh (which is the default in macOS 10.15+), put this in your ~/.zshrc instead:

if [ $ITERM_SESSION_ID ]; then
precmd() {
  echo -ne "\033]0;${PWD##*/}\007"

You can also spell \033 as \e and \007 as \a.


Possibly a simpler answer is to use the string interpolation functionality offered by iTerm 2. Providing:


in settings would result in a changed Window title. The option is accessible through Preferences>>Profiles>>[Profile we need to modify]>>Window

settings Settings

RESULTS Window title

  • 3
    Wow... finally the right answer that I was just looking for!!! If you want this to work for TABS, use \(current.Session.path)
    – vanHoesel
    Commented Oct 22, 2021 at 10:30
  • 4
    Fixing @vanHoesel's answer: for tabs it's \(currentSession.path) Commented Aug 7, 2022 at 9:32
  • More variables are documented here if interested: iterm2.com/documentation-variables.html
    – varogen
    Commented Jul 14, 2023 at 23:03
  • That's definetely the right way of doing that, thanks!
    – mrded
    Commented Aug 16, 2023 at 10:03
  • Any way to show relative path like ~, ~/Desktop instead of absolute path?
    – sanjarcode
    Commented Dec 30, 2023 at 4:13

I like this answer from this gist to add it to the tab title

# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
  export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";

You can relatively easily set the tab title in iTerm2 on macOS to the current working directory by placing the following in your ~/.zshrc profile:

# Set iTerm Tab Title to Current Working Directory

iterm_tab_title() {
  echo -ne "\e]0;${PWD##*/}\a"
add-zsh-hook precmd iterm_tab_title

It uses a precmd hook function to execute before each prompt, setting the tab title by echoing out the current working directory.

For good measure, some Oh My Zsh themes mess around with the Terminal window title, so setting DISABLE_AUTO_TITLE="true" fixes this.


Don't have enough karma to comment, but if you want it to show ~/dir instead of /users/username/dir you can use

if [ $ITERM_SESSION_ID ]; then
precmd() {
  echo -ne "\033]0;$(dirs)\007"



Under Preferences -> Profiles -> General -> Basics...

Set the Title to PWD only.

enter image description here

You must log in to answer this question.

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