Skip to main content

OSC 4

AI-Generated Content
This page was generated with the assistance of AI and may contain inaccuracies. It is intended as a placeholder for future human verification. If you spot issues ahead of its initial review, please report them on GitHub!
Experimental

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
Formal syntax
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​

ParameterDescriptionDefault
cColor palette index (0-255)(required)
specColor 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​

SpecificationSection
XTerm ctlseqs—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✓YesListed 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_rc2Change/query color palette entries
foot✓YesQuery/change palette entry, osc.c:1310-1370
Ghostty✓v1.0.0
iTerm2✓v20260216-nightly
Kitty✓YesChange/query color palette entry
Konsole✓YesReportColors enum value 4 in src/Vt102Emulation.h:190, handled in src/Vt102Emulation.cpp:1200-1222
mintty✓YesImplemented at termout.c:4687, change/query color palette entries
mlterm✓rel-2_9_1
PuTTY~YesQuery only (OSC 4;n;?) supported; setting colors not implemented
Rio✓v0.0.28Supports both changing and querying with '?' for palette indices
rxvt-unicode✓rxvt-unicode-2.0Supports querying and setting palette colors
st✓0.8.5Supports both set and query operations
terminology✗NoAcknowledged but not implemented
VT100✗No
VTE✓YesOSC 4 (XTERM_SET_COLOR) handled in vteseq.cc
WezTerm✓YesOSC 4 ChangeColorNumber with query support - see wezterm-escape-parser/src/osc.rs:46,201-224,364,462
Windows Terminal✓YesSetColor case with SetColorTableEntry/RequestColorTableEntry support
xterm✓YesOSC 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.3Set and query palette entries
tuios✗No
Zellij✓v0.16.0

See also​