On Friday you had four agents going: one on the API, one on the docs, a Codex session running tests, and one you'd parked halfway through a refactor. Over the weekend macOS installed an update and restarted. On Monday the tabs are gone, and you don't remember which session was in which folder.
The conversations aren't lost. What stopped is the processes:
- What's saved: every message up to the moment the agent stopped. Claude Code, Codex, and Grok Build write the transcript as they go.
- What isn't: a reply that was still being written, and the running process itself.
-
Bring one back: in the project folder, run
claude --continue,codex resume --last, orgrok --continue. - Bring several back: list your most recent sessions with their folders, pick the ones you were using, and resume each. There's a command below that prints them for you.
What happens to a running agent when I close the terminal or restart?
Closing a terminal window, quitting the terminal app, logging out, and restarting all end the processes inside, including Claude Code, Codex, and Grok Build. Whatever the agent had already written to its transcript stays on disk. A turn that was halfway through is cut off.
Sleep is different. When the Mac sleeps, processes pause and pick up where they were when it wakes. A request that was in flight to the model can fail while the network is down. If the agent reports an error after wake, tell it to continue.
Some terminal apps reopen your windows after a restart, with the same folders and scrollback. That looks like the session is back, but it's a fresh shell. The agent isn't running in it.
How do I resume the last session in a project?
Open a terminal in the project folder and run:
# Claude Code
claude --continue
# Codex
codex resume --last
# Grok Build
grok --continue
Each picks the most recent session from the current directory. If you ran more than one session in that folder, use the picker instead: claude --resume, codex resume, or /resume inside Grok. The folder matters. Run the same command from your home directory and you get a different session, or none.
How do I bring several sessions back at once?
When several agents were running in different folders, you need each session's folder and ID. The transcripts don't record whether a session was still running, but the ones you were using before the restart are usually the most recently written. These commands print one ready-to-run line per recent session, most recently active first:
# Claude Code: the 10 most recent sessions
ls -t ~/.claude/projects/*/*.jsonl | head -10 | while read -r f; do
jq -r 'select(.cwd) | "cd \(.cwd | @sh) && claude --resume \(.sessionId)"' "$f" | head -1
done
# Codex: the 10 most recent sessions
ls -t ~/.codex/sessions/*/*/*/*.jsonl | head -10 | while read -r f; do
jq -r 'select(.type == "session_meta") | "cd \(.payload.cwd | @sh) && codex resume \(.payload.id)"' "$f" | head -1
done
# Grok Build: the 10 most recent sessions, without subagents' sessions
subagents=$(find ~/.grok/sessions -mindepth 4 -maxdepth 4 -path '*/subagents/*' -exec basename {} \;)
ls -t ~/.grok/sessions/*/*/summary.json | while read -r f; do
id=$(jq -r '.info.id' "$f")
printf '%s\n' "$subagents" | grep -qx "$id" && continue
jq -r '"cd \(.info.cwd | @sh) && grok --resume \(.info.id)"' "$f"
done | head -10
Each line looks like cd '/Users/you/code/api' && claude --resume 8e539d93-…. Pick the ones you were working on, open a tab per session, and paste its line. A session that sat idle for a long time can fall below newer ones, so raise head -10 if one is missing. Skip lines whose folder no longer exists, such as a worktree you've since removed.
These commands read each tool's session files directly. That format is internal and can change between releases, so treat them as a convenience, not an interface. Grok keeps a subagent's work as a session of its own next to the main one, which is why its command skips those. If you set GROK_HOME, use it in place of ~/.grok. If you turned on Codex's experimental compression, older sessions are .jsonl.zst files and won't show up in the list. All three need jq, which ships with macOS 15 and later. The pickers work too: press Ctrl+A in claude --resume to see every project, run codex resume --all, or open /resume in Grok from each project folder. The list above is faster when you want several sessions back at once.
Can I skip looking up folders and session IDs?
In PonyMux, each Terminal is a saved record: its name, folder, List, and the sessions that ran in it. Quitting PonyMux or restarting the Mac ends the processes, but the Terminals stay where you left them. They come back sleeping, marked with a zzz badge.
Select a sleeping Terminal that had an agent conversation, and PonyMux shows the last exchange from that session, so you can see where it stopped. With automatic resume on, a short countdown starts. When it runs out, PonyMux resumes that exact session in the Terminal's folder. You can resume right away, pause the countdown, or choose Shell Only for a plain shell instead.

A sleeping Terminal after a restart. The last exchange is on screen, and Resume counts down before it reopens the session.
That replaces the list-and-paste step above: each Terminal already knows its folder and session, so bringing four agents back is four clicks. Automatic resume can be turned off in Settings → General. If the transcript is gone, for example after Claude Code's 30-day cleanup, the Terminal says so and offers a shell instead.
For how sleeping and waking work, see Terminal Lifecycle. To find an older session by what was said in it, see Claude Code conversation history.
Originally published on ponymux.com, where the demos are interactive.
Top comments (0)