Definition

TTY

TTY is the Unix abstraction for a terminal device, inherited from teletypewriters. It defines stdin, stdout, signals, and line discipline for every CLI.

TTY is short for "teletypewriter," the electromechanical devices that were the original user interface to timesharing Unix systems in the 1970s. The name stuck as the abstraction for any character-oriented terminal device the kernel exposes. Today a TTY is usually not a physical machine but a virtual one — either a kernel virtual console (/dev/tty1) or a PTY pair backing a terminal emulator.

Why it matters

The TTY abstraction is what makes CLIs feel the way they do. Line editing, echo, Ctrl+C sending SIGINT, Ctrl+D sending EOF, window resize signals, foreground/background process groups, the distinction between stdout and stderr — all of this is TTY behavior baked into the kernel's line discipline. If you strip the TTY away (by piping to a file), programs drop the interactive features and often switch output format.

For AI-first developer tools like SpaceSpider, this matters because Claude Code, Codex CLI, and Qwen Code all rely on TTY semantics for streaming output, interactive confirmation prompts, and ANSI escape code rendering. Every pane in a SpaceSpider grid layout is a real TTY so these tools behave identically to running them in a native terminal.

How it works

Under the hood, a TTY device file is a kernel endpoint with an associated termios structure. termios holds dozens of flags controlling input canonicalization, output post-processing, control characters (like the current interrupt key), and baud rate (a legacy from actual serial lines). User-space talks to the kernel via tcgetattr/tcsetattr to toggle raw mode, ioctl(TIOCGWINSZ) to read the current size in rows and columns, and standard read/write for data.

The kernel also tracks the TTY's foreground process group, which is the set of processes that receive signals from Ctrl+C, Ctrl+Z, and related keys. This is how a running vim can catch Ctrl+C while a background job doesn't.

isatty(fd) returns true when a file descriptor is connected to a TTY. CLI tools branch on this to decide colorization, paging, and prompt style.

FAQ

What's the difference between a TTY and a PTY?

A TTY is the abstract kernel device; a PTY is a specific flavor of TTY implemented as a master/subordinate pair in software. Every PTY is a TTY, but not every TTY is a PTY (kernel consoles, serial lines, and SSH sessions are also TTYs).

How do I check what TTY a process is attached to?

Run tty inside a shell, or look at ps -o tty for any process. Background daemons show ? because they have no controlling TTY.

Related terms