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

# Sessions

> A suspended session has no runner but still answers reads and records writes; `sessions.resume` or sending a turn starts it again

A session id is `cs_` followed by 16 characters. Fields of the `Session` object: [API schema](https://docs.opencomputer.dev/reference/api-schema.md#objects).

## Status

| `status` | Meaning |
| - | - |
| `starting` | The runtime is starting. `runtime.starting` events give the phase: `computer`, then `agent` |
| `running` | A turn is running |
| `waiting` | An ask is open |
| `idle` | No turn is running |
| `suspended` | No runner holds the session. The host answers reads and records writes |

Each change is a `session.status_changed` event with `from` and `to`.

## Create and list

HTTP only: `POST /sessions` with a `CreateSessionBody`, and `GET /sessions`.

```json theme={null}
{"input":"Run the test suite and fix what fails","title":"Fix tests","mode":"acceptEdits","metadata":{"ticket":"ENG-123"}}
```

Every field is optional ([API schema](https://docs.opencomputer.dev/reference/api-schema.md#operations)). `id` is a session id chosen by the client; `input` is the first message. Accepted values for `model`, `effort`, `speed` and `mode` are in the session's `capabilities`.

`access` sets who may use the session ([Access](#access)). Without it, the session gets the organization's `apiAccessDefault`.

`GET /sessions` lists only the sessions you may use. That holds for admins too: being an admin shows you no one else's session. A session's own short-lived key lists only that session, and cannot create sessions (`403 forbidden`, `reason: "computer_principal"`).

## Read

`sessions.get` (`GET /sessions/{id}`) returns the `Session`, including the active turn id, queued turns, open asks, running subagents and `lastSeq`. `minSeq` reads your own write: [Session journal](https://docs.opencomputer.dev/api/overview.md#session-journal).

## Watch

To follow a session as it runs, read its [events](https://docs.opencomputer.dev/api/events.md) over HTTP, then subscribe to `events:<id>` (and `deltas:<id>` for text as it is written) on [Live](https://docs.opencomputer.dev/api/live.md). Watching never resumes a suspended session. Its `capabilities` (models with their effort levels, permission modes, and features) are at `GET /sessions/{id}/capabilities`.

## Update

`sessions.update` (`PATCH /sessions/{id}`, HTTP only like every write) changes any of `title`, `model`, `effort`, `speed`, `mode`, `archived`, `metadata` and `access` ([Access](#access)). It returns the session and a `seq`.

Only the session's owner may update it. Anyone else it is shared with, admins included, gets `403 forbidden` with `reason: "owner_only"`. They can still read and watch the session, send messages, answer asks, and stop or interrupt it. A new message un-archives an archived session, whoever sends it.

```json theme={null}
{"mode":"plan","metadata":{"ticket":"ENG-124"}}
```

| Item | Rule |
| - | - |
| `metadata` | Keys (up to 40 characters) are merged one by one. Values are strings of up to 500 characters, or null |
| `session.updated` event | `changes` maps each changed field to `{from, to}`. A metadata key is `metadata.<key>` |
| Model the harness does not accept | `invalid_request` with `field: "model"`. The session stays on its model |

## Access

Sessions started from the dashboard, opc or the API have an `access` field, `{"mode", "people"}`:

| `mode` | Who may use the session |
| - | - |
| `owner` | Only its owner |
| `org` | Every member of the organization |
| `people` | Its owner and the members in `people` (`usr_` ids). The owner is never listed |

Using a session means everything that reads or drives it: get, list, watch on Live, history (events, turns, asks, subagents), writes, terminals and workspace files. Anyone with access drives the session with its owner's secrets and subscription. To someone without access, the session does not exist: `404 session_not_found`.

Set it when you create the session, or change it with `PATCH /sessions/{id}`:

```json theme={null}
{"access":{"mode":"people","people":["usr_01j...","sam@example.com"]}}
```

| Item | Rule |
| - | - |
| Who may change it | The owner only |
| Anyone else with access, in `org` or `people` | `403 forbidden` with `reason: "owner_only"`. Ask the owner to share it |
| Admins | No exception. An admin uses a session only when its access lets them in, as any member, and cannot change its access or add themselves. To someone without access, including an admin, the session does not exist (`404 session_not_found`). Admins manage organization-level things: org secrets, invites, roles, API keys and the organization default below |
| `people` | Up to 50 entries: `usr_` member ids, WorkOS `user_` ids, or the email of someone who owns a session in the organization. An email that matches no one: `400 invalid_request` with `field: "access.people"` and `reason: "unknown_member"` |
| Slack sessions | `access` shows `owner` and cannot be changed over the API: `403 forbidden` with `reason: "access_in_slack"`. Manage who drives a Slack session in its thread |
| A track's agent or start session | Its access is its owner's and cannot be set or changed: `403 forbidden` with `reason: "role_session"` |
| Sessions from before access modes | `owner`: only their owner sees them until they share them. A stored session without a mode is read as `owner` |
| Terminals | The owner and the members in `people` only. Members of an `org` session and admins get no terminal by their role ([Terminals](https://docs.opencomputer.dev/api/terminals.md)) |
| After a change | Reads, writes and live events follow the new access at once. Open terminals that lose access are closed |

Two fields on the session say where you stand:

| Field | Meaning |
| - | - |
| `access` | `{"mode", "people"}` as above. `people` is empty unless `mode` is `people`. Slack sessions show `{"mode":"owner","people":[]}` |
| `canManageAccess` | `true` when you may change the session's access: you are its owner, it was not started in Slack, and it is not a track's agent or start session. Otherwise `false` |

### Organization default

`GET /settings` returns `{"settings":{"apiAccessDefault":"owner"}}`. `apiAccessDefault` is the access of new sessions started from the dashboard, opc or the API without `access`: `owner` (the default) or `org`. A session an agent starts takes the access of the session that started it. An organization admin changes it with `PATCH /settings` and `{"apiAccessDefault":"org"}`. Anyone else gets `403 admin_required`. Slack sessions keep their own default, set in Slack.

## Set aside

Triage lists the asks waiting on you. Setting a session aside moves its ask out of that list until something newer needs you. HTTP only: `PUT /sessions/{id}/aside` sets it, `DELETE /sessions/{id}/aside` brings it back. Both return the session.

```json theme={null}
{"ref":"toolu_01AbCdEf"}
```

| Item | Rule |
| - | - |
| `ref` | The id of the ask being set aside: the session's oldest open ask |
| `aside` | True while `ref` is still the session's oldest open ask. Once that ask closes, `aside` is false again, with no `DELETE` |
| Caller | The session's owner, with `sessions:write`. Anyone else: `403 forbidden` with `reason: "aside_owner_only"` |
| Events | None. Setting a session aside does not change `lastActiveAt` |

## Compact

`sessions.compact` (`POST /sessions/{id}/compact`) queues a compaction as a turn and returns the same result as `turns.send`.

`instructions` (up to 10,000 characters) is passed to the harness's `/compact` command. The `session.compacted` event gives `beforeTokens`, `afterTokens` and `auto` (true when the harness compacted on its own). See Context and compaction.

## Suspend

`sessions.suspend` (`POST /sessions/{id}/suspend`) stops the session's runner. The journal and workspace stay on the computer.

| State when called | Result |
| - | - |
| Idle | Suspends |
| A turn is waiting on an ask | The turn is interrupted, then the session suspends |
| A turn is running and no ask is open | `409 session_busy`. Interrupt first |
| `ifIdle: true` and the session is not idle, or has running subagents or queued turns | The session, unchanged |
| Already suspended | The session, unchanged |

Suspending cancels queued turns, stops running subagents, closes open asks as `interrupted`, and records `runtime.suspended` with `reason: "requested"`. The other reasons are `idle` and `lost`.

## Resume

`sessions.resume` (`POST /sessions/{id}/resume`) starts the runtime of a suspended session, or of an `idle` one whose runner has exited after two hours idle, and returns at once; `runtime.starting` and `runtime.connected` events follow. On a session that is not suspended it returns the session unchanged. [Sending a turn](https://docs.opencomputer.dev/api/turns.md#send) to a suspended session also starts it.


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