---
title: "Bring your Rex agents back"
description: "I run a dozen coding agents in Rex, one per tab. A small Lua script puts each one back on its own session after a server update."
pubDate: "2026-11-20"
---

I've been using [Rex](https://www.superlogical.com/rex) lately, a terminal with a CLI and a Lua API. I run about a dozen coding agents in it at once, each in its own tab. One agent coordinates. It opens tabs, starts agents in them, hands out the work and reads what comes back. I have Rex on macOS, Linux and iOS, with the Mac app on the Bleeding Edge channel, so updates come often.

Rex comes in two parts, the app you look at and a server that runs the terminals behind it. When the app updates, the server keeps every program going. When the server updates, the tabs come back but the agents in them are gone, and each tab sits at a bare shell.

`claude --continue` brings back the newest session in a folder. That works for one tab. With two agents on the same repo, both tabs get the same session, and with twelve tabs it's a lot of retyping.

## Rex already knows what each tab runs

Claude Code and [pi](https://github.com/badlogic/pi-mono) report their status to Rex as they work, and Rex lets a Lua script listen. So I wrote [agent-resume.lua](https://github.com/bitbonsai/rex-scripts). It runs in the background, and each time an agent reports in, it saves which session that tab has open. For Claude Code the session ID is in `~/.claude/sessions/<pid>.json`.

When the server comes back from an update, the script waits for each tab's shell, then types the resume command into it, the same way I would:

```sh
cd -- '/Users/me/project' && \
  claude --resume <session-id> \
  --permission-mode auto \
  '<prompt>'
```

The prompt at the end is a short note to the agent. It says Rex restarted, so a turn may have been cut off and any background tasks it had started are gone. The agent checks its own transcript, picks the turn back up and restarts what it still needs. If nothing was running, it says so in one line.

## Twelve tabs in 8 seconds

The last update took the server from `preview.21` to `preview.22`. Eight seconds after the new server started, all twelve tabs were back on their own sessions, in the same permission mode as before. The tab where I wrote the script was one of them, and the first thing in it was the note.

That changes when I update. I install a new build when it shows up, and the agents carry on where they were.

## Try it

The script and the `init.lua` snippet that starts it are at [bitbonsai/rex-scripts](https://github.com/bitbonsai/rex-scripts). The [`README`](https://github.com/bitbonsai/rex-scripts#readme) walks through setup and a dry run that prints what it would type, without typing anything. It works with Claude Code and pi. Pi doesn't keep a file per process, so the script takes the newest session in the tab's folder, and two pi agents in the same folder can swap. I've run it on macOS with Rex `0.1.0-preview.22`.

I wrote it with Claude Code, in one of the tabs it now brings back. <img src="/claude-hammer.gif" alt="Pixel-art Claude Code mascot swinging a hammer" width="49" height="32" loading="lazy" style="display: inline; vertical-align: middle; margin: 0 0 0 0.25rem;" />
