A session from the command line
December 04, 2026
At the end, six commands build the session that smug start v4 builds, and you know which smug field each command replaces.
Before you start
From memory
From lesson 1: write the three levels of Rex, largest first. Then write the four ways in which Rex matches a target, in order.
Your smug file, field by field
This is ~/.config/smug/v4.yml:
session: i4o-v4
root: ~/Work/v4.i4o.dev
windows:
- name: code
layout: even-horizontal
commands:
- gitty
panes:
- commands:
- vp i
- vp run dev
- name: agents
layout: main-vertical
commands:
- claudeThree rex commands make things (Shell Scripting). rex new makes a session with one window and one terminal. rex window new adds a window to a session. rex split splits a block. A fourth command, rex send, types into a terminal.
| smug field | What it means | Rex command |
|---|---|---|
session: i4o-v4 | The name of the session | rex new i4o-v4 |
root: | The directory of each pane | --cwd DIR on each command that makes a terminal |
windows: - name: code | A window and its name | --window code on rex new for the first window, then rex window new for each other one |
panes: | More panes in the window | rex split, one time for each more pane |
commands: | Lines that smug types into the pane | rex send |
layout: even-horizontal | Panes side by side | rex split puts the new block on the right by default |
Two ways to start a program
You can give a command after --, as in rex new work -- htop. Then the terminal runs that command in place of a shell. The command gets the environment of your login shell, so PATH applies. It does not get your interactive configuration, so an alias or a function from ~/.zshrc does not exist there (CLI Commands, rex new). When the command exits, the pane closes, unless you add --keep-open.
Or you can start a shell and type into it with rex send. An alias works, because your shell reads the line. When the program exits, you are back at the prompt. This is what smug does with commands:. So this lesson uses rex send.
Do it
Do these steps in a Rex pane. Each command prints an ID or nothing.
See what your commands are
type gitty vp claudeFor each name, zsh says if it is an alias, a function or a file. An alias or a function works only when a shell reads the line.
Make the session and its first window
rex new i4o-v4 --cwd ~/Work/v4.i4o.dev --window codeThe command prints the ID of the new session. The docs do not say if the app moves to the new session. If yours did not, press Cmd+K and pick
i4o-v4(Mac Actions).Type into the first pane
rex send -s i4o-v4 -w code $'gitty\n'rex sendadds no newline. In zsh,$'...'turns\ninto a real newline, so the shell in that pane runs the line.Add the second pane and type into it
rex split -s i4o-v4 --cwd ~/Work/v4.i4o.dev --label dev rex send -s i4o-v4 -b dev $'vp i\nvp run dev\n'--label devgives the new block a label. The next command uses that label as its target. The two lines go into one shell, sovp run devstarts aftervp iends. Your YAML does the same.Add the second window
rex window new -s i4o-v4 agents --cwd ~/Work/v4.i4o.dev --focus=false rex send -s i4o-v4 -w agents $'claude\n'--focus=falseleaves thecodewindow in front.Look, from outside
rex window ls -s i4o-v4 rex capture -s i4o-v4 -b dev --trimThe second command prints what the dev server wrote. You read a pane in a session that you are not looking at.
You now have this, and each part has a name that you gave it.
session: i4o-v4
window 1: code
window 2: agents
Predict, then test
Run the first command one more time:
rex new i4o-v4 --cwd ~/Work/v4.i4o.dev --window codeBefore you press Enter, write down what you expect: an error, the old session, or a second session. Then run rex ls.
After that, run rex send -s i4o-v4 -w code hello and read the message and the exit status (echo $?). Use lesson 1 to explain what you see. To clean up, end the session that you do not want by its short ID, which rex ls prints: rex kill <short ID>.
Keep it as a script
Put the six commands in a file, for example ~/.config/rex/v4.sh, with #!/bin/sh on the first line. End the session with rex kill i4o-v4, then run the file. This is smug start v4 with no smug.
The file has limits. It does not stop when a command fails. It finds the panes by label, and you saw what happens when a label is there two times. And it is one more file for each project, which is the problem that you want to remove. The Rex docs say to use Lua for more than a few commands in sequence (Shell Scripting). Lessons 4 and 5 do that.
Check yourself
Check yourself
Answer from memory. Do not scroll up first.
gitty is a zsh alias. Why can rex new x -- gitty fail?
What does rex send add after the text?
Which smug field does --cwd replace?
Two sessions have the label i4o-v4. You run rex kill i4o-v4. What happens?
0 of 4 answered
Primary source
Read "Keeping Track of IDs" and "Building a Layout". The page shows how a script keeps an ID with --json and jq. You do not need that today, but it is the reason for the Lua in lesson 4. The commands of this lesson are in the CLI sheet.
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 3, your prefix key.