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));

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\x07 on every chpwd / 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's vcs_info style and starship emit it automatically; bash needs PROMPT_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$PWD with $PWD percent-encoded. Terminals strip the URI prefix and resolve $PWD locally 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

Related sequences

In the family cookbook

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