Skip to main content

start(options)

Opens a session and resolves with it. Only agent is required.

Sending turns

session.send(message, { effort?, output?, askForReport?, signal? }) runs one turn; a session runs one at a time, so a send() while a turn runs, or after close(), is a rejected turn. Await it for the turn’s result: While it runs, turn.events streams what the agent does (the AI SDK’s stream parts: text-delta, reasoning-delta, tool-call, tool-result, tool-error, error; and a step with the session id and tokens at each step’s end); it can be read at any time, from the turn’s start. turn.output holds the report as soon as the agent makes one. A turn that crashes, or whose stream reports an error, rejects, and its events end with that error; an interrupted one, by interrupt(), close() or its own signal, resolves with interrupted: true.
  • session.steer(guidance) adds guidance to the running turn; the agent reads it between tool calls. Nothing happens when no turn runs.
  • session.interrupt() ends the running turn (one interrupted before it reached the agent never does). The session keeps everything, its id included once Claude Code has started the turn (a turn interrupted before then never reached the agent, and a new session has no id yet); the next send() carries on.
  • session.fork() returns a new session that continues this one’s conversation from here, in the same place; this one is left as it is.
  • session.close() stops the running turn and ends the session: its events end and it takes no more turns. start({ resume: id }) continues it later.
  • session.events streams every turn’s events, from when you start reading until close().
  • session.id is the harness’s session id once a turn has reported it (or the one resumed); session.cwd is where the agent works.
Effort and output schema are per turn: a session can plan at high effort, build at medium, and end a review turn with a report of another shape.