OSC 4
OSC 4 changes or queries entries in the terminal's 256-color palette. It allows applications to dynamically redefine any of the 256 indexed colors at runtime, or to query the current color value assigned to a given index.
Syntax
OSC 4 ; c ; spec ST Set color index c to spec
OSC 4 ; c ; ? ST Query current color at index c
OSC4_set = 0x1b, "]", "4", ";", index, ";", color_spec, ( 0x07 | 0x1b, "\\" ) ;
OSC4_query = 0x1b, "]", "4", ";", index, ";", "?", ( 0x07 | 0x1b, "\\" ) ;
index = digit, { digit } ;
color_spec = "rgb:", hex, "/", hex, "/", hex ;
hex = hex_digit, hex_digit, [ hex_digit, hex_digit ] ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
hex_digit = digit | "a" | "b" | "c" | "d" | "e" | "f"
| "A" | "B" | "C" | "D" | "E" | "F" ;Parameters
| Parameter | Description | Default |
|---|---|---|
c | Color palette index (0-255) | (required) |
spec | Color specification in X11 format (e.g., rgb:RR/GG/BB) or ? to query | (required) |
Response
When queried with ?, the terminal responds with the current color value in the format:
OSC 4 ; c ; rgb:RRRR/GGGG/BBBB ST
The response uses 16-bit color components (four hex digits per channel), regardless of the terminal's internal color precision.
Description
Per the XTerm control sequences documentation, OSC 4 allows dynamic modification of the terminal's color palette. The color specification uses X11 color syntax, most commonly rgb:RR/GG/BB where each component is a hexadecimal value. Some terminals also accept rgb:RRRR/GGGG/BBBB (16-bit components) or X11 color names.
Multiple color assignments can be chained in a single sequence by providing additional index/spec pairs separated by semicolons:
OSC 4 ; c1 ; spec1 ; c2 ; spec2 ST
The 256-color palette is organized as:
- 0-7: Standard colors (black, red, green, yellow, blue, magenta, cyan, white)
- 8-15: Bright/high-intensity variants
- 16-231: 6x6x6 color cube
- 232-255: Grayscale ramp
Changes made with OSC 4 affect only the current terminal session and are not persisted. Use OSC 104 to reset palette entries to their default values.
Examples
# Set color index 1 (red) to a bright orange
printf '\e]4;1;rgb:ff/80/00\e\\'
# Query the current value of color index 0 (black)
printf '\e]4;0;?\e\\'
# Set multiple colors in a single sequence
printf '\e]4;0;rgb:00/00/00;1;rgb:cc/00/00;2;rgb:00/cc/00\e\\'
# Set color 196 to pure red
printf '\e]4;196;rgb:ff/00/00\a'
Specifications
| Specification | Section |
|---|---|
| XTerm ctlseqs | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✓ | Yes | Listed as IMPLEMENTED in escape_support.md:98 |
| Bobcat | ? | ? | Would be handled by underlying TerminalCtrl library, not directly in Bobcat code |
| contour | ✓ | v0.2.0.171_rc2 | Change/query color palette entries |
| foot | ✓ | Yes | Query/change palette entry, osc.c:1310-1370 |
| Ghostty | ✓ | v1.0.0 | |
| iTerm2 | ✓ | v20260216-nightly | |
| Kitty | ✓ | Yes | Change/query color palette entry |
| Konsole | ✓ | Yes | ReportColors enum value 4 in src/Vt102Emulation.h:190, handled in src/Vt102Emulation.cpp:1200-1222 |
| mintty | ✓ | Yes | Implemented at termout.c:4687, change/query color palette entries |
| mlterm | ✓ | rel-2_9_1 | |
| PuTTY | ~ | Yes | Query only (OSC 4;n;?) supported; setting colors not implemented |
| Rio | ✓ | v0.0.28 | Supports both changing and querying with '?' for palette indices |
| rxvt-unicode | ✓ | rxvt-unicode-2.0 | Supports querying and setting palette colors |
| st | ✓ | 0.8.5 | Supports both set and query operations |
| terminology | ✗ | No | Acknowledged but not implemented |
| VT100 | ✗ | No | |
| VTE | ✓ | Yes | OSC 4 (XTERM_SET_COLOR) handled in vteseq.cc |
| WezTerm | ✓ | Yes | OSC 4 ChangeColorNumber with query support - see wezterm-escape-parser/src/osc.rs:46,201-224,364,462 |
| Windows Terminal | ✓ | Yes | SetColor case with SetColorTableEntry/RequestColorTableEntry support |
| xterm | ✓ | Yes | OSC 4 changes/queries ANSI color palette entries (OSC_SetAnsiColor in misc.c:3484) |
| xterm.js | ✓ | 4.10.0 | |
| Multiplexers | |||
| cy | ✓ | Yes | |
| GNU Screen | ✗ | No | |
| tmux | ✓ | 3.3 | Set and query palette entries |
| tuios | ✗ | No | |
| Zellij | ✓ | v0.16.0 | |
See also
- OSC 104 — Reset Color Palette — Resets palette entries to their default values
- OSC 10 — Set Default Foreground Color — Sets the default foreground (text) color
- OSC 11 — Set Default Background Color — Sets the default background color