1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use HashMap;
use OsString;
use io;
use ExitStatus;
/// PID + birth-epoch the supervisor writes into `<sid>.pid` (and `<sid>.relaunch`).
///
/// `born` is a Unix timestamp (seconds since epoch) captured immediately before
/// the child is spawned. It acts as a nonce: the relaunch loop and the hook both
/// compare a stored `born` value against the current pidfile to confirm they are
/// looking at the same incarnation of the process and not a recycled PID.
/// One foreground execution of `claude`. Impls MUST:
/// 1. Inherit the caller's tty for stdin/stdout/stderr (never pipe).
/// 2. Write `<sid>.pid` (`"<pid> <born>"`) **immediately after spawn, before
/// blocking in wait** — the limit-switch hook fires while claude is still
/// alive and reads this file to stamp the relaunch sentinel's `born`. If we
/// wrote it only after the child exits, the hook would find no pidfile.
/// 3. Return only when the child exits.
/// 4. Leave the terminal usable for the relaunch loop afterward.
/// 5. Remove `<sid>.pid` is the relaunch loop's job, not the launcher's.
///
/// The `env` map contains child-only environment overrides (e.g.
/// `CLAUDE_CONFIG_DIR`). Impls merge these into the inherited environment
/// rather than replacing it wholesale.