# Set Window Title (OSC 2)

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

- **Sequence:** `OSC 2 ; Pt ST`
- **ECMA-48:** [§8.3.89 OSC – Operating System Command, p. 51](https://archive.org/details/ecma-48-5th-edition-june-1991/page/n64/mode/1up)
- **VT510:** [4.2 Control Characters](https://vt100.net/docs/vt510-rm/chapter4.html#S4.2)
- **xterm:** [Operating System Commands](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

`OSC 2 ; Pt ST` sets the window title to `Pt`, and leaves the icon name
alone; [OSC 0](https://control-codes.page/osc/icon-and-title/index.html.md) sets both, and [OSC 1](https://control-codes.page/osc/icon/index.html.md) 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`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L4141-L4150)),
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`](https://control-codes.page/osc/kitty-color/index.html.md), 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`](https://control-codes.page/osc/dtterm-title/index.html.md) for the title, [`OSC L`](https://control-codes.page/osc/dtterm-icon/index.html.md)
for the icon name and [`OSC I`](https://control-codes.page/osc/dtterm-icon-file/index.html.md) for the icon.

## Support

| Terminal | Version | Support | Notes |
| --- | --- | --- | --- |
| VT220 | [manual](https://vt100.net/docs/vt220-rm/), 2nd ed., 1984 | No | OSC is not among the controls it recognizes ([§4.2](https://vt100.net/docs/vt220-rm/chapter4.html#S4.2)) |
| VT510 | [manual](https://vt100.net/docs/vt510-rm/), 1st ed., 1993 | No | ignores an OSC string ([chapter 4](https://vt100.net/docs/vt510-rm/chapter4.html)) |
| xterm | patch 412, [xterm-411a](https://github.com/ThomasDickey/xterm-snapshots/tree/xterm-411a) | Yes | an empty title is `xterm` |
| libghostty-vt | [0f171f6](https://github.com/ghostty-org/ghostty/tree/0f171f650a1cbbd6df4a2573b6b0c7de57cc6d90) | Yes | an empty title clears it (OSC2-8) |
| Konsole | 26.11.70, [a24c3d71](https://invent.kde.org/utilities/konsole/-/tree/a24c3d71be3684f24d030aa2dbe9bd723d985233) | Yes |  |
| kitty | 0.49.1, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/kitty.json) | Yes | passes the 3 cases that show it working |
| foot | 1.28.0, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/foot.json) | Yes | passes the 3 cases that show it working |
| pyte | 0.8.2, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/pyte.json) | Yes | passes the 3 cases that show it working |
| xterm.js headless | 6.0.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/xtermjs.json) | Yes | passes the 3 cases that show it working |
| alacritty_terminal | 0.26.0, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/alacritty.json) | Yes | passes the 3 cases that show it working |
| ConEmu | build 230724, its [documentation](https://conemu.github.io/en/AnsiEscapeCodes.html) | Yes | `OSC 0..2` set the console window title: [ANSI escape codes](https://conemu.github.io/en/AnsiEscapeCodes.html) |
| rxvt-unicode | 9.31, [run in a VM](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/urxvt.json) | Yes | passes the 3 cases that show it working |
| VTE | 0.84.1, [run as a library](https://git.jcollie.dev/jeff/control-codes/src/branch/main/emulators/results/vte.json) | Yes | passes the 3 cases that show it working |

## Validation

### OSC2-1: Ended with ST

Input, one step per line:

```text
\e]2;Hello\e\\
```

Expected screen:

```text
|___|
title "Hello"
cursor 1,1
```

### OSC2-2: Ended with BEL

Input, one step per line:

```text
\e]2;Hello\a
```

Expected screen:

```text
|___|
title "Hello"
```

### OSC2-4: The last one wins

Input, one step per line:

```text
\e]2;first\a
\e]2;second\a
```

Expected screen:

```text
|___|
title "second"
```

### OSC2-8: An empty title is xterm

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
\e]2;Window\a
\e]2;\a
```

Expected screen:

```text
|___|
title "xterm"
```

---

This is the Markdown version of <https://control-codes.page/osc/title/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
