← all posts

Fixing iTerm2 Initial Directory: When the UI fails, use the Shell

Gordon Beeming
Gordon Beeming
On this page3 sections ▾

I wanted new iTerm2 sessions on my MacBook to start in my GitHub folder, as they had in Warp. The profile's Initial Directory setting looked correct, but new tabs kept opening at /. Setting Send text at start to run a cd command worked around it.

I also tried granting iTerm2 Full Disk Access in macOS, which didn't change the behaviour. I wanted to keep using iTerm2 because opencode worked better there than in Warp.

#The Problem

In iTerm2, you should be able to go to your Profile settings and simply define your "Initial Directory." It looks correct and the path is valid, but when you hit Cmd + T for a new tab, you are greeted by this:

iTerm2 prompt showing the current directory as the root slash
A new iTerm2 tab opening at / despite the configured initial directory

#Set the directory after the shell starts

I checked for hidden cd commands in .zshrc and tried the Advanced Configuration options without resolving it. The workaround is to run a command after the session opens.

#The Fix

  1. Open iTerm2 Settings (Cmd + ,).
  2. Go to Profiles > General.
  3. Locate the Send text at start field.
  4. Enter the following:
Send text at start
cd /Users/gordonbeeming/Developer/github && clear
The Send text at start field in iTerm2 settings with the cd command entered
Send text at start changes to the GitHub folder and clears the terminal

#Why this works

The Send text at start field tells iTerm2 to wait for the shell to finish initializing, then type that command automatically.

This changes the working directory explicitly instead of relying on the Initial Directory preference. The && clear clears the terminal after a successful cd, so the startup command doesn't remain on screen.

Open a new tab and run pwd to check the directory. To undo the workaround, clear the Send text at start field.

Gordon Beeming
Gordon Beeming

Father • Husband • Triathlete • SSW Solution Architect

Related posts