# Terminal session and worktree set commands

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


> The rl commands that create and manage terminal sessions, worktree sets, sessions on this computer and the worktrees a workstation keeps.


The `rl terminalsession`, `rl worktreeset` and `rl localterminalsession` groups manage
[terminal sessions](https://docs.ringleader.dev/workstations/sessions/terminal-sessions/),
[worktree sets](https://docs.ringleader.dev/workstations/sessions/worktree-sets/) and sessions on this
computer. Two `rl workstation` commands list and remove the worktrees a workstation keeps. This
page lists each command with its arguments and flags. The fields of the objects are on
[TerminalSession and LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/)
and [WorktreeSet](https://docs.ringleader.dev/reference/resources/worktreeset/).

Every command here takes these flags, which the tables below leave out:

| 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. |

## `rl terminalsession`

Manage terminal sessions. Aliases: `terminalsessions`, `ts`, `terminal`, `term`, `terminals`. The
group's own verbs are below. It also has `edit`, `label`, `annotate` and `copy`, which work as
[Resource verbs](https://docs.ringleader.dev/reference/cli/commands/resource-verbs/) describes. To change a
session's panes, use `add-pane`, `move-pane` and `close-pane`.

## `rl terminalsession create <name>`

Create a terminal session on a workstation. The command writes the session and returns, and the
workstation starts the panes when it picks the session up. A name already in use fails, and
nothing is written.

```bash
rl terminalsession create my-shells --workstation my-box --panes main,logs,tests
rl terminalsession create fix --workstation my-box --worktree-set tls-floor
rl terminalsession create build --workstation my-box --panes main,tests \
  --command "tests=go test ./..." --initial-size 200x50 --record
```

| Flag | Description |
|------|-------------|
| `--workstation <name>` | **Required.** The workstation the panes run on. |
| `--panes <names>` | Pane names, comma-separated, in the order the session shows them. Each is a lowercase DNS label, and none repeats. Default `main`. |
| `--command <pane>=<command>` | A command for one pane's login shell to run in place of an interactive shell, as `-l -c`. Repeat for each pane. The pane must be in `--panes`. The pane closes when the command exits, and the command runs again when the session's server restarts. |
| `--workdir <dir>` | The directory the panes start in. A relative path is read from the login user's home. Default: the login user's home. It cannot change later. Ringleader does not create it. |
| `--worktree-set <name>` | A [worktree set](https://docs.ringleader.dev/workstations/sessions/worktree-sets/) on the same workstation that you own, for the panes to work in. Not with `--workdir`. It cannot change later. Deleting the session leaves the set's trees. |
| `--initial-size <COLSxROWS>` | The size the window opens at, such as `200x50`. Each number is from 2 to 1000. Default `80x24`. |
| `--record` | Keep a record of each pane's output on the workstation. Default off. The record holds up to 64 MiB for each pane, and stays 30 days after you delete the session or close the pane. |
| `-l, --labels <name=value>` | Labels, repeatable or comma-separated. |
| `--annotations <name=value>` | Annotations, repeatable or comma-separated. |
| `--dry-run` | Print the object instead of creating it. |
| `-o, --output <format>` | `yaml` or `json`. Print the manifest and create nothing. |

There is no flag for a record's retention. Set `recordingRetention` in a file.

## `rl terminalsession get` / `describe` / `delete` / `wait`

These work as [Resource verbs](https://docs.ringleader.dev/reference/cli/commands/resource-verbs/) describes.
`get` has the alias `list`. Their own flags follow.

| Command | Flag | Description |
|---------|------|-------------|
| `get [name...]` | `-A, --all-namespaces` | List every namespace. |
| `get` | `--mine` | List only the sessions you own. |
| `get` | `-l, --selector <selector>` | Label selector instead of names. |
| `get` | `-o, --output <format>` | `table`, `yaml`, `json` or `jsonpath='{.path}'`. Default `table`. |
| `get` | `-w, --watch` | Watch for changes. |
| `get`, `describe` | `--to <origin>`, `--origin <origin>` | Read from one origin by name, or `self` for this device, instead of the default routing. |
| `get` | `--out-of-policy`, `--reveal` | Accepted, and they apply to other kinds. |
| `describe [name...]` | `-A`, `-l` | As for `get`. |
| `describe` | `--timestamps <zone>` | `utc` or `local`. Default `utc`. |
| `delete [name...]` | `-f, --filename <file>` | A file, a URL or `-`: delete every object it declares. Repeatable. |
| `delete` | `-l, --selector <selector>` | Label selector instead of names. |
| `delete` | `--to self` | Delete from this device only. |
| `delete` | `-y, --yes` | Skip the confirmation prompt. Its prompt is for Workstations and Secrets. |
| `wait [name...]` | `--for <condition>` | A phase name such as `Running` or `Stopped`, `Deleted`, `condition=<Type>[=<Status>]` or `jsonpath='{<path>}'=<value>`. The flag's default is `Ready`. |
| `wait` | `--timeout <duration>` | How long to wait before giving up. `0` means no limit. Default `20m0s`. |
| `wait` | `--all`, `-A`, `-l` | Wait on every session in the namespace, in every namespace, or by selector. |

`get` prints `NAME`, `WORKSTATION`, `PHASE`, `PANES`, `BUILD` and `AGE`, with `NAMESPACE`, `OWNER`
and `ORIGINS` where they apply. `rl terminalsession wait my-shells --for Running` returns once the
session runs.

After you delete a session, the command says what stays behind:

- A session that names a worktree set leaves the set's trees. The message tells you to delete the
  set with `rl worktreeset delete` once no session runs in it.
- A set that the app or the console made for the session is deleted once no session has named it
  for 10 minutes. The message says how to keep it.
- A session with a `directory` leaves the directory as it is.
- A recorded session leaves its records on the workstation, and the message says until when.

## `rl terminalsession attach <session>`

Carry a session's terminal protocol on standard input and output. This command is for a terminal
client such as the Ringleader desktop app. It draws nothing, and it refuses to start when standard
input or output is a terminal. Use `rl shell` or `rl tmux` to get a shell in your own terminal.

Attaching needs two rights, and the command checks both before it connects: `attach` on the
session, which its owner gives with `rl terminalsession share`, and `ssh` on the session's
workstation, which its owner gives with `rl workstation share`. The command then opens the
session's socket on the workstation over SSH. It passes on only frames that list, read or search
the session's panes, type into a pane, or move focus to a pane or resize it. Standard output holds
only the server's frames, and messages go to standard error. The command exits 0 when either side
ends the connection. A server that speaks another protocol version is refused by name.

| Flag | Description |
|------|-------------|
| `--pane <name>` | Pass on frames for this pane only. |
| `--streams` | Carry several clients over one process and one SSH connection. Each client names its own pane, and the command checks both rights again for each. The desktop app uses it for each pane it shows. |
| `--local` | Attach to a [LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/#localterminalsession) in the `local` namespace on this computer. It asks for no grant, uses no SSH, and needs no running daemon. |

Inside a workstation, the command attaches only to a session that the workstation created and
runs. It asks for the `attach` right alone, and opens the socket without SSH. When the session
records its panes, the command says so in one line on standard error before the first frame.

## `rl terminalsession add-pane <session>`

Add a pane to a session. The pane runs a login shell, or a command that shell runs.

```bash
rl terminalsession add-pane my-shells --after main --name tests --command "go test ./..."
```

| Flag | Description |
|------|-------------|
| `--after <pane>` | The pane the new pane goes after. Default: the end. |
| `--command <command>` | A command for the pane's login shell to run in place of an interactive shell. The pane closes when it exits. |
| `--name <name>` | The new pane's name. Default: `d` and eight random lowercase letters and digits. |

The new pane starts in the first of these places that applies: the first tree of the session's
worktree set, the current directory of the pane before it when that pane is running, the current
directory of the last running pane, and then the session's `--workdir` or the login user's home.
When the login user cannot open the directory of the second or third, the pane starts in the
last place.

## `rl terminalsession close-pane <session> <pane>`

Close one pane, which ends its process. Closing the last pane closes the session.

```bash
rl terminalsession close-pane my-shells tests
```

## `rl terminalsession move-pane <session> <pane>`

Move one pane to before or after another pane. Give one of the two flags.

| Flag | Description |
|------|-------------|
| `--before <pane>` | The pane the moved pane goes before. |
| `--after <pane>` | The pane the moved pane goes after. |

## `rl terminalsession upload <session> -- <path>...`

Upload files and folders to the session's workstation, and print their paths to paste into a pane.
Write `--` before the paths, so a path that starts with `-` stays a path. The desktop app runs this
command when you drop a file on a pane. Uploading needs the same two rights as attaching.

```bash
rl terminalsession upload my-shells -- ./build.log ./results
```

The files land on the workstation's virtual machine, never in a dev container, in a directory that
only the login user can read:
`<home>/.ringleader/terminal/<session uid>/drops/<UTC time>-<8 hex digits>/<n>/<name>`. In a file
name, each control character, each backslash and each byte that is not UTF-8 becomes `_`, and the
name is cut to 200 bytes. A folder is copied whole, and its archive holds at most 64 MiB. The files
stay until you delete the session or its login user changes.

Standard output holds only the text to paste: each path quoted, one space between them and one
after the last, with no newline. It reads back as the paths in sh, bash, zsh and fish, and a csh
or tcsh login shell is not supported. When any path fails, the command exits 1 and prints no text
to paste, and the files it already uploaded stay. Inside a workstation, the command uploads
nothing, checks the `attach` right, and prints the paths you gave, made absolute and quoted.

| Flag | Description |
|------|-------------|
| `-o, --output <format>` | `text` or `json`. `json` prints `{"paths": [...], "paste": "..."}`. Default `text`. |

## `rl terminalsession upgrade [name...]`

Move sessions onto the deployment's current terminal build. A running session keeps the build it
started on. This command asks for a restart, which ends every process in the session. The command
returns once the workstation accepts the request. The workstation then fetches the build, restarts
the session's server, and starts the panes again as new processes. A session already on the
current build is left alone. While a release is in progress, the command can say that the session
keeps its build. Run it again after the release.

```bash
rl terminalsession upgrade my-shells
rl terminalsession upgrade -l team=infra
```

| Flag | Description |
|------|-------------|
| `-l, --selector <selector>` | Label selector instead of names. |
| `-A, --all-namespaces` | Upgrade sessions in every namespace. |

## `rl terminalsession transcript <session>`

Print what one pane recorded. You need the `transcript-read` right on the session, which `attach`
includes, and the `ssh` right on its workstation.

```bash
rl terminalsession transcript my-shells --pane main
rl terminalsession transcript my-shells --pane main --at 10m
```

With no `--at`, the command prints every line of the pane's text log. When the pane has several
records, it prints each in the order it started, after a line saying when. A line in brackets says
where output was not recorded, or where a record ends.

| Flag | Description |
|------|-------------|
| `--pane <name>` | **Required.** The pane to print. |
| `--at <time>` | Print the screen as the snapshot at or before this moment shows it, without colors. An RFC 3339 time, or a duration back from now such as `10m`. |
| `--format <format>` | `text` or `asciicast`. Default `text`. `asciicast` writes the newest record's raw output and resizes as asciicast v2, or with `--at` the record that covers that moment. |

## `rl terminalsession share <name>`

Share a session with subjects by creating a Grant. Without `--access`, the Grant gives `attach`.
Each person also needs `ssh` on the session's workstation.

```bash
rl terminalsession share my-shells --with user:alice@acme.com
rl terminalsession share my-shells --with user:alice@acme.com --access read
```

| Flag | Description |
|------|-------------|
| `--with <subject>` | The subject to share with, such as `user:alice@acme.com`. Repeatable. |
| `--access <level>` | `read` grants `transcript-read` only, so the person cannot attach. `write` grants `attach` and `transcript-read`. One Grant for each person. Sharing a person at `read` deletes their earlier attach-only Grant. If that Grant also names other people, the command stops and changes nothing. |
| `--all` | Target every terminal session in the namespace. |
| `--admin` | The administrator path: grant on any subject's session. Gated by RBAC. |
| `--allow-missing` | Create the Grant before the session exists. Skips only the check that the session exists. |
| `--dry-run` | Print the Grant instead of creating it. |
| `-o, --output <format>` | `yaml` or `json`. Print the Grant and create nothing. |

## `rl terminalsession unshare <name>`

Delete the Grant that shares a session. It removes both a person's attach share and their level
share.

| Flag | Description |
|------|-------------|
| `--with <subject>` | The subject the share named. Repeatable. |
| `--all` | The share targeted every session. |
| `--admin` | Delete the administrator Grant instead of your own. |

## `rl terminalsession access <name>`

Report who can read the session's record or attach to it, and through which Grant.

## `rl worktreeset`

Manage worktree sets. Alias: `worktreesets`. Its verbs are `create`, `get`, `describe`, `edit`,
`delete`, `wait`, `label`, `annotate` and `copy`. It has no `share`, `attach` or `upgrade`.
`get`, `describe`, `delete`, `edit` and `wait` take the same flags as the `rl terminalsession`
verbs of the same name.

## `rl worktreeset create <name>`

Create a worktree set on a workstation. The command writes the set and returns, and the workstation
makes the trees. Check them with `rl worktreeset get <name>`. A name already in use fails, and
nothing is written.

```bash
rl worktreeset create tls-floor --workstation my-box \
  --path sessions/ringleader/tls-floor --branch fix/tls-floor \
  --source ringleader --source infra
```

| Flag | Description |
|------|-------------|
| `--workstation <name>` | **Required.** The workstation the trees are made on. It cannot change later. |
| `--path <dir>` | **Required.** The directory that holds the trees, absolute or relative to the login user's home. Write a home path without `~`. Each tree is at `<path>/<source>`. It cannot change later. |
| `--branch <name>` | **Required.** The branch every tree is on, exactly as written. A branch of that name that a source's clone already has is continued. It cannot change later. |
| `--source <name>` | **Required**, at least once. A workstation source the set holds a tree of. Repeat for each, in order. A set holds one to eight. You can change the sources later with `rl worktreeset edit`. |
| `-l, --labels <name=value>` | Labels, repeatable or comma-separated. |
| `--annotations <name=value>` | Annotations, repeatable or comma-separated. |
| `--dry-run` | Print the object instead of creating it. |
| `-o, --output <format>` | `yaml` or `json`. Print the manifest and create nothing. |

`rl worktreeset delete <name>` is refused while a terminal session names the set, and while an
agent session that names it is running. For each tree it prints that the tree is removed once it
holds no unsaved work, and that `rl workstation list-worktrees` lists it until then. The branch
stays in the source's clone. `rl worktreeset wait` has the same flags as above. Its default
`--for` is `Ready`, the phase a set reaches when every tree is made.

## `rl localterminalsession`

Manage terminal sessions on this computer. Alias: `localterminalsessions`. Its verbs are `create`,
`get`, `describe`, `edit`, `delete`, `wait`, `label`, `annotate` and `copy`, with the flags of the
`rl terminalsession` verbs of the same name.

`create <name>` takes only `--dry-run` and `-o <format>`, which print the object as `yaml` or
`json` instead of creating it. It writes a session with a name and no panes, and `-o yaml` prints that file for you to
complete. Write the full session in a file and apply it with `rl apply -f`, as
[TerminalSession and LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/#localterminalsession)
shows. Attach to one with `rl terminalsession attach --local`, from a terminal client such as the
desktop app.

## `rl workstation list-worktrees <workstation>`

List the worktrees a workstation holds because they wait or because they hold unsaved work. The
list comes from the workstation's status, so the command needs no connection to the workstation.

```bash
rl workstation list-worktrees my-box
```

The table has the columns `PATH`, `SOURCE`, `SESSION` and `STATE`. `being made` means the
workstation is making the tree. `blocked` means something on the workstation has to change first.
`refused` means the session's worktree entry cannot be met as written. A tree whose session was
deleted is `blocked`, and only the session's uid is known for it. A made tree of a set that still
exists does not appear. When the workstation holds nothing, the command says so.

| Flag | Description |
|------|-------------|
| `-o, --output <format>` | `json`. Default: a table. |

## `rl workstation remove-worktree <workstation> <path>`

Remove one worktree that a workstation keeps, after showing what the removal destroys. Name the
tree by the path `list-worktrees` shows. The command connects to the workstation over SSH, so
the workstation must be one this device can reach.

```bash
rl workstation remove-worktree my-box sessions/ringleader/tls-floor/infra
```

The command prints the tree's path, source and session. It then prints either `The workstation
found nothing in it that git has not saved.` or `Removing it destroys:` with a list of what is
lost. It asks `Remove it?`. If you decline, it prints `Not removed.` and exits 1. With no terminal
to ask on and no `--yes`, it exits 2. On success it prints `removed` and the path. The workstation
removes the tree on its next pass, usually within a minute, and only when no session on it still
declares the tree and no agent runs in it. The removal cannot be undone.

| Flag | Description |
|------|-------------|
| `-y, --yes` | Remove the tree without asking. Required when there is no terminal to ask on. |

## Next steps

- [Terminal sessions](https://docs.ringleader.dev/workstations/sessions/terminal-sessions/): open a session,
  share it and read its record.
- [Worktree sets](https://docs.ringleader.dev/workstations/sessions/worktree-sets/): create a set and remove
  a kept worktree.
- [Agent session commands](https://docs.ringleader.dev/reference/cli/commands/agent-sessions/): the
  commands that run a coding agent in a set.
- [Shares and access](https://docs.ringleader.dev/reference/cli/commands/shares-access/): the command that
  gives the `ssh` right a session needs.

