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));Used in
Real-world tools that emit this sequence — anchors the bytes to commands you've already used.
- zsh, fish, bash `__vte_prompt_command`shells emit `\x1b]7;file://hostname/abs/path\x07` from the chpwd / PROMPT_COMMAND hook so the host terminal can record cwd per shell-pane and pass it to new-tab / new-window actions
- tmux `update-environment`, new-window -ctmux reads the OSC 7 payload from the active pane to seed `new-window` / `split-window` cwd — `tmux new-window` opens in the current shell's directory, not tmux's start directory
- iTerm2, Terminal.app new-tab inheritanceCmd-T in iTerm2 / macOS Terminal opens the new tab at the previous tab's last reported OSC 7 cwd — break this by disabling shell_integration and the new tab falls back to `$HOME`
- GNOME Terminal, Konsole, WezTerm pane-split cwdGTK / KDE / WezTerm terminals all consume OSC 7 to keep `Split Right` / `Split Down` / `Duplicate Tab` opening at the source pane's directory — the URI must be `file://host/...`, a bare path is rejected silently
- VS Code integrated terminal `Open in External Terminal`VS Code reads the most recent OSC 7 from each terminal panel so the `Terminal: Open in External Terminal` command launches the system terminal at the integrated shell's cwd instead of the workspace root
Frequently asked
Short answers to the questions developers actually search for this sequence.
- How do I make a new tab inherit the current shell's working directory?
- Have the shell emit
\x1b]7;file://hostname/absolute/path\x07on everychpwd/PROMPT_COMMAND. iTerm2, gnome-terminal, Konsole, kitty, ghostty, wezterm, and Windows Terminal all read OSC 7 and use it as the cwd for new tabs / splits. Zsh'svcs_infostyle and starship emit it automatically; bash needsPROMPT_COMMAND='printf "\033]7;file://%s%s\007" "$HOSTNAME" "$PWD"'. Fish emits it natively since 3.0. - Why must the path be URL-encoded with
file://instead of a bare path? - OSC 7 was specified by GNOME / freedesktop to carry a URI, not a path string — so it can identify the *host* (for SSH / multiplex scenarios where the terminal and the shell are on different machines) and round-trip non-ASCII / space characters losslessly. Send
file://$HOSTNAME$PWDwith$PWDpercent-encoded. Terminals strip the URI prefix and resolve$PWDlocally if the hostname matches their own; otherwise they fall back to the user's home directory.
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
- partial
- 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 | partial | no |
Related sequences
In the family cookbook
OSC cookbook · 5. Shell prompt marks — `OSC 133` (FinalTerm A / B / C / D)