# Set Window Title (OSC 0, OSC 2, OSC l)

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

- **Sequence:** `OSC Ps ; 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)

Set the window title to `Pt`, which is UTF-8 text. `Ps` says which title:

| `Ps` | Sets |
| --- | --- |
| `0` | the window title and the icon name |
| `1` | the icon name only |
| `2` | the window title only |

Nothing on the screen changes. 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.

**The older forms.** Before these, Sun's terminals and CDE's dtterm set the
title with a letter instead of a number, and xterm accepts them too: its
[Control Sequences](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
document lists them in its table of the Sun and dtterm window operations.

| Sequence | Sets |
| --- | --- |
| `OSC l Pt ST` | the window title |
| `OSC L Pt ST` | the icon name |
| `OSC I Pt ST` | the icon, from the file `Pt` |

There is no `;`: everything after the letter is the text, a `;` included
([`do_osc`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L4013-L4034)).
These are also the forms xterm answers in when it reports the title or the
icon name, `CSI 21 t` and `CSI 20 t` (see [XTWINOPS](https://control-codes.page/csi/xtwinops/index.html.md)),
though a default xterm refuses those reports. libghostty-vt has only the
numbered forms and ignores the letters, so the cases that set the title
with `OSC l` are known differences.

## 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-3: OSC 0, with UTF-8

Input, one step per line:

```text
\e]0;café ☕\a
```

Expected screen:

```text
|___|
title "café ☕"
```

### 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-5: The dtterm form

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

Input, one step per line:

```text
\e]lHello\e\\
```

Expected screen:

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

### OSC2-6: Everything after the l is the title

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

Input, one step per line:

```text
\e]l;two;parts
```

Expected screen:

```text
|___|
title ";two;parts"
```

### OSC2-7: OSC L sets only the icon name

Input, one step per line:

```text
\e]2;Window
\e]LIcon
\e]IIcon.xpm
A
```

Expected screen:

```text
|A__|
title "Window"
cursor 1,2
```

---

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>.
