Definition

ANSI escape codes

ANSI escape codes are control sequences that terminals interpret for colors, cursor movement, and screen clearing — the language of every modern CLI UI.

ANSI escape codes (also called VT sequences or CSI codes) are control sequences that terminals interpret to change colors, move the cursor, clear the screen, set text attributes, and much more. They're the control language every modern terminal understands — the reason ls produces colored output and htop can redraw in place.

Why it matters

Every CLI UI you've ever seen — progress bars, colored output, interactive prompts, TUI apps like vim or btop, streaming output from Claude Code — works by emitting ANSI sequences. A terminal that doesn't support them displays garbled output like ESC[31m instead of red text. A PTY or ConPTY transports these sequences from the running program to the terminal renderer.

SpaceSpider uses @xterm/xterm as its renderer, which implements a large subset of VT100, VT220, and xterm-specific extensions. That's what lets Claude Code, Codex CLI, and plain shells render identically inside a pane as they would in a native terminal.

How it works

An ANSI escape code starts with the ESC character (0x1B), usually followed by [ (the Control Sequence Introducer or CSI). Common sequences:

  • ESC[0m — reset all attributes
  • ESC[1m — bold
  • ESC[31m — red foreground
  • ESC[38;5;208m — 256-color mode, orange
  • ESC[38;2;255;165;0m — true color (24-bit RGB)
  • ESC[H — move cursor to home (top-left)
  • ESC[2J — clear screen
  • ESC[?25l — hide cursor
  • ESC[?1049h — switch to alternate screen buffer (used by vim, less)

Newer terminals add extensions: true-color (16M palette), hyperlinks via OSC 8, sixel graphics, synchronized output (BSU/ESU), and more. Cross-platform behavior varies — the ConPTY compatibility shim is what makes older Windows apps render correctly on modern terminals.

How it's used

Where you'll meet ANSI codes:

  • Building a CLI: pick a library (chalk, colored, termcolor) that wraps the sequences
  • Debugging terminal output: cat -v shows literal escape characters
  • Writing a terminal emulator: you parse them
  • Dealing with CI logs: some CI systems strip or mangle colors
  • PTY — the transport that carries ANSI codes
  • ConPTY — the Windows equivalent
  • TTY — the underlying device abstraction
  • Shell — a common producer of ANSI output
  • Windows Terminal — a major ANSI-capable terminal

FAQ

Are ANSI escape codes standardized?

The core set is ECMA-48 / ISO 6429, dating back to the 1970s VT100. Beyond that, extensions are de-facto standards — xterm's behaviors are what most terminals implement.

Why do my logs show [31m instead of red text?

Your terminal or viewer is passing the escape sequence through literally instead of interpreting it. That usually means either a non-ANSI-capable viewer or NO_COLOR handling. In SpaceSpider panes it should always render correctly.

Related terms