What happens to a running session when its terminal closes or its VM stops?
Decided 2026-10-04: B. Closing the terminal ends the session. The decision and its reasons are in the I46I46 (closed): S05-cli, S06-vm-lifecycle: session lifecycle, detach, sleep and failureS05-cli and S06-vm-lifecycle describe starting a session and its summary at the end, but not what happens in between, or when things go wrong: comment that starts Decision (2026-10-04):. Source: I46I46 (closed): S05-cli, S06-vm-lifecycle: session lifecycle, detach, sleep and failureS05-cli and S06-vm-lifecycle describe starting a session and its summary at the end, but not what happens in between, or when things go wrong:. Affects S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command., S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does., S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem. and S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.. Note 2026-10-07: the decision is now in those specs, see “The spec change” below. The figures and sub-decisions further down show option A as recommended before the decision.
The problem
Section titled “The problem”Figure 1. A session spans three processes and two links. Each numbered break needs a defined outcome. Break 1 is the detach decision. Break 2 is already half specified: wb-guestd pauses the session’s processes until the link returns (S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.). Break 3 loses the session.
Figure 2. The recommended lifecycle (option A). “Paused” means the host-guest socket is down and the session’s processes are stopped in the guest: host sleep, idle suspend, or a wb-hostd restart (I48I48 (closed): S04-architecture: process supervision, failure, version skew and host resource limitsS04-architecture names the processes but not how they are supervised, what happens when one fails, or how they are upgraded:). Any state can go to “lost”. The figure shows the one from detached.
The spec change
Section titled “The spec change”What option B became, with the sub-decisions it left open written the strict way:
- States (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.): starting, running, paused, ending, ended and lost, with no detached state. A session has one client, the
wbthat started it. Every state before ended has an exit for a dropped link and for a stopped VM, and each state that waits on the guest has a deadline on the host (10 minutes to start, 7 to end), after which the session ends as a failure andwbexits 255. - Hangup: when
wbgetsSIGHUPor its connection towb-hostdcloses,wb-guestdcloses the session’s terminal device, soclaudegetsSIGHUPfrom the guest kernel. 10 seconds later it kills every process in the session, and every process of the project user when this was its project’s only session. WIP is then committed and pushed as on a normal exit (S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end., “Session end”). A process that escapes withsetsidwhile another session of the project runs survives and is logged (S13-02-filesystem-profileS13-02-filesystem-profile: Layer 2: Seatbelt Filesystem Profile (v1)The Seatbelt profile each session's process tree runs under, where it comes from, its exceptions for Xcode builds, and its known gaps., “Known gaps”). - As the project user: everything under a project user’s home, the worktree, carry-in, WIP commit and push included, runs as that user. Root in the guest never opens a path there.
--continue: Claude Code keeps conversations per working directory, and each session has its own worktree path. Sowb-guestdlinks each new worktree’s history directory to one directory per project, as the project user. That rests on Claude Code’s storage layout, which was read on the host, not checked in a guest (I135I135 (closed): S06-vm-lifecycle: check claude --continue and the trust prompt across session worktreesThe spec change for #46 (S06-vm-lifecycle, "Projects and sessions inside a VM") gives each session a new worktree at <home/sessions/<session-id., which also checks the folder-trust prompt and job control).- Socket drops: every project process in the VM stops. When the link returns,
wb-guestdlists its sessions, andwb-hostdchecks each entry against this VM and VM generation: “resume” only for a session whosewbis still there, “finish” for one whosewbis gone, and “end” with no push for anything else. A session paused for 30 seconds of host time awake is lost. Reconnects back off and are capped per VM, and the list is capped at 64 entries. - Lost: a VM,
wb-guestdorwb-hostdthat stops loses its sessions, andwbexits 255. A lost session counts as ended for the VM’s network grants. At the next connection to that VM,wb-hostdhaswb-guestdcommit and push each lost session’s WIP, to its own branch only.wb discardandwb project rmend a lost session with no push. The project user is locked only after its lost sessions have ended, so recovery can still run as that user. A session whose end report was lost in the drop still ends normally, becausewb-guestdrepeats the report until the host acknowledges it. - Pushes:
landing.gitaccepts a push only to the branch of a live session of that project in that VM, so nothing writes to an ended session’s branch. - Idle suspend: never while the VM has a session that is starting, running, paused or ending.
wb vm suspendandwb vm stopare refused then, and the refusal says to close the session’s terminal or wait for its deadline. A terminal left open keeps the VM up (NFR03-footprintNFR03-footprint: FootprintIdle VMs suspend after a configurable period.) and holds its slot (NFR05-two-macos-vmsNFR05-two-macos-vms: Platform limitmacOS permits at most two concurrently running macOS guests per host.). - Exit status (S05-02-exit-status-and-signalsS05-02-exit-status-and-signals: Exit Status and SignalsWhat wb claude exits with, and what it does with each signal.):
claude’s code, 128 + n for signal n, 2 for a usage error, 255 for every other Wraith Box failure, a WIP push that failed and running outside a repository included. Interactive use means both standard input and standard output are terminals. The summary goes to standard error. - Signals: keyboard signals are bytes in the stream.
wbforwardsSIGINT,SIGQUITandSIGTERM, and ignoresSIGPIPE. Ctrl-Z, or aSIGTSTPtowb, stopswbtoo, after it resets the terminal, andfgcontinues both. A helper in the guest leads each session’s terminal, as a shell does, so thatclaudecan stop at all.
Options
Section titled “Options”The options are mine, built around the issue’s recommendation, which is option A.
Each option leaves the SEC* controls unchanged. wb attach shows guest output, so it follows the same rule as a session: no approval prompts in that terminal (SEC14-no-fake-approvalsSEC14-no-fake-approvals: Approvals cannot be spoofed by the guestApproval prompts are never rendered in the agent's terminal stream.).
Sub-decisions
Section titled “Sub-decisions”| Item | Recommendation |
|---|---|
| When idle suspend may happen | When no client is attached and the VM has had no session output, guest CPU load, or open guest connections for the idle period. A detached session alone doesn’t block it. wb attach restores the VM. |
| Host sleep | The VM pauses with the host. On wake wb-guestd resynchronizes the clock (S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.). The session continues whether attached or detached. |
| Socket drops | As S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection. says: the session’s processes stop, and resume when the link returns. A restore after idle suspend is that case. |
VM dies, or wb-guestd exits |
The session is lost. wb prints a wraith box: line and exits 255. The worktree stays on the data disk, and at the next VM start wb-hostd has wb-guestd commit and push its WIP. |
| Exit codes | claude’s own code. 128+n when claude was killed by signal n. 255 when the session was lost or wb failed after the start. 2 for usage errors before the start (S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command.). claude can also exit 2 or 255. The stderr line tells them apart. |
| Signals | Interactive: Ctrl-C, Ctrl-Z and the rest are bytes in the terminal stream, window size changes are forwarded, and SIGHUP or SIGTERM to wb detaches. Non-interactive: SIGINT, SIGTERM, and SIGHUP are forwarded to claude, and wb waits for its exit code. |
| WIP push | At session end, as S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem. says. Also a snapshot to wb/<session-id>/wip on detach and before suspend, which the landing repository’s ref rule already allows. |
| Two clients | One attached client per session. A second wb attach takes over and the first one detaches. |
| Parallel sessions | Unchanged: a worktree and session id each (S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does., S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command.). Each wb prints its own summary. A session that ended detached shows its summary in wb sessions. |
Impact
Section titled “Impact”Evidence
Section titled “Evidence”- verified S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command. specifies the summary on exit and the exit code of
claude, and doesn’t list anattachorendcommand. The command table inpackages/wraithbox-go/internal/cli/cli.gohas neither, so both names would be new and reserved. - verified When the host-guest socket drops,
wb-guestdstops the session’s process group and resumes it when the link returns (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes.). - verified Idle VMs are saved and stopped, and the next session restores them (S06-06-devices-and-warm-startS06-06-devices-and-warm-start: Devices, Warm Start and TimeA VM's devices and resources, saving and restoring its state, and how the guest clock follows the host., “Warm start”).
- verified WIP is committed and pushed at session end,
wbmay push mid-session, and the landing repository accepts onlyrefs/heads/wb/<session-id>/*(S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end.). - verified A new session’s worktree starts at the host’s current
HEAD(S08-01-into-the-guestS08-01-into-the-guest: Into the GuestHow the project's code reaches the guest: the clone, its transport, its remotes, and the uncommitted changes carried in at session start.), which is why B loses the open files of the old session. - verified
ssh“exits with the exit status of the remote command or with 255 if an error occurred” (man ssh, OpenSSH 10.3). A command killed by signal n returns 128+n (man bash). - verified
git stash createmakes a commit “without storing it anywhere in the ref namespace” (git help stash), but includes tracked files only. - inferred So the snapshot needs a temporary index to include untracked files. Doing it without touching the agent’s index is an implementation detail for the M4 work.
- inferred A
wb-guestdexit closes the terminal device it holds, andclaudegets a hangup. The PTY rule is standard Unix behavior. Thatwb-guestdholds the PTY follows from S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does., where it runs commands as a project user with a PTY. - assumed That host-guest socket connections drop on save and restore, so “paused” covers idle suspend. X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest? checks descriptors across save and restore.
- assumed That
claudecontinues cleanly after its processes were stopped for hours, retrying model API calls that timed out. Cheap to check once X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment. has a VM that suspends.
What this unblocks
Section titled “What this unblocks”- I52I52 (closed): S04-architecture, S09-policy-credentials-audit, S10-tech-stack: first .proto contracts and settings schemaS04-architecture says all IPC is protobuf over gRPC and S10-tech-stack adds proto/ "with the first RPC".: the terminal stream contract (attach, detach, resize, signals, exit status) waits on this decision.
- The spec pull request that adds the lifecycle to S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.,
wb attachandwb endto S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command., and the WIP snapshot to S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem.. - It waits on nothing for the decision. The “paused” state rests on X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest? and X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment..
Details and glossary
Why A for non-interactive sessions is different. A piped session (wb claude -p "…" | jq) has no one to come back to it: its input and output are tied to the pipe. Ending it with the client is what a script expects.
Why ephemeral sessions end with the client. FR14-ephemeralFR14-ephemeral: Ephemeral sessionsAn ephemeral mode runs a session with no persisted state. promises no persisted state. A detached ephemeral session would keep its throwaway user and files until someone ends it.
Why a second attach takes over. Sharing one session between terminals would need rules for whose window size wins and who may type. Taking over is what most users expect after moving to another terminal.
Glossary
- Session: one run of
claudein its own git worktree, with an id likemyrepo-20261003-1412-k3f9. - Attach and detach: connecting a terminal to a running session, and leaving it running without one, as
tmuxdoes. - PTY: the terminal device a program like
claudedraws on. Its other end is held bywb-guestd. - Hangup: the signal a program gets when its terminal goes away. Most programs exit on it.
- WIP commit: a commit of everything uncommitted in the worktree, marked as work in progress, so nothing is lost.
- Idle suspend: saving the VM’s state to disk and stopping it after a quiet period (NFR03-footprintNFR03-footprint: FootprintIdle VMs suspend after a configurable period.).