Documentation
¶
Overview ¶
Command fakeclaude is a test-only stand-in for the real `claude` CLI used by Pyrycode's e2e harness. It opens a JSONL session file under a configured sessions directory, then watches a trigger file: on first appearance it closes the original fd, opens a fresh <uuid>.jsonl in the same directory, removes the trigger, and idles forever. Subsequent triggers are ignored. The strict close-OLD-before-open-NEW order is what makes the consumer ticket's exact-match probe check deterministic.
Configuration is env-only:
PYRY_FAKE_CLAUDE_SESSIONS_DIR directory that must already exist
PYRY_FAKE_CLAUDE_INITIAL_UUID stem for the first <uuid>.jsonl
PYRY_FAKE_CLAUDE_TRIGGER path watched for the rotation signal
PYRY_FAKE_CLAUDE_STDIN_LOG optional filesystem path; when set,
every byte read from os.Stdin is
appended (with fsync per write) so the
e2e harness can observe what the
supervisor wrote to the PTY. In
stream-json mode the value is a path
STEM rather than the file: each child
tees its own stdin to
<stem>.<its session id> — the value
after the last --session-id/--resume on
its own argv, or <stem>.unattributed
when argv carries none (#1137,
per-child since #1331). The PTY path is
unchanged: there the value is still the
literal file every child appends to.
Default off — when unset, stdin is not
read.
PYRY_FAKE_CLAUDE_ASSISTANT_TRIGGER optional path watched in parallel
with PYRY_FAKE_CLAUDE_TRIGGER. When the
file appears, its contents are written
to os.Stdout (the supervisor's PTY),
then the trigger is removed. Used by
the assistant-turn e2e (#311) to script
a scripted assistant chunk on demand.
Default off — when unset, no watch.
PYRY_FAKE_CLAUDE_JSONL_TRIGGER optional path watched in parallel with
the others. When the file appears, its
contents (claude-format JSONL lines) are
appended verbatim to the live session
JSONL, fsynced, then the trigger is
removed. Used by the structured-receive
e2e (#642) to feed real turn events into
the daemon's structured-turn producer,
which tails this file. Default off — when
unset, no watch.
PYRY_FAKE_CLAUDE_TUI optional; when set to any non-empty
value, fakeclaude emits claude's idle-
prompt glyph (U+276F) once at startup and
its thinking-spinner glyph (U+273B) once
on the first stdin bytes, so tui-driver's
IsIdle/IsThinking detection — and the #594
WaitReady→DeliverPrompt→commit contract —
can confirm a turn against fakeclaude.
Default off — when unset, fakeclaude emits
no TUI substrate and is byte-identical to
its pre-#603 behaviour.
PYRY_FAKE_CLAUDE_IDLE_TRIGGER optional path watched in parallel with the
others. When set, fakeclaude starts BUSY:
it emits no startup idle glyph and never the
thinking spinner, so tui-driver's IsIdle
stays false and the supervisor's WaitReady
blocks (claude "busy"). On the trigger
file's first appearance it emits the idle
glyph (U+276F) once — flipping IsIdle true so
WaitReady returns — then removes the trigger;
claude then stays idle for every later turn
(nothing overwrites the bottom status region,
and the delivered prompt is not echoed to
stdout), so a queued backlog drains
back-to-back. Used by the queue-drain e2e
(#792) to open a controllable busy window.
Mutually exclusive with PYRY_FAKE_CLAUDE_TUI,
whose startup idle glyph would defeat the
busy window. Default off — when unset, no
watch and startup behaviour is unchanged.
PYRY_FAKE_CLAUDE_MODAL_TRIGGER optional path watched in parallel with the
others. When set, fakeclaude emits the idle
glyph (U+276F) once at startup — a baseline
non-modal screen, so tui-driver classifies the
child as Unknown/idle — and never the thinking
spinner. On the trigger file's first appearance
it writes a permission-modal screen once
(fsync'd) whose bottom region carries the exact
"Do you want to proceed?" anchor, then removes
the trigger. tui-driver's merge loop detects the
Unknown->Permission class transition on the next
poll tick, so the daemon's #798 modal producer
surfaces a modal_shown to interactive phones.
One-shot: later trigger drops are ignored, and
the fake never clears the modal or reads the
answer keystroke for coordination (each #791
test raises exactly one modal and ends). Used by
the remote-permission e2e (#791). Mutually
exclusive with PYRY_FAKE_CLAUDE_TUI and
PYRY_FAKE_CLAUDE_IDLE_TRIGGER, whose startup
spinner / busy window would perturb the baseline.
Default off — when unset, no watch and startup
behaviour is unchanged.
PYRY_FAKE_CLAUDE_ESC_ENDS_TURN optional; when set to any non-empty value,
fakeclaude puts stdin into raw mode (like modal
mode) so the lone interrupt ESC is not withheld by
the canonical line discipline, and the stdin
reader watches the byte stream for a bare ESC — a
0x1b not part of a CSI/bracketed-paste sequence
(i.e. not immediately followed by '[').
That bare ESC is the remote interrupt keystroke
(supervisor.SendEsc writes a lone 0x1b). On the
first bare ESC fakeclaude appends claude's own
interruption marker (interruptMarkerLine) to the
live session JSONL and fsyncs, so the daemon's
structured-turn producer maps it to a
turn_end{cancelled} — making the Esc the CAUSE of
the turn ending (the interrupt-live e2e #794
asserts a turn_end whose only source is this
handler; #1244 additionally asserts the reason).
One-shot: a second
ESC is inert, matching claude's own re-interrupt
no-op. Unlike the idle/modal triggers this
coexists with PYRY_FAKE_CLAUDE_TUI (the two touch
different bytes: TUI emits the startup glyph +
spinner, this scans for the bare ESC). Default off
— when unset, fakeclaude is byte-identical to its
prior behaviour.
PYRY_FAKE_CLAUDE_MODAL_CLEAR_ON_ANSWER optional; EXTENDS modal mode (requires
PYRY_FAKE_CLAUDE_MODAL_TRIGGER — a no-op otherwise).
When set, after the modal has been shown the first
stdin bytes fakeclaude reads (the local pyry attach
head's answer keystroke) cause it to write a
modal-clearing screen once (modalClearScreen): a run
of newlines that scrolls the "Do you want to
proceed?" anchor above the permission detection
window plus a trailing idle glyph, so tui-driver's
detected class transitions Permission->Unknown and
the merge loop fires EventKindPtyModalHidden. That
makes the local keystroke the CAUSE of the modal
vanishing, which the daemon's #706 local arm resolves
into modal_dismissed{local} (the two-head
first-answer-wins e2e #793). The stdin reader only
signals (clearPending); the main goroutine writes the
clear, preserving the single-writer discipline.
One-shot: a second keystroke is inert. Gated on the
modal having been shown, so a pre-modal keystroke
cannot clear early. Byte-identical to today when
unset — #791 sets only MODAL_TRIGGER and its fake
never clears, so its remote arm stays unaffected.
PYRY_FAKE_CLAUDE_TRUST_TRIGGER optional path watched in parallel with the
others. A sibling of the modal trigger for
claude's STARTUP trust-folder dialog (the #988
no-auto-trust gate). fakeclaude comes up idle
(startup glyph); on the trigger's first appearance
it writes trustScreen once — the "Quick safety
check" dialog whose ❯-marked option row satisfies
tui-driver's gridHasTrustDialog — so DetectModalClass
transitions Unknown->TrustFolder (the daemon surfaces
modal_shown{trust}) AND WaitReady returns
Readiness{TrustModal:true} (the supervisor HOLDS the
queued turn with ErrTrustModalPending, #1013). It
then watches stdin to discriminate the two
resolutions (the load-bearing part): the accept
keystroke ("1\r" from Supervisor.AcceptTrust — the
first post-trust stdin bytes that are NOT a bare
ESC) clears the dialog once (trustClearScreen), so
WaitReady returns clean and the held turn delivers;
a bare ESC deny (Supervisor.SendEsc, via a trust
modal_answer{exit}/timeout) is IGNORED — the dialog
stays up, the turn stays held forever, and no reply
is produced (the daemon's typed "folder not trusted"
session_error is emitted at the resolver regardless
of child behaviour, #1014). Reuses containsBareESC to
distinguish; the stdin reader only signals
(trustAcceptPending), the main goroutine is the sole
writer of f/stdout (single-writer discipline). Raw
mode required so "1\r" and the bare ESC reach the
reader verbatim/unbuffered. One-shot show + one-shot
clear. Used only by the untrusted-cwd trust e2e
(#993). Mutually exclusive with PYRY_FAKE_CLAUDE_TUI /
_IDLE_TRIGGER / _MODAL_TRIGGER, whose startup
spinner / busy window / permission screen would
perturb the baseline. Default off — when unset, no
watch and startup behaviour is unchanged.
PYRY_FAKE_CLAUDE_STREAM_JSON optional; when set to any non-empty value,
fakeclaude speaks line-delimited stream-json
instead of the PTY/TUI surface: it reads
{"type":"user",…} turn envelopes on stdin and,
for each, writes one assistant text line (echoing
the prompt) followed by one result{subtype:
"success"} line to stdout — one response per
received user turn. Non-user lines (a
control_request interrupt, a blank line) are read
and ignored. This is the fake the daemon's
interactive_runner stream path drives: claude
spawned headless over a pipe, no PTY and no
transcript. Checked FIRST in main(), above the
mustEnv(SESSIONS_DIR/…) calls, so it binds no
sessions dir and opens no <uuid>.jsonl, and it
short-circuits before every other mode — making it
mutually exclusive with all of them by
construction (if both this and a PTY mode are set,
stream wins and the other is inert). Default off —
when unset, fakeclaude is byte-identical to its
prior behaviour.
PYRY_FAKE_CLAUDE_STREAM_REPLAY_FIRST optional path to raw stream-json stdout
bytes. When set in stream mode, the first user
envelope writes these bytes once instead of the
canned echo/result pair. The bytes are not parsed
or normalized; stream mode still opens no PTY or
transcript. Default off.
PYRY_FAKE_CLAUDE_STREAM_REPLAY_SECOND optional path to a second raw fragment.
Requires STREAM_REPLAY_RELEASE and is emitted
once when that signal appears, after the first
fragment and without another user envelope.
PYRY_FAKE_CLAUDE_STREAM_REPLAY_RELEASE optional filesystem signal paired with
STREAM_REPLAY_SECOND. Recognized control requests
remain serviceable while the fake waits for it.
PYRY_FAKE_CLAUDE_INITIALIZE_MODELS optional path to a JSON array used as the
initialize response's model menu in stream-json
mode. Unset uses the canned initializeModels.
PYRY_FAKE_CLAUDE_STREAM_CAN_USE_TOOL optional JSON object whose keys are the
inner can_use_tool request fields. In stream-json
mode, each user turn emits the configured request
and waits for its correlated control_response before
ending the turn. Invalid JSON or an unknown key
disables the rider. Default off.
PYRY_FAKE_CLAUDE_STREAM_EXIT_AFTER_CAN_USE_TOOL optional; "1" makes the
stream child exit immediately after emitting the
configured can_use_tool request. It drives
origin-child teardown while the ask is parked.
PYRY_FAKE_CLAUDE_SESSION_ID_FROM_ARGV optional; when set to any non-empty
value, fakeclaude takes the stem for its INITIAL
<uuid>.jsonl from its own argv — the value after
the last "--session-id" or "--resume"
(argvSessionID) — instead of
PYRY_FAKE_CLAUDE_INITIAL_UUID. That env is
process-wide, so every child of one daemon
inherits it identically; a MINTED
per-conversation session therefore wrote
<sharedDir>/<INITIAL_UUID>.jsonl while the daemon
tailed <convDir>/<mintedSessionID>.jsonl
(resolveBoundSessionJSONL) — the two could never
agree, so conversation-scoped turn lifecycle was
observable on ZERO PTY-tier tests (#1195). The
spawn argv is the one per-child channel that
already carries the id the daemon tails
(sessions.buildSession bakes in
"--session-id <pool id>"), which is what real
claude honours too. The value is adopted only if
it is a safe filename stem (see argvSessionID);
no flag, or an unsafe value, falls back to
PYRY_FAKE_CLAUDE_INITIAL_UUID rather than exiting,
so a legacy unpinned spawn still works and the
e2e fails on its assertion rather than on a dead
child. A later /clear rotation still mints a fresh
random uuid (rotateSession), as real claude does.
NOTE the flag's presence is NOT a minted/bootstrap
discriminator — since #839 every bootstrap spawn is
pinned too — so this must stay explicitly selected:
keying the behaviour on argv alone would re-point
every existing bootstrap child's transcript.
Default off — when unset, fakeclaude is
byte-identical to its prior behaviour, including
for a child whose argv carries --session-id or
--resume.
PYRY_FAKE_CLAUDE_JSONL_TRIGGER_DIR optional directory watched in parallel with
the others. When set, fakeclaude watches
<dir>/<its own initial stem>.jsonl.trig and, on
each appearance, appends its contents verbatim to
the live session JSONL and fsyncs — the same
consume as PYRY_FAKE_CLAUDE_JSONL_TRIGGER, on a
PER-CHILD path. The shared-path trigger cannot
serve a multi-child process tree: its claim
protocol is sound only because each fakeclaude
runs a single poll goroutine, so with a bootstrap
child polling the same path whichever child claims
first appends the line to ITS OWN transcript — a
coin flip. Keying the path on the child's own stem
makes ownership structural: a test drops
<dir>/<mintedID>.jsonl.trig and only the minted
child can ever claim it, while the bootstrap child
polls <dir>/<initialUUID>.jsonl.trig, which the
test never creates. The path is computed once from
the stem openSession used, so per-child isolation
is exactly as good as the stem divergence
PYRY_FAKE_CLAUDE_SESSION_ID_FROM_ARGV provides
(the two are typically set together, but neither
requires the other). Independent of, and not
disabled by, PYRY_FAKE_CLAUDE_JSONL_TRIGGER; a
test may set both. Not one-shot — the consume
re-fires on every re-drop, which is what the #929
subscription-offset kicker needs. Used by the
minted per-conversation turn-lifecycle e2e
(#1195). Default off — when unset, no watch and
fakeclaude is byte-identical to its prior
behaviour.
PYRY_FAKE_CLAUDE_REJECT_ABSENT_RESUME optional directory. When set, a
stream-mode spawn whose argv's LAST id flag is
"--resume <id>" and for which <dir>/<id>.jsonl
does not exist writes real claude's own refusal
to stderr and exits 1, instead of serving the
turn. That is the never-established-session
crash-loop #1631 closes, made observable in the
fake-daemon tier: a session that launched but ran
no turn establishes no transcript, so every
--resume respawn is refused forever on a widening
backoff until the daemon's by-id probe switches
the flag to --session-id. Stream mode only, by
construction — the check lives inside the
PYRY_FAKE_CLAUDE_STREAM_JSON branch, so no
PTY-tier test can observe it even if the env
leaked. Default off — when unset, byte-identical
to prior behaviour.
PYRY_FAKE_CLAUDE_STREAM_ROSTER optional decimal COUNT. When it parses to a
positive number, each stream-mode user turn is
preceded by one system/background_tasks_changed
line canning that many task entries (#2080) —
claude's mid-turn report of what is running in
the background, which nothing else in this file
produces. See writeBackgroundTaskRoster for the
fixture and for why the knob carries a count
rather than a boolean. Stream mode only.
Unset, empty, unparsable or non-positive ⟹ off
⟹ byte-identical to prior behaviour, which is
fail-CLOSED: a typo silently disables the rider
rather than enabling some default roster, so a
miswired test fails as "no frame arrived"
instead of passing on a fixture nobody chose.
PYRY_FAKE_CLAUDE_STREAM_MODEL_WINDOWS
optional. When non-empty, every stream-mode
result line carries a modelUsage map reporting
a per-model context window (#2107) — the field
claude uses to say how large each model's
window actually is, which nothing else in this
file produces. See riderModelUsage for the
fixture and its provenance. A boolean rather
than a value, unlike the two knobs above,
because there is nothing here to count or to
choose: the fixture is one canned map, its
numbers copied from a committed capture and one
key's variant suffix from #2118's live probe.
Stream mode only.
Unset or empty ⟹ off ⟹ byte-identical to prior
behaviour (the field is omitempty).
PYRY_FAKE_CLAUDE_STREAM_SESSION_FACTS
optional. When non-empty, every stream-mode
user turn is preceded by one system/init line
(#2315) — the line claude opens each turn with,
and the one this file wrote no form of before.
See writeSystemInitLine for the fixture and its
provenance. A boolean like the knob above and
for its reason: the fixture is one canned line,
with nothing to count and nothing to choose.
Stream mode only.
Unset or empty ⟹ off ⟹ byte-identical to prior
behaviour.
PYRY_FAKE_CLAUDE_MCP_STATUS optional. When non-empty, answer an inbound
mcp_status control request with one canned,
fully populated server row. The daemon sends
this request only after an eligible child's
initialize reply. Unset or empty leaves the
request unanswered, preserving prior hermetic
test traffic. Stream mode only.
The binary lives under internal/e2e/internal/ to visibility-fence it from non-e2e callers. Because TUI mode makes this file carry claude-TUI substrate glyphs, it is on the cmd/substrate-guard allowlist (#603), mirroring the sanctioned internal/agentrun/ptyrunner/helper_test.go exemption.