# Terminal sessions

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


> A terminal session is a named set of shells on a workstation, called panes, that keep running when you close the app, sleep your laptop or lose your network.


A terminal session is a named set of shells on a workstation, called panes, that keep running
when you close the app, sleep your laptop or lose your network. You open a session in the
Ringleader desktop app or the web console, work in one pane at a time, and come back later to
the same shells and the same scrollback. You can add panes, run a command in a pane, share a
session with a teammate and record what a pane printed.

Two other ways to get a shell on a workstation work differently. `rl shell` opens one shell over
SSH, and it ends when the connection drops. `rl tmux` attaches to the one tmux session each
workstation has, in your own terminal. A terminal session is an object you declare: you list
sessions with `rl terminalsession get`, a workstation can have several, each has named panes,
and a grant can share it. For `rl shell` and `rl tmux`, see
[Shells and remote commands](https://docs.ringleader.dev/workstations/connectivity/shells-remote-commands/).

To start, create a session from the command line, then open it in the app:

```bash
rl terminalsession create my-shells --workstation my-box --panes main,logs
```

In the desktop app, open **Terminals** and choose `my-shells` under `my-box`. If that is all you
need, you are done. The sections below say what survives a restart, where panes start, who can
open a session and what recording keeps.

`rl terminalsession attach` does not open a shell for you. It speaks a protocol to a terminal
program such as the Ringleader desktop app, and it refuses to start when its input or output is a
terminal. To get a shell in your own terminal, use `rl shell` or `rl tmux`.

## What survives and what does not

A session keeps its shells running while nothing is attached. Closing the app, sleeping the
laptop and losing the network end nothing. When you open the session again, you see the same
panes and the same scrollback.

A restart of the session's terminal server ends every shell. That happens when the server
crashes, when the workstation stops and starts, and when you run `rl terminalsession upgrade`.
The panes come back as new shells, and a pane that runs a command runs it again.

A pane whose shell or command exits closes and stays closed. When every pane has exited, the
session deletes itself. So a one-pane session whose command fails at once disappears shortly
after you create it. Deleting a session ends its processes. A stopped workstation shows its
sessions as `Stopped`, and a session whose workstation was deleted, or whose lease ended, stays
`Stopped`.

A live shell also keeps the workstation awake, which
[Find what keeps a workstation awake](#find-what-keeps-a-workstation-awake) describes.

## How a pane starts and where

Each pane is a login shell of the workstation's login user, on the workstation's virtual
machine. A pane with a command runs it through that shell with `-l -c`, so your profile sets
`PATH` first, and the pane closes when the command exits. You cannot change a pane's command.
Close the pane and add it again with the new command.

A session's first panes start in the first of these places that applies:

1. The first tree of the session's [worktree set](https://docs.ringleader.dev/workstations/sessions/worktree-sets/), when the session names one.
2. The directory the session names with `--workdir`. A relative path is read from the login
   user's home. Ringleader does not create it. While the login user cannot enter it, panes
   start in the home directory and the session's status says so.
3. The login user's home directory.

A pane you add later starts in the first of these places that applies:

1. The first tree of the session's worktree set, when the session names one.
2. The current directory of the pane before it, when that pane is running.
3. The current directory of the last running pane.
4. The session's `--workdir`, or else the login user's home.

When the login user cannot open the directory in step 2 or 3, the pane starts in the place of
step 4.

A pane's name is a lowercase label of at most 63 characters, and no two panes in a session share
one. The window opens at 80 columns by 24 rows, and widens when you attach from a wider window.
Set another size with `--initial-size` when you create the session.

## Desktop app and web console

You open a session in the Ringleader desktop app on macOS or Windows, or in the web console.
There is no Linux desktop app, no terminal view in `rl tui`, no split pane (one pane shows at a
time) and no client for your own terminal.

In the desktop app, the **Terminals** route lists a row for this computer, then one row for each
workstation you hold. Each row lists its sessions, and a strip above the terminal shows
the open session's panes. Selecting a session in the list opens it. The app lists every session
you can reach, including ones you created with `rl terminalsession create`. It keeps a viewed
pane connected for about two hours after you last show it.

In the console, a workstation's details page has a **Terminals** tab, and the **Terminals** page
lists your sessions. The console opens sessions only for workstations you own that are not tied
to one computer, and only the workstation's owner can open them there. You must also
hold the attach right on the session, but you need no SSH access. Open any other workstation's
sessions in the desktop app.

A Projects route exists as a preview. It stays hidden unless the `terminal-projects.visible` rule
is turned on, and this page does not describe it.

### Rules that show the Terminals routes

Three rules decide what you see. An administrator of your Ringleader deployment sets them, and
`rl featureflag mine` shows the value each has for you. They show or hide screens: a grant
still decides who may open a session.

| Rule | Default | What it shows | Change it on one device |
|------|---------|---------------|-------------------------|
| `desktop.terminals-route` | on | The **Terminals** route in the desktop app. | `rl node settings set desktop.terminals false`, then restart the app. |
| `desktop.local-terminals-route` | on | The row for this computer in **Terminals**. | `rl node settings set flag.desktop.local-terminals-route false` |
| `terminal-relay` | on | Lets the web console open terminal sessions. | None. When it is off for you, the console tells you to ask your administrator. |

A device setting changes only what that device shows. Run `rl node settings unset` with the same
setting to remove it. Setting `flag.desktop.terminals-route` is refused, because
`desktop.terminals` is the setting for that route.

### Keyboard shortcuts

The app and the console take these chords before the pane sees them. A button in the app's header
opens a **Keyboard shortcuts** dialog that lists them. On macOS, a shell loses only Option+J and
Option+K. On Windows, a shell loses every chord in the Windows column. The console uses
Alt+Shift, written Option+Shift on macOS, because a browser keeps the Ctrl and Cmd chords. The
console's chords have not been checked on Linux. On Windows with several input languages,
Alt+Shift can switch the input language.

| Action | macOS | Windows | Console |
|--------|-------|---------|---------|
| New pane | Cmd+Enter | Ctrl+Shift+Enter | Alt+Shift+N |
| Close pane | Cmd+W | Ctrl+Shift+W | Alt+Shift+W |
| Close session (asks first) | Cmd+Shift+W | Ctrl+Shift+Backspace | Alt+Shift+Backspace |
| Next pane, previous pane | Cmd+L, Cmd+H | Ctrl+Shift+L, Ctrl+Shift+H | Alt+Shift+L, Alt+Shift+H |
| Move pane forward, back | Cmd+Shift+L, Cmd+Shift+H | Ctrl+Shift+Right, Ctrl+Shift+Left | Alt+Shift+Right, Alt+Shift+Left |
| Next session, previous session | Cmd+J, Cmd+K | Ctrl+Shift+J, Ctrl+Shift+K | Alt+Shift+J, Alt+Shift+K |
| Move session forward, back | Cmd+Shift+J, Cmd+Shift+K | Ctrl+Shift+Down, Ctrl+Shift+Up | Alt+Shift+Down, Alt+Shift+Up |
| Next, previous workstation (in the app, also this computer) | Option+J, Option+K | Alt+J, Alt+K | Alt+Shift+PageDown, Alt+Shift+PageUp |

## Recording

A session records nothing unless you ask. Create it with `--record` (or `recording: box` in its
file), and Ringleader keeps each pane's output on the workstation, in
`~/.ringleader/terminal-records`.

<div class="callout callout-warning">
  <p class="callout-title">A record holds everything a program prints</p>
  <div class="callout-body">
    A record holds output only, never your keystrokes: a password you type at a prompt that does
not echo is not recorded. But anything a program prints is recorded, such as a token that a
command prints or a secret you <code>cat</code>, and nothing removes it. Anyone who can log in to the
workstation as the login user can read the record files. A record stays on the workstation, up
to 64 MiB for each pane. By default Ringleader keeps it 30 days after you delete the session or
close the pane, and never longer. It goes when the workstation is deleted.
  </div>
</div>


A record covers one pane for the life of one terminal server. A reused pane name, or a server
restart, starts a new record. When a record reaches 64 MiB, it stops, and reading it says where.
You can shorten how long Ringleader keeps records with `recordingRetention` (for example `7d`
or `72h`) in the session's file. You cannot lengthen it. Only the session's owner can turn
recording on. When a session records, `rl terminalsession attach` says so on its standard error
before it passes on the first frame.

## Who can open a session

The session's owner, and an administrator of its namespace, can open it. To let someone else open
it, share it with `rl terminalsession share`, which creates a
[Grant](https://docs.ringleader.dev/organizations-teams/accounts-access/roles-grants/#grants). A session has
two rights:

- `attach` lets a person open the session and type in it.
- `transcript-read` lets a person read a pane's record. `attach` includes it.

Opening a session through Ringleader also needs the `ssh` right on its workstation, which you
give with `rl workstation share`. Sharing the session alone is not enough. The web console
instead needs the attach right and your ownership of the workstation.

<div class="callout callout-warning">
  <p class="callout-title">Anyone with SSH access to the workstation can reach the shells</p>
  <div class="callout-body">
    A pane runs as the workstation&rsquo;s login user. A person who can log in to the workstation as that
user can reach every session&rsquo;s shells from a shell of their own, whatever the session&rsquo;s grants
say. Share a workstation&rsquo;s <code>ssh</code> right only with people you would trust with those shells.
  </div>
</div>


`rl terminalsession access my-shells` shows who can open the session or read its record, and
through which grant.

## Sessions on this computer

A session on this computer runs on your own computer, not on a workstation, and the desktop
app lists it in the row for this computer. It is a `LocalTerminalSession`. Your computer's daemon
runs it, it works while you are signed out, and signing in never copies it to a control plane.

It is simpler than a workstation's session. It lives in the `local` namespace, and it has panes,
a start directory and a window size. It has no recording, no worktree set, no sharing and no
console view, and a file dropped on one of its panes is refused. Create one with **New session** under the row for this computer, or write a
file and apply it. [TerminalSession and LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/#localterminalsession)
lists its fields.

## Create a session

Create a session on a workstation, and the workstation starts its panes when it picks the
session up. The session is `Pending` until it does.


### Use the application


1. In the desktop app, open **Terminals**.
2. On the workstation's row, choose **New session**.
3. Enter a **Name**.
4. Optional: tick **Make a worktree set for this session**, then enter its **Path** and
   **Branch**. [Worktree sets](https://docs.ringleader.dev/workstations/sessions/worktree-sets/) says what
   this creates and when Ringleader deletes it.
5. Choose **Create session**.

The session opens with one pane and appears last in the list.



### Use the command line


Run `rl terminalsession create` with the workstation, and with the panes you want:

```bash
rl terminalsession create my-shells --workstation my-box --panes main,logs,tests
```

Give a pane a command with `--command`, once for each pane. Start a pane in a directory with
`--workdir`, or in a worktree set with `--worktree-set` (not both). Keep a record with
`--record`.

```bash
rl terminalsession create fix --workstation my-box --workdir src/app \
  --panes main,tests --command "tests=go test ./..." --initial-size 200x50 --record
```

The command writes the session and returns. Check its phase with
`rl terminalsession get my-shells`, or wait for it:

```bash
rl terminalsession wait my-shells --for Running
```

A name already in use fails, and nothing is written. To declare the session in a file, see
[TerminalSession and LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/).






## Check why a session is Pending

A new session is `Pending` until its workstation reports the session's panes, and its
`status.message` says what it waits for. Read it with `rl terminalsession describe my-shells`.

| Message starts | What to do |
|----------------|------------|
| `Waiting for my-box, which is` followed by a phase | Start the workstation, for example with `rl workstation start my-box`. |
| `Waiting for the agent on my-box to be updated` | The workstation's agent is too old to run terminal sessions. Wait for it to update. |
| `Starting this session's server` or `Starting this session's panes` | Nothing: the workstation is starting them. |

A session that names a worktree set also waits until the workstation has made the set's trees.
[Worktree sets](https://docs.ringleader.dev/workstations/sessions/worktree-sets/#when-a-tree-waits) lists
what holds a tree up.

## Add, move and close panes

Add a pane to a running session, move it within the strip, or close it. Closing a pane ends its
process, and closing the last pane closes the session.


### Use the application


In **Terminals**, open the session. Above the terminal, a strip shows its panes in order.

- To add a pane, choose **New pane** (the plus button). It goes after the pane you are
  viewing.
- To move a pane, show it, then choose **Move pane back** or **Move pane forward**.
- To close a pane, choose its close button. When it is the last pane, the app asks before it
  closes the session.

The chords in [Keyboard shortcuts](#keyboard-shortcuts) do the same.



### Use the command line


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

`add-pane` puts the pane at the end unless you give `--after`, and names it `d` and eight random
characters unless you give `--name`.






## Upload a file to a session

Send a file or folder from your computer to a session's workstation, and paste its path into a
pane. Files land on the workstation's virtual machine, never in a dev container, in a
directory only the login user can read. Ringleader keeps them until you delete the session.
A session on this computer takes no dropped file.


### Use the application


Drag a file onto a pane. The app uploads it and pastes its path into the pane.



### Use the command line


Write `--` before the paths. The command prints the quoted paths to paste, one space after each:

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

You need the attach right on the session and the `ssh` right on its workstation. A folder is
copied whole, up to 64 MiB. The text reads back as paths in sh, bash, zsh and fish, and a csh or
tcsh login shell is not supported. If any path fails, the command exits 1 and prints nothing to
paste, and the files it uploaded before the failure stay.






## Share a session

Give a teammate the right to open your session from the command line. They also need the `ssh`
right on the workstation.

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

`share` grants `attach` by default. To let someone read a pane's record without typing in the
session, share at a level:

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

`--access read` grants `transcript-read` only, and `--access write` grants both rights. Sharing a
person at `read` again deletes an earlier attach-only grant for them. If that grant also names
other people, the command stops and changes nothing. `--all` shares every session in the
namespace. To take access back, run `rl terminalsession unshare` with the same `--with`. The
[`rl terminalsession` commands](https://docs.ringleader.dev/reference/cli/commands/terminal-sessions/#rl-terminalsession-share-name)
list every flag.

## Read a pane's record

Print what a recorded pane printed. 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
```

With no `--at`, the command prints every line the pane's text log holds. When a 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. To see the screen as it was at one
moment, give `--at` a time or a duration back from now:

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

To replay a record in a player such as asciinema, write the newest record's raw output with
`--format asciicast`.

## Upgrade a session

A running session keeps the terminal build it started on, even after the deployment ships a new
one. `rl terminalsession get` shows each session's build, and the current build beside it when the
two differ. To move a session to the current build, run:

```bash
rl terminalsession upgrade my-shells
```

Upgrading restarts the session's server, which ends every process in it. The panes come back as
new shells, and a pane with a command runs it again. The command returns once the workstation
accepts the request. A session already on the current build is left alone. During a release,
the command can tell you it kept the session's build. Run it again after the release. Give
`-l` a label selector, or `-A`, to upgrade several sessions.

## Find what keeps a workstation awake

A running shell in a terminal session keeps a workstation's idle policy from stopping it,
whatever conditions you declare, and whether or not anyone is attached. Run
`rl workstation describe my-box` and read **Idle policy**. While a session's shell is running,
the **In use because** line says `a terminal session has a live process`.

When every shell has exited, or you delete the sessions, the conditions you declared decide
again. Deleting the sessions is how you let the workstation stop. See
[Idle stop](https://docs.ringleader.dev/workstations/lifecycle/starts-stops-restarts/#idle-stop) for the
idle policy.

## Delete a session

Delete a session to end its shells. Ringleader asks first in the app.


### Use the application


In **Terminals**, open the menu of the session and choose **Close session**. The app asks before
it ends the shells.



### Use the command line


```bash
rl terminalsession delete my-shells
```

The command then says what stays: a worktree set keeps its trees, a `--workdir` directory stays
as it is, and a recorded session's records stay on the workstation until their retention ends.






## Next steps

- [Worktree sets](https://docs.ringleader.dev/workstations/sessions/worktree-sets/): give a session's panes
  a git worktree of each source on one branch.
- [Agent sessions](https://docs.ringleader.dev/workstations/sessions/agent-sessions/): run a coding agent
  on a workstation, with the same worktree sets.
- [Terminal session and worktree set commands](https://docs.ringleader.dev/reference/cli/commands/terminal-sessions/):
  every command and flag.
- [TerminalSession and LocalTerminalSession](https://docs.ringleader.dev/reference/resources/terminalsession/):
  every field of a session.
- [Roles and grants](https://docs.ringleader.dev/organizations-teams/accounts-access/roles-grants/): how a
  grant gives someone access.

