···70707171pty stats # live metrics for all sessions
7272pty stats myserver # stats for a specific session
7373-pty stats --json # stats as JSON
7373+pty stats --json # stats as JSON (includes CPU, memory, PIDs)
7474+7575+pty events myserver # follow events in real-time
7676+pty events --all # follow events from all sessions
7777+pty events --recent myserver # show recent events and exit
7878+pty events --json myserver # output raw JSONL
74797580pty restart myserver # restart an exited session
7681pty kill myserver # terminate a running session
···99104```
100105101106Detach with `Ctrl+\`. (Press `Ctrl+\` twice to send it through to the process.)
107107+108108+### Nesting Prevention
109109+110110+If you run `pty run` (or a wrapped command) inside an existing pty session, pty detects the nesting via the `PTY_SESSION` environment variable and runs the command directly instead of creating a session-inside-a-session. This means wrapped commands "just work" inside pty sessions without double-wrapping.
111111+112112+Use `pty run -d` to explicitly create a background session from inside another session.
113113+114114+### Events
115115+116116+Sessions automatically log terminal events — bell, title changes, desktop notifications (OSC 9/99/777), focus requests, and cursor visibility transitions — to per-session JSONL files.
117117+118118+```sh
119119+pty events myserver # follow events live (like tail -f)
120120+pty events --all # follow all sessions, interleaved
121121+pty events --recent myserver # dump recent events and exit
122122+pty events --json myserver # raw JSONL output
123123+```
124124+125125+Event files auto-truncate at 1,000 lines and are cleaned up with the 24-hour dead session TTL.
102126103127## Testing Library
104128