What Is OSC in a Terminal?

OSC = Operating System Command, a family of terminal control sequences that lets programs change terminal emulator state.

Table of Contents

  1. What OSC Means
  2. What An OSC Sequence Looks Like
  3. How It Differs From Shell Commands And CSI
  4. Common Uses
  5. Security Notes
  6. Short Summary

1. What OSC Means

In terminal, terminal emulator, xterm, and VT control sequence contexts, OSC means Operating System Command.

It is not a normal command typed into a shell. It is a special byte sequence written to the terminal output stream. The terminal emulator interprets it as an instruction for terminal state instead of rendering it as ordinary text.

For example, command-line programs can use OSC to set the window title, emit clickable terminal hyperlinks, query or change colors, write to the clipboard, or tell the terminal the current working directory.

2. What An OSC Sequence Looks Like

The common 7-bit form is:

ESC ] command ; data BEL

Where:

Example: set a terminal title.

printf '\033]0;Demo Title\a'

A supporting terminal will not print ]0;Demo Title. It will set the window title to Demo Title.

3. How It Differs From Shell Commands And CSI

ConceptTypical FormInterpreted ByPurpose
Shell commandls, cd, git statusThe shell or an executable programRun programs, read files, write files, start processes
CSI sequenceESC [ 31mThe terminal emulatorMove the cursor, set text color, clear the screen
OSC sequenceESC ] 0 ; title BELThe terminal emulatorSet titles, color tables, hyperlinks, clipboards, and other string-oriented terminal state

As a rough rule: CSI is common for display control inside the screen, such as color, cursor movement, and clearing; OSC is common for terminal emulator state and extensions, such as titles, palettes, clipboards, and hyperlinks.

4. Common Uses

OSC 0 / OSC 2: Set The Window Title

printf '\033]0;project: api-server\a'
printf '\033]2;project: api-server\a'

Shell prompts, SSH helpers, and terminal integrations often use these to show the current host, directory, or task.

OSC 4: Set Or Query Palette Colors

# Exact support depends on the terminal emulator.
printf '\033]4;1;rgb:ff/00/00\a'

This family of sequences is used for terminal color table operations. Support differs across terminals.

OSC 8: Terminal Hyperlinks

printf '\033]8;;https://example.com\aExample\033]8;;\a'

Terminals that support OSC 8 display Example as a clickable link.

OSC 52: Clipboard

# SGVsbG8= is Base64 for "Hello".
printf '\033]52;c;SGVsbG8=\a'

OSC 52 can write content to the clipboard. Because it affects user clipboard state, many terminals disable it, limit it, or require explicit user configuration.

5. Security Notes

OSC means that terminal output can trigger terminal behavior. Untrusted text printed directly to a terminal may do more than display characters.

6. Short Summary

OSC is the terminal control sequence family for string-oriented terminal commands: a program writes ESC ] ... BEL, and the terminal emulator may use it to set titles, links, colors, clipboards, and related state.

References