OSC 133
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)
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:
| Marker | Name | Description |
|---|---|---|
A | Prompt start | Marks the beginning of the shell prompt. |
B | Command start | Marks the end of the prompt and beginning of user input. Also sent when the user presses Enter (the command line is finalized). |
C | Output start | Marks the end of user input and beginning of command output. |
D | Command end | Marks 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:
A-- Shell prints the prompt- (prompt text appears)
B-- User has typed a command and pressed EnterC-- Command begins executing, output follows- (command output appears)
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, andPROMPT_COMMANDto emit markers at the appropriate points - Zsh: Uses
precmdandpreexechooks - Fish: Uses
fish_promptandfish_preexec/fish_postexecevents
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
| Specification | Section |
|---|---|
| VS Code Shell Integration | — |
Terminal support
| Terminal | Support | Version | Notes |
|---|---|---|---|
| Terminal Emulators | |||
| Alacritty | ✗ | No | |
| Bobcat | ? | ? | Would be handled by underlying TerminalCtrl library, not directly in Bobcat code |
| contour | ✓ | v0.1.0 | OSC 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 | ✓ | Yes | FinalTerm semantic zones (FTCS_PROMPT, FTCS_COMMAND_START, FTCS_COMMAND_EXECUTED, FTCS_COMMAND_FINISHED) |
| Ghostty | ✓ | v1.0.0 | Shell integration semantic prompts |
| iTerm2 | ✓ | Yes | FinalTerm shell integration via XTERMCC_FINAL_TERM token |
| Kitty | ✓ | 0.24.0 | Part of shell integration feature |
| Konsole | ✓ | Yes | Fully supports FinalTerm semantic prompts with REPL mode tracking for prompt (A/N/P), input (B), output (C), and completion (D) |
| mintty | ✗ | No | No implementation found for OSC 133 shell integration |
| mlterm | ✗ | No | |
| PuTTY | ✗ | No | |
| Rio | ✗ | No | Shell integration markers are documented as not implemented (commented out in docs) |
| rxvt-unicode | ✗ | No | |
| st | ✗ | No | |
| terminology | ✗ | No | |
| VT100 | ✗ | No | |
| VTE | ✓ | Yes | Full iTerm2 shell integration support (A/B/C/D/L modes) |
| WezTerm | ✓ | 20210203-095643-70a364eb | FinalTerm semantic zones for shell integration |
| Windows Terminal | ✓ | Yes | Supports FinalTerm sequences A, B, C, D for shell integration |
| xterm | ✗ | No | Shell integration (FinalTerm semantic zones) not implemented |
| xterm.js | ✗ | No | |
| Multiplexers | |||
| cy | ✓ | v1.10.0 | |
| GNU Screen | ✗ | No | |
| tmux | ✓ | 3.4 | |
| tuios | ✗ | No | |
| Zellij | ✗ | No | No OSC 133 shell integration support found |
See also
- OSC 7 — Current Working Directory — Report the shell's working directory to the terminal