^[control-codes
live in libghostty-vt

Operating system commands

OSC 1337 iTerm2 Extensions

View as Markdown

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 and the pages it links to:

PtDoeslibghostty-vt
AddAnnotation=messageattach a note to the text at the cursor, and show itignored
AddHiddenAnnotation=messageattach a note without showing itignored
Block=id=name;attr=startmark where a block of text starts, or with attr=end ends, for folding and copy buttonsignored
Button=type=copy;block=nameadd a button that copies a block; type=custom adds one that sends a code backignored
Capabilitiesask which features the terminal has; answered OSC 1337 ; Capabilities=features ST, from iTerm2’s feature reporting protocolnot recognized; ignored, so not answered
ClearCapturedOutputerase the output captured from the last commandignored
ClearScrollbackerase the scrollbackignored
Copy=:base64put text on the clipboardpassed to the host, as OSC 52
CopyToClipboard=namecopy all the text that follows to a clipboard, until EndCopyignored
CurrentDir=dirreport the shell’s working directorykept, as OSC 7
CursorShape=n0 block, 1 bar, 2 underline, from Konsoleignored
Custom=id=secret:patterna sequence a script defines itselfignored
Disinterbring back a session that was buriedignored
EndCopyend CopyToClipboardignored
File=args:base64show a file, usually an image, inline in the text, or download itignored
FileEndend a file sent with MultipartFileignored
FilePart=base64one piece of a file sent with MultipartFileignored
HighlightCursorLine=yesshow or hide the cursor guide, a highlight on the cursor’s lineignored
MultipartFile=argsstart a file sent in pieces, as File does at once, for tmuxignored
OpenURL=:base64ask to open a URL, with the user’s permissionignored
PopKeyLabelsrestore the Touch Bar’s labels from the stackignored
PushKeyLabelssave the Touch Bar’s labels on a stackignored
RemoteHost=user@hostreport the user and host the shell is onignored
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
RequestAttention=yesbounce the dock icon; once, no, or fireworks at the cursorignored
RequestUpload=format=tgzask the user for files to uploadignored
SetBackgroundImageFile=base64show a picture behind the text, with the user’s permissionignored
SetBadgeFormat=base64set the badge, text drawn in the corner of the sessionignored
SetColors=key=valuechange one of the session’s colorsignored
SetKeyLabel=key=valuelabel a Touch Bar keyignored
SetMarkset a mark to jump back toignored
SetProfile=namechange the session’s profileignored
SetProfileProperty=key=base64change one setting of the session’s profile, given as JSONnot recognized; ignored
SetUserVar=name=base64set a variable iTerm2 can show, such as in a tab titleignored
ShellIntegrationVersion=nreport the version of iTerm2’s shell integrationignored
StealFocusbring the window forwardignored
UnicodeVersion=nchoose Unicode 8’s or 9’s character widthsignored
UpdateBlock=id=name;action=foldfold or unfold a blocknot recognized; ignored

That is every key iTerm2 documents, in its Proprietary Escape Codes page and in the pages it sends a reader to for images, badges and feature reporting. libghostty-vt recognizes all but three, without regard to case, and acts on two, Copy and CurrentDir; it consumes the rest without doing anything. The three it does not know, Capabilities, SetProfileProperty and UpdateBlock, are newer, and it ignores them all the same.

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 blue; see OSC 6ignored
OSC 21337set the tab’s status text and indicatorignored
OSC Pchange 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.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aNoignored
libghostty-vt0f171f6Partlyacts on Copy and CurrentDir and consumes the rest (ITERM2-1)
Konsole26.11.70, a24c3d71Partlyonly inline images (File, MultipartFile) and ReportCellSize
iTerm23.7.3, its documentationYesProprietary Escape Codes
ConEmubuild 230724, its documentationNonot in its ANSI escape codes

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

A
\e]6;1;bg;red;brightness;255\a
B
|AB____|
cursor 1,3

ITERM2-6: Newer keys are ignored too

A
\e]1337;Capabilities\a
\e]1337;SetProfileProperty=Cursor Type=Mg==\a
\e]1337;UpdateBlock=id=b;action=fold\a
B
|AB____|
cursor 1,3
reply none
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.