Skip to content

Testing

Run your program once against the real CLI, with record on the transport.

const Recording = ClaudeAgent.layer().pipe(
Layer.provide(ClaudeSdk.layer({
record: "test/fixtures/fix-issue.jsonl"
}))
)

For Codex, CodexAppServer.layer({ record }) does the same. Each connection starts the file afresh, except one that opens while another is recording (a status call during a session, say): that one isn’t recorded.

Swap the transport for a replay. The real event mapping runs, but no process starts, so the test is fast and free.

import { it } from "@effect/vitest"
import { ClaudeReplay } from "@jpowersdev/effect-agent/claude"
const Replay = ClaudeAgent.layer().pipe(
Layer.provide(ClaudeReplay.layerFile("test/fixtures/fix-issue.jsonl"))
)
it.effect("replies on the issue", () =>
Effect.gen(function*() {
yield* work(issue)
expect(replies).toHaveLength(1)
}).pipe(Effect.provide(Replay)))

For Codex, use CodexReplay.layer(recordingText). The program has to make the calls it made while recording. If it doesn’t, the replay fails with replay_diverged.

A Claude recording includes each hook call. The replay calls your session’s hooks at the same points, with the inputs the CLI sent, and reports what they returned.

const answers: Array<ReadonlyArray<unknown>> = []
const Replay = ClaudeAgent.layer().pipe(
Layer.provide(
ClaudeReplay.layerFile("test/fixtures/fix-issue.jsonl", {
onHook: (call) => answers.push(call.outputs)
})
)
)

The model’s replies come from the recording, so they don’t change with your hooks.

A Codex replay runs no commands, so it never calls your hooks. Test those by calling them directly, or with a real codex.

Terminal window
pnpm typecheck && pnpm test
EFFECT_AGENT_TEST_HOST=bun pnpm test # session hosts under Bun instead of Node
# Against the real CLIs (costs a little)
node scripts/live-claude.ts
node scripts/live-codex.ts
pnpm build

To take a new Claude Code or Codex release, follow UPGRADING.md.