Session

works.iterative.claude.effectful.Session
trait Session

An active Claude Code session backed by a long-lived CLI process.

Each session maintains a single CLI process whose stdin is kept open for multi-turn conversation. send writes a prompt to stdin; stream reads stdout until the next ResultMessage — see the hazard note on stream before correlating the two. The session is acquired as a Resource, which handles process cleanup on both normal exit and error.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def send(prompt: String): IO[Unit]

Writes a prompt to the session's stdin as an SDKUserMessage JSON line.

Writes a prompt to the session's stdin as an SDKUserMessage JSON line.

Attributes

def sessionId: IO[String]

The session ID assigned by the CLI, wrapped in IO since it reads a Ref.

The session ID assigned by the CLI, wrapped in IO since it reads a Ref.

Returns IO("pending") until the CLI emits an init SystemMessage or until the first turn completes (at which point the ResultMessage session ID is used).

Attributes

def stream: Stream[IO, Message]

Reads stdout messages until the next ResultMessage.

Reads stdout messages until the next ResultMessage.

HAZARD — the messages read are NOT "the reply to your last send". The underlying message queue is shared and long-lived across the whole session, and the CLI owns turn boundaries:

  • it emits output with no send in flight (a background task finishing resumes the main loop and produces a full extra ResultMessage), and
  • it merges a send issued while a turn is running into that turn, so the merged send never gets a ResultMessage of its own. Correlating send and stream positionally therefore attributes replies to the wrong message. At most one consumer may read at a time; concurrent readers silently split the messages between them. See docs/adr/0001-session-is-a-stream-not-turns.md.

Attributes