Skip to main content

OSC 133

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 133 marks semantic zones in the terminal output, enabling the terminal to distinguish between prompts, user input, and command output. Originally designed for the FinalTerm terminal emulator, this protocol has been adopted by VS Code's integrated terminal, kitty, WezTerm, and iTerm2.

Syntax​

OSC 133 ; A ST              Prompt start
OSC 133 ; B ST Command start (end of prompt / input begins)
OSC 133 ; C ST Output start (command is executing)
OSC 133 ; D ; exitcode ST Command finished with exit code
OSC 133 ; D ST Command finished (no exit code)
Formal syntax
OSC133-A  = 0x1b, "]", "133", ";", "A", ( 0x07 | 0x1b, "\\" ) ;
OSC133-B  = 0x1b, "]", "133", ";", "B", ( 0x07 | 0x1b, "\\" ) ;
OSC133-C  = 0x1b, "]", "133", ";", "C", ( 0x07 | 0x1b, "\\" ) ;
OSC133-D  = 0x1b, "]", "133", ";", "D", [ ";", exitcode ], ( 0x07 | 0x1b, "\\" ) ;
exitcode  = [ "-" ], digit, { digit } ;
digit     = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

Parameters​

The four zone markers define the boundaries of a command lifecycle:

MarkerNameDescription
APrompt startMarks the beginning of the shell prompt.
BCommand startMarks the end of the prompt and beginning of user input. Also sent when the user presses Enter (the command line is finalized).
COutput startMarks the end of user input and beginning of command output.
DCommand endMarks the end of command output. Optionally followed by ;exitcode to report the command's exit status.

Description​

Shell integration via OSC 133 allows the terminal to understand the structure of an interactive shell session. A typical command cycle looks like:

  1. A -- Shell prints the prompt
  2. (prompt text appears)
  3. B -- User has typed a command and pressed Enter
  4. C -- Command begins executing, output follows
  5. (command output appears)
  6. D;0 -- Command finished with exit code 0

With this information, the terminal can provide features such as:

  • Command navigation -- Jump between prompts using keyboard shortcuts
  • Output selection -- Select the output of a specific command
  • Exit code decoration -- Show success/failure indicators on the prompt
  • Scrollback marks -- Mark each command in the scrollback for quick access
  • Command-aware copy -- Copy only a command's output, excluding the prompt

Shell configuration​

Shell integration requires the shell to emit these markers. Most implementations inject the markers through shell hooks:

  • Bash: Uses PS0, PS1, and PROMPT_COMMAND to emit markers at the appropriate points
  • Zsh: Uses precmd and preexec hooks
  • Fish: Uses fish_prompt and fish_preexec/fish_postexec events

VS Code, kitty, WezTerm, and iTerm2 each provide their own shell integration scripts that set up these hooks automatically.

Additional parameters​

Some implementations extend the A marker with key-value parameters. For example, VS Code uses OSC 133 ; A ; cl=m ST to indicate a multi-line prompt. These extensions are terminal-specific and not part of the original FinalTerm specification.

Examples​

# Minimal bash integration using PROMPT_COMMAND and PS0
__prompt_command() {
local exit_code=$?
# Mark end of previous command
PS1='\[\e]133;D;'$exit_code'\a\]'
# Mark prompt start
PS1+='\[\e]133;A\a\]'
# Actual prompt content
PS1+='\u@\h:\w\$ '
# Mark command start (after prompt)
PS1+='\[\e]133;B\a\]'
}
PROMPT_COMMAND=__prompt_command
# PS0 marks output start when a command is executed
PS0='\e]133;C\a'

Specifications​

SpecificationSection
VS Code Shell Integration—

Terminal support​

TerminalSupportVersionNotes
Terminal Emulators
Alacritty✗No
Bobcat??Would be handled by underlying TerminalCtrl library, not directly in Bobcat code
contour✓v0.1.0OSC 133 shell integration (SEMA) is implemented in Functions.h line 648, handled via processShellIntegration() in Screen.cpp line 4057, supporting prompt markers (A, B, C, D)
foot✓YesFinalTerm semantic zones (FTCS_PROMPT, FTCS_COMMAND_START, FTCS_COMMAND_EXECUTED, FTCS_COMMAND_FINISHED)
Ghostty✓v1.0.0Shell integration semantic prompts
iTerm2✓YesFinalTerm shell integration via XTERMCC_FINAL_TERM token
Kitty✓0.24.0Part of shell integration feature
Konsole✓YesFully supports FinalTerm semantic prompts with REPL mode tracking for prompt (A/N/P), input (B), output (C), and completion (D)
mintty✗NoNo implementation found for OSC 133 shell integration
mlterm✗No
PuTTY✗No
Rio✗NoShell integration markers are documented as not implemented (commented out in docs)
rxvt-unicode✗No
st✗No
terminology✗No
VT100✗No
VTE✓YesFull iTerm2 shell integration support (A/B/C/D/L modes)
WezTerm✓20210203-095643-70a364ebFinalTerm semantic zones for shell integration
Windows Terminal✓YesSupports FinalTerm sequences A, B, C, D for shell integration
xterm✗NoShell integration (FinalTerm semantic zones) not implemented
xterm.js✗No
Multiplexers
cy✓v1.10.0
GNU Screen✗No
tmux✓3.4
tuios✗No
Zellij✗NoNo OSC 133 shell integration support found

See also​