Starts and manages a long-lived Claude Code CLI session process.
The process is spawned once and kept alive for the whole session. stdin is fed from a queue (keeping the pipe open across sends). ONE internal reader fiber owns the stdout stream: it parses each line, captures the session id, routes control responses to their waiting request, folds results into the readable SessionState, and fans every message out over a Hub — so any number of events/stateChanges consumers each see the full stream.
Scope finalizers run in reverse registration order, which closes a session in this order: shut down stdin, wait for the CLI to exit on its own (up to CloseTimeout; skipped when the close is an interruption), signal the readers, kill the process tree, and keep the transcript one last time.
How long closing a session waits for the CLI to exit once its stdin is closed, before the CLI is killed. A session closed by an interruption — a Stop — does not wait. The CLI finishes the turn it is in and writes the rest of its transcript before it exits, so this is a ceiling for a CLI that does not end, not a wait every close pays.
How long closing a session waits for the CLI to exit once its stdin is closed, before the CLI is killed. A session closed by an interruption — a Stop — does not wait. The CLI finishes the turn it is in and writes the rest of its transcript before it exits, so this is a ceiling for a CLI that does not end, not a wait every close pays.
Default sliding-buffer capacity for the events and stateChanges Hubs. The buffer is a stated contract parameter, not a tuning knob: events is lossy for rendering only, so a conservative default is right.
Default sliding-buffer capacity for the events and stateChanges Hubs. The buffer is a stated contract parameter, not a tuning knob: events is lossy for rendering only, so a conservative default is right.