Launch a script in a new Ghostty window
Open Ghostty in a specific project directory, run a setup script (source env vars, start a container, load credentials), then drop into an interactive shell when the script finishes.
The trick
The intuitive open -na Ghostty --args -e /bin/bash -c "./scripts/setup-env.sh; exec $SHELL -i" looks right, but it fails in two ways:
- Two tabs open instead of one. Ghostty's
-eonly consumes the next single token as the executable. Everything after that (-c, the script path, the shell line) is parsed as separate Ghostty flags, and-ctriggers a second tab. command not foundfor Homebrew tools. Switching to--command=fixes the tab issue, but Ghostty wraps the value inbash --noprofile --norc. Your.zprofileand.zshrcnever run, so/opt/homebrew/binis missing fromPATHand anything installed via Homebrew is not found.
Working configuration
{
"label": "Open project shell (prod)",
"type": "command",
"command": "open",
"args": [
"-na", "Ghostty",
"--args",
"--working-directory=/Users/you/Code/your-project",
"--command=zsh -lc './scripts/setup-env.sh prod; exec zsh -i'"
]
}
Paste this as an action inside any service, group, or shortcut. Replace these three placeholders with your own values:
--working-directory=…: absolute path to the project the shell should open in../scripts/setup-env.sh: path (relative to the working directory) of the script you want to run.prod: any arguments your script expects. Omit if there are none.
Why this works
open -na Ghosttylaunches a fresh Ghostty instance and forwards everything after--argsto it. Direct CLI launch is not supported on macOS, so going throughopenis required.--working-directory=tells Ghostty where to set the new window'scwd.--command=takes the whole shell line as one value, so Ghostty cannot misparse it into a second tab.- The value
zsh -lc '...'starts an interactive login shell.-ltriggers your shell init files (.zprofile,.zshrc), soPATHpicks up/opt/homebrew/binand the script can call anything you'd normally use in a terminal. exec zsh -iat the end replaces the script process with an interactive shell, so the window stays open after the setup runs.
Prerequisites
- Ghostty installed (tested on 1.3.x)
zshas the user's shell (default on macOS 10.15+)- Any binaries your setup script calls (e.g.
aws,docker) must end up onPATHonce your.zprofileor.zshrchas run. If they work when you open a normal terminal, they'll work here.