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

# Sessions

> A session's settings and states, closing it, and what happens to it when the machine sleeps, is forked or is deleted.

A session is one conversation with one harness on one machine. This page is about the session itself. For talking to the agent in it, see [Conversations](https://docs.boxd.sh/guides/agents/conversations.md).

## Start a session

A session's harness, model, effort and working directory are chosen when it starts, and stay fixed.

```typescript TypeScript theme={"theme":"github-dark"}
const session = await agents.start("myapp", {
  harness: "claude-code",
  model: "sonnet",
  cwd: "/home/boxd/app",
});
console.log(session.id, session.state);   // "a1b2c3..." "idle"
```

```python Python theme={"theme":"github-dark"}
session = agents.start(
    "myapp", "claude-code", model="sonnet", cwd="/home/boxd/app"
)
print(session.id, session.state)   # a1b2c3... idle
```

```bash CLI theme={"theme":"github-dark"}
boxd agent start myapp claude-code --model sonnet --cwd /home/boxd/app
```

The [reference](https://docs.boxd.sh/guides/agents/reference.md#options) has every option, and [Harnesses and models](https://docs.boxd.sh/guides/agents/harnesses.md#models-and-effort) the models and effort levels.

## Check on your sessions

```typescript TypeScript theme={"theme":"github-dark"}
const open = await agents.list("myapp");
const all = await agents.list("myapp", { all: true });

const one = await agents.get("myapp", session.id);
console.log(one.state, one.turn, one.queued);
```

```python Python theme={"theme":"github-dark"}
open_sessions = agents.list("myapp")
all_sessions = agents.list("myapp", all=True)

one = agents.get("myapp", session.id)
print(one.state, one.turn, one.queued)
```

```bash CLI theme={"theme":"github-dark"}
boxd agent list myapp           # open sessions
boxd agent list myapp --all     # closed and failed too
boxd agent get myapp $SESSION
```

`list` gives the open sessions, and with `all` the closed and failed ones too.

| State | Meaning |
| - | - |
| `idle` | Open, and waiting for a message. |
| `running` | A turn is in progress. |
| `closed` | Ended. Its events stay readable. |
| `failed` | The agent can't go on. The session's `error` says why. |

A session runs one turn at a time. A machine can have several sessions, and they run side by side.

## Close a session

```typescript TypeScript theme={"theme":"github-dark"}
await agents.close("myapp", session.id);                      // now
await agents.close("myapp", session.id, { whenDone: true });  // when its work is done
```

```python Python theme={"theme":"github-dark"}
agents.close("myapp", session.id)                  # now
agents.close("myapp", session.id, when_done=True)  # when its work is done
```

```bash CLI theme={"theme":"github-dark"}
boxd agent close myapp $SESSION               # now
boxd agent close myapp $SESSION --when-done   # when its work is done
```

A plain close ends the session at once. It interrupts a running turn, drops the messages that are still waiting, and stops the agent.

With `whenDone`, nothing is cut short. The session stays open, and still takes messages, until no turn runs, no message waits, and no command that the agent left running is still going.

## Sessions and the machine

Sessions live on the machine's disk. A small service on every machine runs them. It starts with the machine, does nothing until it is called, and doesn't keep the machine awake by itself.

| When | What happens |
| - | - |
| A turn runs, or a command the agent left running | The machine stays awake. |
| A session is idle | The machine can sleep. |
| The machine [sleeps](https://docs.boxd.sh/guides/suspend-resume.md) or restarts | Sessions survive, and a message wakes the machine. |
| You [fork](https://docs.boxd.sh/guides/fork.md) the machine, or create one from a [snapshot](https://docs.boxd.sh/guides/snapshots.md) | The copy has the same sessions, idle. Nothing runs twice. |
| You delete the machine | Its sessions go with it. Finished turns stay in the [run history](https://docs.boxd.sh/guides/agents/history.md#run-history) for 30 days. |


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