Claude Code and Codex
Both sit behind one Agent service. Switching providers is a layer change.
const AgentLive = ClaudeAgent.layer().pipe( Layer.provide(ClaudeSdk.layer()))// or CodexAgent.layer() + CodexAppServer.layer()const program = Effect.gen(function*() { const agent = yield* Agent const session = yield* agent.open({ cwd: process.cwd(), spendCapUsd: 5 })
// Print each command the agent runs const events = yield* session.subscribe yield* events.pipe( Stream.filter((event) => event._tag === "ToolCall"), Stream.runForEach((event) => Console.log(`$ ${event.summary}`)), Effect.forkScoped )
const result = yield* session.turn("Fix the failing test") // $ pnpm test // $ rg -n "parseRange" src // $ pnpm test test/range.test.ts
yield* Console.log(result.finalText) // Fixed an off-by-one in parseRange. All 42 tests pass.}).pipe( Effect.scoped, // stops the agent and everything it started Effect.catchTags({ UsageLimited: (e) => Console.log(`Hit the ${e.window} usage limit`), SpendCapReached: (e) => Console.log(`Stopped at $${e.spentUsd}`) }))Claude Code and Codex
Both sit behind one Agent service. Switching providers is a layer change.
const AgentLive = ClaudeAgent.layer().pipe( Layer.provide(ClaudeSdk.layer()))// or CodexAgent.layer() + CodexAppServer.layer()Steering
steer sends into the running turn. interrupt stops the turn and keeps the session.
yield* session.send("Add a --json flag")yield* session.steer("Call it --format")yield* session.interruptTyped endings
A failed turn is a tagged error you can match on, and a value you can store.
session.turn(prompt).pipe( Effect.catchTag("Stalled", () => session.turn("Still there?")))Reattach
Sessions can run in their own process. After a restart, attach by id and catch up.
// After a restartconst session = yield* hosts.attach(id)yield* session.awaitMessage(messageId)