Shell
Locates and starts the Codex executable as the foreground process.
codex + argumentslong-running Codex processA command such as ls runs briefly, writes output, and exits. Codex is different: it stays alive, accepts keys continuously, talks to model services, launches tools, and repeatedly redraws a terminal UI.
This lesson separates systems that are easy to blur together.
From a shell prompt you run:
codexThe shell parses one command and starts the Codex process on the same PTY slave. While Codex owns the terminal foreground, the shell waits. Ghostty does not become “an AI terminal.” It still transports input bytes and interprets output bytes.
A sports network switches from a short report to a live show with its own producer and continuously changing graphics.
Locates and starts the Codex executable as the foreground process.
codex + argumentslong-running Codex processA shell commonly begins in canonical mode: the kernel collects and edits a line, echoes characters, and delivers the completed line after Enter.
A TUI usually wants keys immediately. It changes terminal settings so arrows, Backspace, Escape, and ordinary characters arrive without line buffering. This is commonly called raw mode, although actual programs may selectively keep or disable individual terminal flags.
The key path is:
keyboard hardware→ OS/window-system event→ GTK or AppKit→ Ghostty key representation→ Ghostty terminal encoding→ PTY master→ PTY slave→ Codex input loopsrc/input/key_encode.zig:1–90Notice the inputs needed beyond a key name: modifiers, action, text, and active terminal modes.The terminal application can request different keyboard protocols. Therefore a native key event cannot simply be copied into the PTY unchanged.
Many TUIs request the alternate screen. Conceptually, Ghostty keeps the normal shell screen and gives the application another screen-sized terminal state. When Codex exits cleanly, Ghostty restores the normal screen and your previous prompt/history reappears.
The alternate screen is not another operating-system window or GPU framebuffer. It is another terminal-state model interpreted by Ghostty.
A crash or abrupt disconnect can leave terminal modes looking wrong because the application did not send its normal cleanup sequences. Shells often provide commands such as reset to restore a usable state.
Codex does not send a GUI widget tree to Ghostty. It emits terminal commands:
Ghostty parses those bytes and updates terminal cells. Modern TUIs try to emit only differences, but some operations repaint large regions.
A host asks a question, the show updates its rundown, and the graphics team publishes a changed lower-third.
Ghostty encodes the event under the terminal modes requested by Codex.
native key eventterminal input bytesThe most important architectural separation is this:
Terminal UI path:you ↔ Ghostty ↔ PTY ↔ Codex TUI
Agent/network path:Codex ↔ HTTPS/model serviceCodex ↔ filesystemCodex ↔ tool subprocessesGhostty does not semantically receive the model prompt, token stream, repository diff, or HTTP response. Codex owns those. Codex decides how to represent them as terminal output.
If the network is slow, Codex may keep animating a spinner by emitting terminal updates. Ghostty only sees the spinner frames, not the reason for the wait.
When Codex runs a command, there are several possible arrangements. It may capture a subprocess through ordinary pipes, allocate another PTY for an interactive tool, or communicate through an internal sandbox. Codex then transforms captured results into its application state and TUI output.
Do not assume every tool process writes directly to Ghostty’s PTY. The top-level terminal relationship belongs to Codex; tool I/O architecture belongs to Codex.
Each feature is another negotiated data format across the same PTY relationship.
The shell starts a long-lived foreground Codex process. Codex configures terminal modes, often uses the alternate screen, and runs an input/event loop. Ghostty converts native input to terminal bytes. Codex updates private application state, communicates with models and tools through separate channels, and emits terminal output describing its TUI. Ghostty parses that output, maintains terminal state, shapes text, and renders frames. When Codex exits and restores modes/screens, the waiting shell becomes foreground again and prints another prompt.
A real broadcast network understands shows, teams, and stories. Ghostty has no concept of agents, prompts, or tools. It is the transport/display endpoint for the byte protocol Codex chooses to emit.