Skip to main content
ansicode

OSC 12 — Set cursor colour (and query)

Override the terminal's cursor colour, or query the current value via the OSC reply.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b]12;#RRGGBB\x07 (set) \x1b]12;?\x07 (query)
\\033[\033]12;#RRGGBB\007
\\e[\e]12;#RRGGBB\a
ESC [ESC ] 12 ; COLOR BEL
hex1b 5d 31 32 3b ... 07

Description

OSC 12 sets the colour of the text cursor (the block / bar / underline drawn at the input position). The colour argument accepts the same syntaxes as OSC 10 / 11: #RRGGBB, #RGB, rgb:RRRR/GGGG/BBBB, or X11 colour names. Sending ? instead of a colour (\x1b]12;?\x07) makes the terminal reply with the current cursor colour using the same syntax — used by themes and :set background=... autodetect tools to query the live palette. Reset the cursor colour back to the user's terminal default with OSC 112 (\x1b]112\x07). Distinct from cursor SHAPE (\x1b[? q — DECSCUSR) and cursor VISIBILITY (\x1b[?25h/l), which control glyph and on/off — OSC 12 only changes the colour.

Spec citation: xterm-ctlseqs (OSC 12 / 112)

Examples

bash
printf '\033]12;#f38ba8\007'   # set cursor to pink\nprintf '\033]12;?\007'         # query current cursor colour
python
import sys; sys.stdout.write('\x1b]12;#f38ba8\x07')
go
fmt.Print("\x1b]12;#f38ba8\x07")
javascript
process.stdout.write('\x1b]12;#f38ba8\x07')
c
printf("\x1b]12;#f38ba8\x07");

Used in

Real-world tools that emit this sequence — anchors the bytes to commands you've already used.

  • neovim cursor-shape themesthemes set `:hi Cursor guibg=...` then drive OSC 12 via `:set guicursor` mappings so the cursor recolours per insert / normal / visual mode without redrawing the screen
  • fish_vi_cursorfish's vi-mode emits `\x1b]12;<colour>\x07` on mode change so the cursor flashes orange in command mode, white in insert — surfaces vi state at a glance
  • kitty, wezterm per-mode cursor overrideskitty's `cursor_text_color` and wezterm's `colors.cursor_fg/bg` accept dynamic OSC 12 from the running shell — `tmux` / `nvim` can override the terminal default per pane on entry
  • tmux `set -g cursor-color`tmux passes through OSC 12 from the active pane, so a per-pane cursor colour reflects the foreground program (vim red, fish white) instead of a single terminal-wide colour
  • terminator, konsole config-file cursor colourGTK terminals read the cursor colour from a profile file, but accept OSC 12 at runtime as a per-session override — useful for SSH sessions that should signal a remote host visually

Terminal support

xterm
yes
Linux console (fbcon)
no
macOS Terminal.app
partial
iTerm2
yes
Windows Terminal
partial
cmd.exe / ConPTY
no
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
yes
GNU screen
yes

Related sequences