ClaudeReplay
ClaudeSdk without a process: plays back a JSONL recording made with
ClaudeSdk.layer({ record }).
ClaudeAgent.layer().pipe( Layer.provide(ClaudeReplay.layerFile("test/fixtures/claude/simple-turn.jsonl")),)Each open takes the next recorded session (from its ctl open line).
When the client sends a message or calls a control method, the recorded
in frames up to the next recorded out/ctl line are emitted. The
client must make the same calls in the same order as the recorded run;
otherwise the call fails with a “replay diverged” error.
Recorded message uuids are mapped, in order, to the uuids the client sends
(and recorded session ids to the client’s), so MessageIds line up.
Recorded hook lines (SDK hook calls) are replayed by calling the
session’s own Options.hooks callbacks for that event, with the recorded
input, just before the in frame at the recorded position. Frames after it
wait for the callbacks, as the CLI would.
What the callbacks return is passed to ReplayOptions.onHook; the model’s
reply can’t change in a replay. Client calls (send, interrupt,
endInput) are taken one at a time.
status and history lines are served apart from the session lines:
status answers with each recorded status in turn (repeating the last),
history with the line recorded for that session id. Replayed sessions
have no process, so pid is none and kill ends the frames as a SIGKILL
would.
Since v0.1.0
Layers
Section titled “Layers”ClaudeSdk playing back a recording.
Signature
declare const layer: ( all: Recording, options?: ReplayOptions,) => Layer.Layer<ClaudeSdk.ClaudeSdk>Since v0.1.0
layerFile
Section titled “layerFile”layer for a recording file, read when the layer is built.
Signature
declare const layerFile: ( path: string, options?: ReplayOptions,) => Layer.Layer<ClaudeSdk.ClaudeSdk>Since v0.1.0
Models
Section titled “Models”Recording (type alias)
Section titled “Recording (type alias)”A parsed JSONL recording, one RecordLine per line.
Signature
type Recording = ReadonlyArray<ClaudeSdk.RecordLine>Since v0.1.0
ReplayOptions (interface)
Section titled “ReplayOptions (interface)”Signature
export interface ReplayOptions { /** * Sessions `sessionExists` reports as present, besides those opened * earlier in this replay. `"all"` skips the resume precheck entirely. */ readonly knownSessions?: ReadonlyArray<string> | "all" /** Reported CLI version; defaults to the first recorded `init` frame's. */ readonly version?: string | null /** * Each replayed hook call: the session's callbacks' outputs for the recorded input. */ readonly onHook?: (call: ReplayedHook) => void}Since v0.1.0
ReplayedHook (interface)
Section titled “ReplayedHook (interface)”One replayed hook call, as passed to ReplayOptions.onHook.
Signature
export interface ReplayedHook { readonly event: HookEvent readonly input: unknown /** * What each of the session's callbacks for that event returned (none: the session has * no such hook). */ readonly outputs: ReadonlyArray<unknown> /** What the recorded run's callbacks returned. */ readonly recorded: unknown}Since v0.1.0
Parsing
Section titled “Parsing”Read and parse a JSONL recording file.
Signature
declare const load: (path: string) => RecordingSince v0.1.0
Parse a JSONL recording; blank lines are skipped. Throws on a line that isn’t a RecordLine.
Signature
declare const parse: (text: string) => RecordingSince v0.1.0