Rex

The map

December 04, 2026

At the end, you can point at any part of your Rex screen, say its Rex name, and reach it from the command line.

Why this comes first

In tmux you write -t session:window.pane to say what a command acts on. Rex has the same need. Each rex command and each Lua call in this course acts on a target. This lesson gives you the names of the parts and the rules for a target. The lessons after it use both.

One program in place of two

Today three programs do your terminal work. Ghostty draws the terminal. tmux keeps your programs running and splits the screen. smug builds a tmux session from a YAML file.

Rex is a terminal with two parts: an app, built on the libghostty core, and a multiplexer (What's Rex). The multiplexer is the Rex server. It runs your shells and the programs in them, and it keeps them running when no app is connected. Rex for Mac runs a server for you. The app is a client of that server. The rex command is a client too.

JobTodayIn Rex
Draw the terminalGhosttyThe Rex app
Keep programs running, split the screenThe tmux serverThe Rex server
Change things from a scripttmux commandsThe rex command, and Lua
Build the windows of a projectsmug and a YAML fileLua (lessons 4 to 8)
Your keystmux.conf~/.config/rex/init.lua (lesson 3)

Three levels

Rex groups your work on three levels (What's Rex). You know all three from tmux.

Rex nameWhat it istmux nameIn a smug file
SessionA group of related work, such as one project. It runs if you look at it or not.Sessionsession:
WindowA tab in a session. It holds a layout of blocks.WindowAn item under windows:
BlockA pane in a window. Today each block is a terminal.PaneAn item under panes:

Rex has two words for the second and third level. Commands and Lua say window and block. The app says tab and pane. In this course, a command or a field name uses the first pair, and a sentence about what you see uses the second pair.

Here is the session that your v4.yml makes, drawn with the Rex names.

session: i4o-v4

window 1: code

gitty
vp i vp run dev

window 2: agents

claude
One session, two windows, three blocks.

IDs, labels and targets

Each session, window and block has an ID that does not change. Each can also have a label that you choose. A target is the text that you give a command to say which one you mean. Rex tries to match a target in this order and stops at the first kind that matches (The CLI, targets):

  1. The full ID, for example session:01a10cf3-2655-7e48-9b9c-43dd6612bef5.
  2. A label. Upper case and lower case are the same.
  3. A position, counted from 1. For a window, the position is its place in the tab order.
  4. A short ID: the end of an ID, four characters or more.

Three options carry a target: -s for a session, -w for a window, -b for a block. With none of them, a command acts on the terminal that you typed it in, and on that terminal's session.

If a target matches two things, the command changes nothing, lists the matches, and exits with status 3. Two things can have the same label, and a label can change. So a label is good for work at the keyboard, and an ID is the safe choice in a script.

Do it

  1. Find the rex command

    Open Rex. In a pane, run:

    which rex
    echo "$REX_BIN_DIR"

    Rex puts REX_BIN_DIR at the front of PATH in each terminal that it opens. Your shell start-up files run after that and can put other directories in front. If which rex prints nothing, add this to ~/.zshrc and open a new pane (The CLI, PATH set-up):

    if [ -n "$REX_BIN_DIR" ]; then
        export PATH="$REX_BIN_DIR:$PATH"
    fi
  2. Make a session to practise in

    Press Cmd+N for a new session (Mac Actions). Do the next steps there, so that the labels of your real work stay as they are.

  3. Look at what is there

    rex ls
    rex session inspect
    rex block inspect
    echo "$REX_BLOCK"

    rex ls lists your sessions. The two inspect commands show the session and the block that you are in. REX_BLOCK holds the ID of the terminal's own block. Find that ID in the output of rex block inspect.

  4. Make a second window and a second pane

    Press Cmd+T for a new tab. Press Cmd+D to split the pane to the right (Mac Actions). Then run:

    rex window ls
    rex block ls

    Count the lines. They must agree with what you see.

  5. Give labels

    rex session rename scratch
    rex window rename notes
    rex block rename left

    Each command acts on the session, window or block that you typed it in. Run rex ls and rex block ls again and find the labels.

  6. Reach a pane by its label

    Move to the other pane (Cmd+]). From there, type into the pane with the label left, and read its screen:

    rex send -b left 'echo hello from the other pane'
    rex send-key -b left enter
    rex capture -b left --trim

    rex send types the text and does not press Enter. rex send-key presses a key. rex capture prints the screen of a block (Shell Scripting).

  7. Predict, then test

    In the pane left, start top. Before you do the next part, write down your answer: if you quit the Rex app now, does top stop?

    Quit the app with Cmd+Q. Open it again. Look at the pane.

Check yourself

From memory

Look at your Rex window. Write its parts as a tree: the session, each window in it, each block in each window. Use the labels that you gave.

Check yourself

Answer from memory. Do not scroll up first.

  1. Which part of Rex keeps your programs running when the app is closed?

  2. In which order does Rex try to match a target?

  3. Two blocks have the label logs. You run rex send -b logs hello. What happens?

  4. What does tmux call the thing that Rex calls a block?

0 of 4 answered

Primary source

Rex docs: What's Rex

Short. Read the two sections "The Server and the Apps" and "Sessions, Windows and Blocks". Then keep the glossary and the tmux and smug map open for the next lessons.

Stuck, or curious?

Ask Claude. Paste the output or the error and say what you expected. A follow-up question is part of the lesson, and it tells Claude what to teach next.

Next: lesson 2, a session from the command line.