^[control-codes live in libghostty-vt

Operating system commands

OSC 1337 iTerm2 Extensions

iTerm2's own commands: inline images, marks, user variables, the clipboard and the working directory, and its other OSC extensions.

OSC 1337 ; Pt ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
Specification
Proprietary Escape Codes, iTerm2 documentation

iTerm2, the macOS terminal, puts most of its own commands under one OSC number, 1337, as OSC 1337 ; Key=value ST; it used OSC 50 once, and moved because xterm uses 50 for fonts. Their definition is iTerm2’s Proprietary Escape Codes page. Some of the ones programs use most:

PtDoeslibghostty-vt
CurrentDir=dirreport the shell’s working directorykept, as OSC 7
Copy=:base64put text on the clipboardpassed to the host, as OSC 52
File=args:base64show a file, usually an image, inline in the textignored
SetMarkset a mark to jump back toignored
SetUserVar=name=base64set a variable iTerm2 can show, such as in a tab titleignored
RemoteHost=user@hostreport the user and host the shell is onignored
ShellIntegrationVersion=nreport the version of iTerm2’s shell integrationignored
CursorShape=n0 block, 1 bar, 2 underline, from Konsoleignored
ReportCellSizeask for a cell’s size in points; answered OSC 1337 ; ReportCellSize=h;w;scale STnot answered
ReportVariable=base64ask for one of iTerm2’s variablesnot answered
ClearScrollbackerase the scrollbackignored
StealFocus, RequestAttention=yesbring the window forward, bounce the dock iconignored
SetProfile=name, SetColors=key=valuechange the session’s profile or colorsignored
CopyToClipboard=name … EndCopycopy all the text in between to the clipboardignored
SetBadgeFormat=base64, SetKeyLabel=key=valuethe badge, the Touch Bar’s labelsignored
UnicodeVersion=nchoose Unicode 8’s or 9’s character widthsignored

The page lists more, such as annotations, blocks and buttons, and Custom=id=secret:pattern for sequences a script defines itself. libghostty-vt recognizes every key it lists, without regard to case, and acts on the two above; it consumes the rest without doing anything.

iTerm2 has a few extensions outside 1337 as well:

SequenceDoeslibghostty-vt
OSC 4 ; -1 ; ? ST, OSC 4 ; -2 ; ? STask for the default foreground and background, through the palette querynot answered
OSC 6 ; 1 ; bg ; red ; brightness ; n STcolor the tab; the same for green and blueignored
OSC 21337 ; status=text STset the tab’s status line and indicatorignored
OSC P n rrggbb STchange a color, the Linux console’s wayignored

and it documents others that this site gives pages of their own: notifications with OSC 9, progress with OSC 9 ; 4, FinalTerm’s shell integration marks with OSC 133, hyperlinks, and its answer to XTVERSION, iTerm2 and its version.

A default xterm has none of these and ignores them (the OSC numbers it knows). OSC 6 is xterm’s own, for turning its special colors on and off, but iTerm2’s string does not parse as that and changes nothing (do_osc); OSC 4 ; -1 is a negative color number, where xterm stops (ChangeAnsiColorRequest). The cases follow xterm, so the one where libghostty-vt keeps the working directory is a known difference.

Validation

ITERM2-1: The working directory

\e]1337;CurrentDir=/home/user\a
|______|
pwd ""

ITERM2-2: The clipboard changes nothing on screen

A
\e]1337;Copy=:SGVsbG8=\a  # "Hello"
B
|AB____|
cursor 1,3
reply none

ITERM2-3: The rest are consumed

A
\e]1337;SetMark\a
\e]1337;SetUserVar=name=dmFsdWU=\a
\e]1337;RemoteHost=user@example.com\a
\e]1337;CursorShape=1\a
\e]1337;File=inline=1:SGVsbG8=\a
B
|AB____|
cursor 1,3
reply none

ITERM2-4: Questions are not answered

\e]1337;ReportCellSize\a
\e]1337;ReportVariable=c2Vzc2lvbi5uYW1l\a
\e]4;-1;?\a
|______|
reply none

ITERM2-5: Tab colors and status

A
\e]6;1;bg;red;brightness;255\a
\e]21337;indicator=#ff0000;status=busy\a
B
|AB____|
cursor 1,3

ITERM2-6: OSC P does not change a color

\e]Pg4040ff\e\\  # the foreground, the Linux console's way
\e]10;?\a
|______|
reply \e]10;rgb:0000/0000/0000\a
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.