Skip to content

Scripting sessions

Alto’s commands do from a script or an agent what tmux’s do, against real sessions you can also see in the window.

Terminal window
id=$(alto new -- npm run dev) # start one; prints its id
alto wait "$id" --text 'ready on port \d+' --timeout 60
alto capture "$id" --last 20 # the last lines, as plain text
alto send "$id" --key C-c # press keys
alto kill "$id"
Terminal window
alto wait 3 --until needs-you # idle, working, needs-you, done, or prompt
alto wait 3 --text 'error|panic' --timeout 2m

Exits 0 when it happens (printing what it found), 124 after --timeout, 125 if the session ends. --text is a regular expression over what the program prints from now on; for what’s already on screen, use capture --screen.

Terminal window
alto run 3 -- cargo test # prints only its output, exits with its status
alto run 3 --json -- make lint # {output, exit, truncated, took, timed_out}

run types the command at the session’s prompt, where it shows, and waits for it by the shell’s own marks. See What run gives back.

Terminal window
alto send 3 'git status' --enter
alto send 3 --key Escape # leave insert mode
alto send 3 ':wq' --enter

Keys go by name: Enter, Escape, Tab, Up, PageDown, F5, q, with C-, M- or S- before them (C-c, M-x, S-Tab). Repeat --key for several, pressed in order.

--on DEVICE works with ls, new, attach, send, capture and kill, and with run and wait:

Terminal window
alto --on studio new -- ./train.sh
alto --on studio capture 4 --last 50

See Remote access with Tailscale.

ALTO_HOME=/some/folder keeps a separate server, sessions and settings in that folder, for trying things without touching your own:

Terminal window
export ALTO_HOME=$(mktemp -d)
alto new -- sleep 600
alto ls