Definition

PTY

A PTY is a virtual terminal pair that lets programs talk to each other as if through a physical serial terminal, enabling real shells inside apps.

A PTY (pseudo-terminal) is a pair of virtual character devices — a master and a subordinate — that behave like a real hardware terminal. One process writes to the master, and the other reads from the subordinate as if it were a serial line. This is how xterm, tmux, SSH, and every modern terminal emulator run shells and programs with full TTY semantics.

Why it matters

Most command-line tools check isatty() and change behavior when they think they're connected to a terminal: ls shows colors, git log opens a pager, and AI CLIs like Claude Code stream interactive prompts instead of dumping batched output. Without a PTY, these programs act as if piped to a file — no colors, no interactivity, no line editing.

SpaceSpider spawns one PTY per pane so every CLI you run — claude, codex, qwen, kimi, or your login shell — sees a real terminal and runs in its normal interactive mode. See first-space for how panes map to PTY sessions.

How it works

On Linux and macOS, the kernel provides /dev/ptmx and /dev/pts/N. Calling posix_openpt() allocates a new master/subordinate pair. The master is used by the terminal emulator or host application to send keystrokes and receive output; the subordinate is what the child process inherits as its stdin, stdout, and stderr.

The kernel's line discipline sits between the two ends, handling features like line buffering, echo, backspace editing, and signal generation (Ctrl+C becomes SIGINT). Terminal size is tracked via TIOCSWINSZ ioctls; resizing the host sends SIGWINCH to the child.

On Windows the equivalent is ConPTY, which exposes similar semantics via CreatePseudoConsole. Cross-platform libraries like portable-pty (Rust) and node-pty (Node.js) abstract both.

How it's used

Any application that embeds a terminal — IDEs like VS Code, tools like tmux and Zellij, SSH servers, and terminal multiplexers — uses PTYs. SpaceSpider is no exception: each pane in a grid layout is a PTY bridged to @xterm/xterm in the browser-style renderer.

FAQ

Why not just use pipes?

Pipes lack line discipline, window size, signals, and the isatty() property. Programs detect this and disable interactive features. A PTY preserves the full terminal contract.

Can I see all open PTYs on my system?

On Linux, ls /dev/pts lists subordinate devices. Each open terminal window, tmux pane, or SSH session typically owns one. SpaceSpider's pane count equals the number of PTYs it holds open.

Related terms