- Book: AI Agents Pocket Guide
- Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go
- My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
- Me: xgabriel.com | GitHub
Claude Code was halfway through renaming a module across thirty files when you closed the terminal tab to tidy your screen. Twenty minutes into a forty-minute refactor, the process is gone. The same afternoon has other versions: the SSH connection to your dev box drops when the train enters a tunnel, or the terminal app updates itself and restarts.
The conversation usually survives. The running process does not. A plain claude or codex session lives inside the terminal that started it, so the window is the agent's life support.
The fixes stack: keep the process off the window, put it on a machine that stays awake, and when it dies anyway, resume the conversation with the CLI's own flags.
tmux: give the agent a home that isn't the window
tmux runs your shell inside a server process that outlives the terminal you typed into. The tmux manual puts it plainly: each session "is persistent and will survive accidental disconnection." You detach, the agent keeps going, you attach again later.
Start a named session and launch Claude Code inside it with a name of its own:
# create the session, or attach if it already exists
tmux new -A -s auth-refactor
# inside tmux: name the Claude session too
claude -n auth-refactor
Detach with Ctrl-b then d. Close the terminal if you like. From any new terminal:
tmux ls # list sessions
tmux attach -t auth-refactor # back where you left it
The -A flag is the one worth memorising. It makes new-session "behave like attach-session if session-name already exists", so the same command creates the session the first time and reattaches every time after. You can keep it in your shell history and never think about which one you need.

tmux keeps the agent in a server process, so closing the window only closes the view.
One limit: tmux on your laptop sleeps when your laptop sleeps, and its processes pause until the machine wakes. That covers a closed tab or a crashed terminal app, but not a refactor that needs to keep moving while the lid is shut.
Claude Code now has its own version of this. claude --bg "finish the auth refactor" starts a background session and returns at once, printing the session ID. A separate supervisor process runs it, so per the docs you can "close your shell" and the work keeps going. Sessions are preserved across sleep, but "shutting down or restarting your machine stops running background sessions." Reattach with claude attach <id>, peek with claude logs <id>, and list everything with claude agents. Two caveats from the same page: agent view is a research preview, and a session that is finished or waiting on you, with nothing attached, stops on its own after about an hour, though the conversation stays on disk and resumes the next time you attach or reply.
Run the agent on a box that doesn't sleep
If the run has to continue while your laptop is closed, the process has to live on a machine that stays on: a cloud VM, a home server, a workstation under your desk. Put tmux there, and SSH becomes a window you can drop and pick up.
ssh -t dev.example.com tmux new -A -s auth-refactor
-t is there because tmux needs a terminal. The ssh manual describes it as "Force pseudo-terminal allocation", for running "screen-based programs on a remote machine." Run the line, start claude -n auth-refactor inside, and close the laptop. When the train reaches a tunnel and the connection drops, run the exact same line again. -A puts you back in the running session.

The laptop is only a window. The agent runs on the machine that stays awake.
Remember what moves with the agent. The repo, the .env file, the toolchain and the agent's own sign-in all have to exist on the remote box, because that is where the agent reads and runs things. Commits land on that machine's checkout until you push them.
When the process dies anyway: resume the conversation
Sometimes nothing kept the process alive. The machine rebooted, or you forgot tmux. The conversation is still on disk.
Claude Code saves sessions "continuously to local transcript files" under ~/.claude/projects/, according to its session docs. Two commands bring one back:
claude --continue # latest session in this folder
claude --resume auth-refactor # a named session
This is why the -n name from earlier pays off. Without it you pick from a list. A resumed session restores the full history, including tool calls and results, plus the model and the permission mode. What it can't restore is the work in flight. A tool that was running when the process died "doesn't finish or run again when you resume." Claude sees the call marked as cut off and is told to check whether it took effect before running it again. Background Bash tasks are not restored either. Expect the first turn after a resume to spend a moment checking the state of the repo.
Codex has the same idea under different names:
codex resume --last # latest chat in this folder
codex resume <SESSION_ID> # a specific session
codex resume --last --all # look outside this folder
Per the Codex command reference, --last skips the picker and --all includes "sessions outside the current working directory." codex fork opens the same picker, or takes --last or a session ID, when you want a copy of the conversation to try a different approach.
Treat resume as a safety net for the conversation; the twenty minutes the agent would have spent working while you were away are gone either way.
The Hermes IDE path
I build Hermes IDE, so weigh this section with that in mind. Hermes runs each agent in its own real terminal, and it treats the app window the way tmux treats your terminal. Per the README, on macOS and Linux "agents keep working while Hermes quits, updates or crashes, and you reattach where they left off."
If you opt into its Agent view for Claude, those sessions also come back after an app restart with the earlier conversation on screen, and Claude continues it.

Quit the app, and the agents behind it keep their place.
The README names macOS and Linux for that behaviour. On Windows, plan on the resume flags above.
For remote work, the full New Session window also has SSH and tmux session types, and since 2.2.9 a dropped or slow SSH connection no longer freezes the window. SSH support has its own notes, which list what works today and what doesn't yet, so read them before you trust it with a long run.
The setup that holds up is the one from the previous section. Open the SSH session in Hermes, run tmux new -A -s auth-refactor on the remote side, and start the agent there. If the connection drops, the tmux session on the box keeps running, and the same command puts you back in it.
Hermes is free, source-available under BSL 1.1, and runs on macOS, Windows and Linux. It is not affiliated with Nous Research, Anthropic, OpenAI or any agent vendor. Download it or read the code on GitHub.
Pick by what is likely to kill the run
| What ends the run | What keeps it going |
|---|---|
| You close the tab or the terminal crashes | tmux, claude --bg, or Hermes on macOS and Linux |
| The laptop sleeps or goes offline | tmux on a remote box, over ssh -t
|
| Your terminal app or Hermes updates or quits | Hermes on macOS and Linux, or tmux |
| The machine reboots | Nothing local. claude --resume or codex resume
|
Name every long session when you start it, tmux new -A -s for the process and claude -n for the conversation. Both cost a few keystrokes, and both are what you type when something goes wrong.
If this was useful
If you run long agent jobs every day, Hermes IDE keeps them alive through quits and updates on macOS and Linux, and a star on GitHub helps other developers find it. For the agent patterns underneath runs like these, the AI Agents Pocket Guide is the short read.

Top comments (0)