> ## Documentation Index
> Fetch the complete documentation index at: https://psychiatrist.sudo.la/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions

> Open a session with start(), send it turns, steer it mid-turn, interrupt, fork and close it.

## start(options)

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

| Option | Meaning | Default |
| - | - | - |
| `agent` | the agent as a provider value ([Agents and providers](https://psychiatrist.sudo.la/sdk/agents.md)) | required |
| `cwd` | the checkout to work in | the current directory |
| `branch` | `{ name, from?, path? }`: work in a worktree on branch `name`. `"head"`: work in `cwd` as it is ([Branches](https://psychiatrist.sudo.la/sdk/branches.md)) | a worktree on a new branch, `psychiatrist/<8 hex digits>` |
| `skills` | the only skills the agent sees, each `{ name, text, dir? }`: its SKILL.md text, and the folder of files beside it (the harness puts them where it reads skills, outside git) | none |
| `mcpServers` | exactly these MCP servers (`{ type: "stdio", command, args?, env? }` or `{ type: "http", url, headers? }`), none of the checkout's or your own, each with `allowTools`, the only tools of it the guard lets run ([The guard](https://psychiatrist.sudo.la/sdk/guard.md)); `graph` is reserved for the report tools | none |
| `guard` | rules added to the guard ([The guard](https://psychiatrist.sudo.la/sdk/guard.md)) | none |
| `readOnly` | the agent reviews and decides: edit tools are off, and the guard refuses changes to the repository | `false` |
| `instructions` | appended to the harness's system prompt: binds every turn | none |
| `root` | the trusted checkout `cwd` is a worktree of: project settings come from there | none: no project settings |
| `title` | a new session's title, where the harness shows one | none |
| `additionalDirectories` | directories outside `cwd` the agent may read | none |
| `resume` | a session id to continue, even one closed before a restart: with no `branch`, in the worktree it worked in ([Branches](https://psychiatrist.sudo.la/sdk/branches.md)). One the harness no longer has rejects with `SessionNotFoundError` before anything starts | a new session |
| `output` | every turn's report schema, unless the turn names its own | none |
| `signal` | an `AbortSignal`: aborting it closes the session | none |

| Option | Meaning | Default |
| - | - | - |
| `sandbox` Planned · #14 | where the agent's whole process runs: `seatbelt()`, `bwrap()` or `noSandbox()` ([Sandboxes](https://psychiatrist.sudo.la/sdk/sandboxes.md)) | the native sandbox for this OS |
| `memory` Planned · #18 | a memory every session on this repo shares ([Memory](https://psychiatrist.sudo.la/sdk/memory.md)) | none |

## 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:

| Field | What it holds |
| - | - |
| `text` | everything the agent said in the turn |
| `toolCalls` | each call's `id`, `name` and `input`, with its `output` or `error` |
| `commits` | the commits the turn added, oldest first |
| `usage` | `{ tokens, cached }` for the turn |
| `sessionId` | the harness's session id: `start({ resume })` continues it |
| `output` | with a schema: `{ ok: true, report }`, the report checked and typed by it, or `{ ok: false, error }`, why the agent could not finish; `undefined` when it made none |
| `interrupted` | `interrupt()` or `close()` ended the turn |

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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.