# Agent session commands

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> Start, follow, answer, stop, share and read the transcript of an agent session from the command line.


The `rl agentsession` group runs coding agents on workstations and manages the sessions that result. Its aliases are
`agentsessions`, `ags` and `as`, so `rl as get` is `rl agentsession get`.
[Agent sessions](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/) explains what a session is and how to use one, and
[AgentSession and AgentSessionConfig](https://docs-stg.ringleader.dev/reference/resources/agentsession/) lists the fields.

Agent sessions are hidden until the setting `agent-sessions.visible` is on for you. While it is off, the group is missing from
`rl --help` and from shell completion, but every command works when you type it. See
[Show agent sessions on your device](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/#show-agent-sessions-on-your-device).

These flags work on every command in the group:

| Flag | Description |
|------|-------------|
| `-n, --namespace <ns>` | Namespace. Default: the pinned namespace, else the primary origin's, else `local`. |
| `--as <subject>` | Impersonate a subject, such as `user:alice`. |
| `--home <dir>` | Data directory. |

Commands that act on several sessions also take these:

| Flag | Description |
|------|-------------|
| `-A, --all-namespaces` | Operate across all namespaces. |
| `-l, --selector <selector>` | Label selector (`key=value[,key!=value,key in (a,b),key,!key]`) instead of names. |

## Start a session

### `rl agentsession create [name] [prompt]`

Start a coding agent on a workstation. The command writes the session and returns, and the agent starts when the
workstation receives it. Argument 1 is the name and argument 2 is the prompt. With no name, Ringleader builds one from the
workstation's name and a random suffix. A name that is already taken is refused. Put `--` before a prompt that begins with `-`.

```bash
rl agentsession create fix-login --workstation my-agent-box --prompt "Fix the failing login test."
rl agentsession create nightly --workstation my-agent-box -- "--verbose is what broke it"
```

| Flag | Description |
|------|-------------|
| `--workstation <name>` | The workstation to run on. Required unless you give `--workstation-pool`. Giving both is refused. |
| `--workstation-pool <name>` | Borrow a workstation from a pool instead. |
| `--prompt <text>` | The prompt, when you give no name. |
| `--agent <agent>` | `claude`, `codex`, `agy`, `pi` or `opencode`. |
| `--model <model>` | The model, as the agent's own catalog spells it. |
| `--model-provider <provider>` | The provider that serves the model. |
| `--effort <level>` | `low`, `medium`, `high`, `xhigh`, `max` or `ultra`. Another single word passes to the agent with a warning. |
| `--permission-mode <mode>` | `ask`, `acceptEdits` or `unattended`. |
| `--allow <pattern>` | An allowed tool pattern. Repeatable. It replaces any layer's list. |
| `--workdir <path>` | Where the agent runs. A relative path resolves against the login user's home. Default: a layer's directory, else the first source checkout, else the home. |
| `--worktree-set <name>` | A worktree set on the workstation for the agent to work in. |
| `--env <NAME=VALUE>` | An environment variable. Repeatable. |
| `--extra-arg <agent>=<arg>` | An extra argument for an agent, one argument per use, never split. Repeatable. |
| `--secret <name>` | A Secret that becomes the session's identity. Repeatable. |
| `--config <name>[=<priority>]` | An AgentSessionConfig layer to fold in. Repeatable. |
| `-l, --labels <name=value>` | Labels for the session. Repeat or separate with commas. A shared layer's selector finds the session by them. |
| `--idle-timeout <duration>` | Stop after this long with no activity. |
| `--max-duration <duration>` | Stop after this much agent run time. |
| `--max-cost <usd>` | Stop once the session has spent this many US dollars. |
| `--end-on-first-idle [true\|false]` | End at the agent's first turn boundary. The bare flag means `true`. |
| `--takes-turns [true\|false]` | `false` refuses every input and ends the session at its first turn boundary. The bare flag means `true`. |
| `--max-auto-resumes <n>` | How many times `--auto-resume-prompt` may bring the session back. Default `5`, and `0` never. |
| `--auto-resume-prompt <text>` | Text sent as the first input after each resume. Empty means the session waits for a person. |
| `--auto-resume-progress <duration>` | How long a resumed session must run to count as productive. Default `1m0s`. |
| `--start-workstation <IfIdleStopped\|Never>` | Start the workstation when its idle policy stopped it. It does nothing with a pool. |
| `--transcript-store <box\|daemon\|plane>` | Where the transcript is kept. Without it, Ringleader chooses and records the choice in `status.transcript`. |
| `--chat` | Open the chat client once the session is written. It needs the `attach` right and does nothing with `--dry-run` or `-o`. |
| `--dry-run` | Print the session as a file instead of creating it. |
| `-o, --output <format>` | `yaml` or `json`. Print the session and create nothing. |

### `rl agentsession exec [name] [prompt]`

Create a session, follow its output and exit with the agent's status: `0` when the agent finished, non-zero when it failed or
stopped. Press Ctrl-C to detach, which does not stop the agent. It takes every `create` flag except `--chat`. Its `-o` is
`yaml` to preview the session, or `json` to stream raw frames.

## Follow a session and talk to it

### `rl agentsession get [name...]`

List sessions, or read the ones you name. Alias: `list`. The table has the columns `NAMESPACE`, `NAME`, `OWNER`,
`DISPLAY NAME`, `PHASE`, `WAITING FOR`, `WORKSTATION` and `AGE`.

| Flag | Description |
|------|-------------|
| `--mine` | List only the sessions you own. |
| `-o, --output <format>` | `table` (default), `yaml`, `json` or `jsonpath='{...}'`. |
| `-w, --watch` | Watch for changes. |
| `--to <origin>`, `--origin <origin>` | Read from one origin by name (`self` for this device). |

### `rl agentsession describe [name...]`

Print each session's spec, status and events.

| Flag | Description |
|------|-------------|
| `--timestamps <utc\|local>` | The time zone of the timestamps. Default `utc`. |
| `--to <origin>`, `--origin <origin>` | Read from one origin by name. |

### `rl agentsession recent`

Print one page of sessions as JSON: every live session (`Pending`, `Starting`, `Running` and `WaitingForInput`) plus the 200
most recently active. The output is `{"sessions": [...], "truncated": bool, "continue": string}`.

| Flag | Description |
|------|-------------|
| `--continue <token>` | The next page of 200, from the `continue` field. |
| `--search <text>` | Filter by text. It uses the same grammar as the `/` filter in the chat list. Repeat it identically on every page. |

### `rl agentsession logs <name>`

Follow the live output of a session. It needs only the right to read the session. It returns when the agent comes to rest, and a
session that waits on a person keeps following. For a session already at rest it prints the phase and exits. It needs a
running `rl` daemon on this device.

| Flag | Description |
|------|-------------|
| `-o, --output <format>` | `text` (default), `json` or `jsonl`. |
| `--include-inputs` | Include who sent each turn. |
| `--include-notes` | Include people's notes. |

### `rl agentsession attach <name>`

A stream of JSON lines in both directions. It writes to the session, so it needs the `attach` right. Send one object per
line: `{"kind":"turn","text":"..."}`, `{"kind":"permission","decision":"allow"}` (or `"deny"`, with `answersRun` and `answers`
naming the question) and `{"kind":"interrupt"}`. Each output line carries `v` and `kind`: `hello`, `frame`, `result` or `bye`.
It detaches when the agent comes to rest. Ctrl-C detaches and never stops the agent. With `-o text`, a line you type is a turn,
and `y` or `n` alone answers the pending question.

| Flag | Description |
|------|-------------|
| `-o, --output <format>` | `text`, `json` or `jsonl`. Default `jsonl`. |
| `--include-inputs`, `--include-notes` | As for `logs`. |

### `rl agentsession chat [name]`

Open a full-screen terminal client. With no name, it opens the session list, most recent first, with the sessions that wait
on you at the top. It needs the `attach` right, and a session that has rested opens read-only. It needs a terminal.

| Flag | Description |
|------|-------------|
| `--history <n>` | How many stored frames to show first. Default `500`. |
| `--read-only` | Open without writing. It needs only the right to read. |
| `--replay <file>` | Open an `export` file offline. Repeatable. It cannot be combined with a name, `-n` or `--as`. |
| `--theme <theme>` | `auto` (default), `dark`, `light` or `basic`. |

### `rl agentsession send <name> [text]`

Send a follow-up turn. The text is one argument and arrives as typed. Put `--` before text that begins with `-`. A turn sent while
the agent works steers the running turn. `send` is refused for a session started with `--takes-turns=false`, and for a
`Stopped` or `Done` session.

```bash
rl agentsession send fix-login "Also add a test for the expired session case."
```

### `rl agentsession approve <name>` / `deny <name>`

Answer the pending permission question with allow or deny. The answer names the question that is pending now. If the agent has
moved on, the command refuses. With nothing pending, it says so and suggests a turn.

### `rl agentsession interrupt <name>`

Stop the turn the agent is working on and keep the session. It is refused when no turn is in flight, and by an agent that cannot
abandon a turn. Send the next instruction with `send`.

### `rl agentsession note <name>`

Add a private note to the session. The agent never sees it.

| Flag | Description |
|------|-------------|
| `--after-run <n>`, `--after-seq <n>` | The frame the note follows. |

### `rl agentsession set-display-name <name> <text>`

Set the label that the console, the Ringleader desktop app and the chat client show beside the name. An empty string clears it.
It holds up to 64 characters, and only the owner or an administrator sets it. Put `--` before text that begins with `-`.

### `rl agentsession inputs <name>...`

Print each session's prompt and turn texts, in the forms `text` (default) and `json` (`-o`). A name that fails prints to
standard error, and the command exits `1`.

### `rl agentsession wait [name...]`

Wait for sessions to reach a condition. For a session, give a phase name.

```bash
rl agentsession wait fix-login --for WaitingForInput --timeout 10m
```

| Flag | Description |
|------|-------------|
| `--for <condition>` | `Ready`, `Deleted`, a phase such as `Running`, `condition=<Type>[=<Status>]` or `jsonpath='{<path>}'=<value>`. Default `Ready`. |
| `--timeout <duration>` | How long to wait. Default `20m0s`, and `0` means no limit. |
| `--all` | Wait on every session in the namespace. |

### `rl agentsession get-resolved-configuration <name>`

Print the settings the session resolves to after its configuration layers merge, including layers that attached and were
refused, with the reasons. It needs no Secret access and prints `${secret:NAME}` as written.

| Flag | Description |
|------|-------------|
| `-o, --output <format>` | `yaml` (default) or `json`. |

## Stop, finish, resume, restart and move

### `rl agentsession stop [name...]` / `done [name...]`

`stop` moves each session to `Stopped`. `done` moves it to `Done`. Ringleader records who did it. Both take `-A` and `-l`.

| Flag | Description |
|------|-------------|
| `--reason <text>` | Why. Up to 1024 bytes. |

### `rl agentsession resume [name...]`

Bring a `Stopped` or `Done` session back, or a session that a limit ended. Each flag raises the ceiling that stopped the session.
A resume turns off `--end-on-first-idle` for that run. It is refused when the workstation was deleted, a pool lease failed,
or the owner no longer holds the pool member. A session that never captured an agent conversation rests where it is, and its
prompt is not run again.

| Flag | Description |
|------|-------------|
| `--max-cost <usd>` | Raise the spend ceiling. |
| `--max-duration <duration>` | Raise the agent run-time ceiling. |
| `--max-auto-resumes <n>` | Raise the auto-resume ceiling. `0` turns auto-resume off. |
| `--start-deadline <time>` | Move the start deadline to this RFC 3339 time. |
| `--resume-window <duration>` | Give the session this resume duration, such as `3d`, counted from its last activity. |

### `rl agentsession restart [name...]`

Replace the agent process with a new one that re-enters the same conversation, to pick up refreshed sign-in, reconnected MCP
servers and new tools. It refuses a session a declared limit ended, a finished session that takes no turns and a session with no
conversation captured yet.

| Flag | Description |
|------|-------------|
| `--wait` | Wait until each session has a new agent process. |
| `--timeout <duration>` | With `--wait`, how long to wait. Default `20m0s`, and `0` means no limit. |

### `rl agentsession move <name> --workstation <name>`

Move a session and its conversation to another workstation. It works for `claude`, `codex` and `pi`, with a
conversation file up to 64 MiB. Working files stay behind, and so do the earlier frames of a transcript kept on the old
workstation, so export it first. It refuses a pool session, a session that a limit ended or that failed, and an old
workstation it cannot reach. A session that is already on the target prints `unchanged`.

| Flag | Description |
|------|-------------|
| `--workstation <name>` | The workstation to move to. |
| `--timeout <duration>` | How long to wait for the session to stop. Default `2m0s`. |
| `-y, --yes` | Move without asking for confirmation. |

## Read and export transcripts

### `rl agentsession transcript <name>`

Print the stored transcript as JSON Lines, oldest first. Each line is an `event` or a `transition`, positioned by `run` and `seq`,
and `seq` restarts at 1 with each agent process. A store that cannot be reached from this device is refused with its name.

| Flag | Description |
|------|-------------|
| `--last <n>` | Print the last n frames. Default `0`, which reads forward. |
| `--limit <n>` | Print at most n frames. Default `0`, which prints all. |
| `--after-run <n>`, `--after-seq <n>` | Start after this run, and after this sequence within it. |
| `--before-run <n>`, `--before-seq <n>` | Read the last frames before this run, and before this sequence within it. |
| `--include-inputs`, `--include-notes` | Include who sent each turn, and people's notes. |
| `--include-gaps` | Include declared gaps in the transcript. |
| `--include-page` | End the output with a record of where a backward read stopped. It needs `--last`. |

### `rl agentsession export <name>`

Write the whole transcript as one JSON document.

```bash
rl agentsession export fix-login -o fix-login.json
```

| Flag | Description |
|------|-------------|
| `-o, --output <file>` | The file to write, whole or not at all. Default `-`, standard output. |
| `--bundle` | Export the whole record: the transcript, the owner and status, token usage and cost, the workstation's records for the session's days and a checksum of each stored part, each marked included, withheld or unavailable. With `-o`, it writes `<file>.sha256` beside the file. Otherwise it prints the checksum to standard error. The checksum detects accidental change only. |

### `rl agentsession grep [session]`

Search transcripts for text. It searches messages, tool input and output, and patches, and not the agent's thinking.

```bash
rl agentsession grep -e "expired session" --list
```

| Flag | Description |
|------|-------------|
| `-e, --pattern <text>` | Text to find. Repeatable. |
| `--any`, `--all` | Match a session that holds any pattern (default), or every pattern. |
| `-A, --all-namespaces` | Search every namespace. |
| `--after <n>` | Lines after a match, 0 to 100. |
| `-B, --before-context <n>` | Lines before a match, 0 to 100. |
| `-C, --context <n>` | Lines before and after a match, 0 to 100. |
| `--list` | Print each matching session once. |
| `--client` | Read every transcript you can read and search them on this device. |
| `-l, --selector <selector>` | Search the sessions a label selector picks. |
| `-o, --output <format>` | `text` (default) or `json` (JSON Lines). |

Sessions kept on a workstation or on your device are not searched unless you add `--client`, and standard error counts them.
The exit status is `0` when something matched and every session was searched, `1` when nothing matched and every session was
searched, and `2` for bad input, a failure or any skipped session, even with no match.

### `rl agentsession purge <name>`

Delete a session's stored records now, before their retention ends. It needs the `purge` right, which namespace administrators
hold. It asks once on a terminal, and it cannot be undone.

| Flag | Description |
|------|-------------|
| `--uid <uid>` | The session to purge when several deleted sessions share the name. |
| `-y, --yes` | Do not ask for confirmation. |

## Share a session

### `rl agentsession share <name>`

Share a session with people by creating a Grant. You must give `--access` or `--right`.

```bash
rl agentsession share fix-login --with user:alice@acme.com --access write
```

| Flag | Description |
|------|-------------|
| `--with <subject>` | The person, such as `user:alice@acme.com`. Repeatable. |
| `--access <read\|write>` | A level. `read` gives `transcript-read`, and `write` gives `transcript-read` and `attach`. One Grant per person. |
| `--right <right>` | One right: `transcript-read` or `attach`. `attach` includes reading. |
| `--all` | Share every session in the namespace. |
| `--admin` | The path for administrators. |
| `--allow-missing` | Create the Grant even if the session does not exist yet. |
| `--dry-run` | Print the Grant instead of creating it. |
| `-o, --output <format>` | `yaml` or `json`. Print the Grant and create nothing. |

Sharing again at another level changes the person's Grant. A change that would leave someone with more access than you asked,
through a Grant that names other people too, is refused.

### `rl agentsession unshare <name>`

Delete the Grant that shares the session.

| Flag | Description |
|------|-------------|
| `--with <subject>` | The person the share named. Repeatable. |
| `--right <right>` | Remove only a share of this right. |
| `--all` | The share targeted every session. |
| `--admin` | Remove the administrator's Grant. |

### `rl agentsession access <name>`

Report who can read or attach to a session, and through which Grant. With no Grants, it says that only the owner can read the
transcript or answer the session.

## Generic verbs

The group also has the verbs every kind has, as [Resource verbs](https://docs-stg.ringleader.dev/reference/cli/commands/resource-verbs/)
describes: `edit`, `delete`, `label`, `annotate`, `copy`, `get`, `describe` and `wait`. `delete [name...]` takes `-f <file>`,
`-l`, `-y` and `--to self`. Deleting a session whose transcript is on the workstation also removes that history. The prompt is
fixed once a session exists, so an edit that changes it is refused.

## Next steps

- [Agent sessions](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/): how a session works, and how to start and manage one.
- [AgentSession and AgentSessionConfig](https://docs-stg.ringleader.dev/reference/resources/agentsession/): the fields of both kinds.
- [Terminal session and worktree set commands](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/): the commands for plain shells.
- [Shares and access](https://docs-stg.ringleader.dev/reference/cli/commands/shares-access/): sharing other kinds.

