OSC 7 — Current working directory hint
Tell the terminal which directory the shell is in — used for tab labels, 'new tab here', and remote-aware split-pane workflows.
Byte forms
Every common string-literal form so you can paste-and-search either direction.
\x1b]7;file://HOST/PATH\x07\033]7;file://HOST/PATH\007\e]7;file://HOST/PATH\aESC ] 7 ; URL BEL1b 5d 37 3b ... 07Description
Tell the terminal the shell's current working directory as a `file://HOST/PATH` URL. Adopted by iTerm2, Windows Terminal, kitty, wezterm, ghostty, Konsole, and VTE-based terminals (gnome-terminal, foot). The terminal uses this for: (a) tab / pane labels that show the basename of the directory, (b) the `Cmd-T`/`new tab here` action that spawns a new shell in the same `cwd`, (c) `tmux` resurrect / wezterm `mux` recovery that restores split panes to the right directory after a session crash. The shell emits this on every prompt — bash via `PROMPT_COMMAND`, zsh via `precmd` or `chpwd`, fish has `__fish_cwd_osc` built in. The hostname matters over SSH: the terminal can refuse to reopen a tab on the remote host since it would have to ssh again.
Spec citation: iTerm2 Proprietary Escape Codes (OSC 7) / VTE / kitty
Examples
# Emit on every prompt — bash 5+\nPROMPT_COMMAND='printf "\033]7;file://%s%s\007" "$HOSTNAME" "$PWD"'import os, socket, sys; sys.stdout.write(f'\x1b]7;file://{socket.gethostname()}{os.getcwd()}\x07')host, _ := os.Hostname(); wd, _ := os.Getwd(); fmt.Printf("\x1b]7;file://%s%s\x07", host, wd)import os from 'node:os'; process.stdout.write(`\x1b]7;file://${os.hostname()}${process.cwd()}\x07`)char host[256]; gethostname(host, sizeof host); printf("\x1b]7;file://%s%s\x07", host, getcwd(NULL, 0));Terminal support
- xterm
- no
- Linux console (fbcon)
- no
- macOS Terminal.app
- partial
- iTerm2
- yes
- Windows Terminal
- yes
- cmd.exe / ConPTY
- no
- kitty
- yes
- alacritty
- partial
- WezTerm
- yes
- Ghostty
- yes
- GNOME Terminal
- yes
- Konsole
- yes
- tmux
- no
- GNU screen
- no
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| no | no | partial | yes | yes | no | yes | partial | yes | yes | yes | yes | no | no |
Related sequences
In the family cookbook
OSC cookbook · 5. Shell prompt marks — `OSC 133` (FinalTerm A / B / C / D)