Getting started
Install
Section titled “Install”pnpm add @jpowersdev/effect-agent effectpnpm add @effect/platform-node # or @effect/platform-bunA first turn
Section titled “A first turn”import { NodeRuntime } from "@effect/platform-node"import { Agent } from "@jpowersdev/effect-agent"import { ClaudeAgent, ClaudeSdk } from "@jpowersdev/effect-agent/claude"import { Effect, Layer, Stream } from "effect"
const program = Effect.gen(function*() { const agent = yield* Agent const session = yield* agent.open({ cwd: process.cwd(), spendCapUsd: 5 })
// Subscribe before sending, so no event is missed const events = yield* session.subscribe yield* events.pipe( Stream.runForEach(Effect.logInfo), Effect.forkScoped )
const result = yield* session.turn("Fix the failing test") yield* Effect.log(result.finalText)})
const Claude = ClaudeAgent.layer().pipe(Layer.provide(ClaudeSdk.layer()))
// Closing the scope ends the session and stops every process it startedprogram.pipe( Effect.scoped, Effect.provide(Claude), NodeRuntime.runMain)Vocabulary
Section titled “Vocabulary”| Noun | What it is | Verbs |
|---|---|---|
| Agent | One provider (Claude Code or Codex), as a service. Its layer picks which. | open a session, status, history, capabilities |
| Session | One agent process working in one directory. It stays open until its scope closes. | send, turn, steer, interrupt, end, subscribe |
| Message | Input you give a session, with a MessageId. |
lands in a turn, or is dropped |
| Turn | The agent’s work on a message, from TurnStarted to TurnEnded. |
starts, ends with an outcome |
| Outcome | How a turn ended: Succeeded with its finalText, or a failure such as Stalled. |
turn succeeds with it, or fails with it as a typed error |
| Event | Something that happened in a session: text, a tool call and its result, a turn ending. | stream them with subscribe or events |
| Host | A process of its own for a session, so the session outlives yours. | AgentHosts can open, attach, list, events |
In the example above, agent.open starts a session, session.turn sends a message and
waits for its turn to end, and subscribe streams the session’s events.
Sessions covers the session verbs, and
Reattach covers hosts.
Platform services
Section titled “Platform services”effect is a peer dependency, and the library imports no platform package. Two parts
need services from context:
- Codex starts
codex app-serverwithChildProcessSpawner. - A session host talks to its parent over
Stdio.
Provide your runtime’s layer:
import { NodeServices } from "@effect/platform-node"// Bun: import { BunServices } from "@effect/platform-bun"
program.pipe(Effect.provide(NodeServices.layer))Everything else uses Node’s built-in modules, which Bun implements too. The test suite runs session hosts on both.
- Providers: what Claude Code and Codex each support.
- Sessions: send, steer, interrupt.
- API reference: every export, generated from the source.