Skip to main content
ansicode

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[\x1b]7;file://HOST/PATH\x07
\\033[\033]7;file://HOST/PATH\007
\\e[\e]7;file://HOST/PATH\a
ESC [ESC ] 7 ; URL BEL
hex1b 5d 37 3b ... 07

Description

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

bash
# Emit on every prompt — bash 5+\nPROMPT_COMMAND='printf "\033]7;file://%s%s\007" "$HOSTNAME" "$PWD"'
python
import os, socket, sys; sys.stdout.write(f'\x1b]7;file://{socket.gethostname()}{os.getcwd()}\x07')
go
host, _ := os.Hostname(); wd, _ := os.Getwd(); fmt.Printf("\x1b]7;file://%s%s\x07", host, wd)
javascript
import os from 'node:os'; process.stdout.write(`\x1b]7;file://${os.hostname()}${process.cwd()}\x07`)
c
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

Related sequences

In the family cookbook

OSC cookbook · 5. Shell prompt marks — `OSC 133` (FinalTerm A / B / C / D)