^[control-codes
live in libghostty-vt

Operating system commands

OSC 2 Set Window Title

View as Markdown

Set the title of the terminal's window or tab.

OSC 2 ; Pt ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
VT510
4.2 Control Characters
xterm
Operating System Commands

OSC 2 ; Pt ST sets the window title to Pt, and leaves the icon name alone; OSC 0 sets both, and OSC 1 the icon name only. In a UTF-8 locale a default xterm keeps the title’s UTF-8, as the OSC 0 page explains. An empty title, OSC 2 ; ST or OSC 2 ST, sets the title to xterm rather than to nothing (do_osc), where libghostty-vt clears it, which the case for that is a known difference. Nothing on the screen changes. DEC’s VT520 had a title sequence of its own, DECSWT, at OSC 21, a number kitty has since given another meaning. The sequence can end with ST (ESC \) or, as most programs that set titles do, with BEL.

A shell sets this from its prompt, which is how a tab comes to show the directory you are in or the command that is running.

Before these, Sun’s terminals and CDE’s dtterm set the title with a letter instead of a number, and xterm accepts those too: OSC l for the title, OSC L for the icon name and OSC I for the icon.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aYesan empty title is xterm
libghostty-vt0f171f6Yesan empty title clears it (OSC2-8)
Konsole26.11.70, a24c3d71Yes
kitty0.49.1, run in a VMYespasses the 3 cases that show it working
foot1.28.0, run in a VMYespasses the 3 cases that show it working
pyte0.8.2, run as a libraryYespasses the 3 cases that show it working
xterm.js headless6.0.0, run as a libraryYespasses the 3 cases that show it working
alacritty_terminal0.26.0, run as a libraryYespasses the 3 cases that show it working
ConEmubuild 230724, its documentationYesOSC 0..2 set the console window title: ANSI escape codes
rxvt-unicode9.31, run in a VMYespasses the 3 cases that show it working
VTE0.84.1, run as a libraryYespasses the 3 cases that show it working

Validation

OSC2-1: Ended with ST

\e]2;Hello\e\\
|___|
title "Hello"
cursor 1,1

OSC2-2: Ended with BEL

\e]2;Hello\a
|___|
title "Hello"

OSC2-4: The last one wins

\e]2;first\a
\e]2;second\a
|___|
title "second"

OSC2-8: An empty title is xterm

\e]2;Window\a
\e]2;\a
|___|
title "xterm"
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.