OSC 2 Set Window Title
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
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | No | OSC is not among the controls it recognizes (§4.2) |
| VT510 | manual, 1st ed., 1993 | No | ignores an OSC string (chapter 4) |
| xterm | patch 412, xterm-411a | Yes | an empty title is xterm |
| libghostty-vt | 0f171f6 | Yes | an empty title clears it (OSC2-8) |
| Konsole | 26.11.70, a24c3d71 | Yes | |
| kitty | 0.49.1, run in a VM | Yes | passes the 3 cases that show it working |
| foot | 1.28.0, run in a VM | Yes | passes the 3 cases that show it working |
| pyte | 0.8.2, run as a library | Yes | passes the 3 cases that show it working |
| xterm.js headless | 6.0.0, run as a library | Yes | passes the 3 cases that show it working |
| alacritty_terminal | 0.26.0, run as a library | Yes | passes the 3 cases that show it working |
| ConEmu | build 230724, its documentation | Yes | OSC 0..2 set the console window title: ANSI escape codes |
| rxvt-unicode | 9.31, run in a VM | Yes | passes the 3 cases that show it working |
| VTE | 0.84.1, run as a library | Yes | passes 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"