# LibTmux.Session

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Elixir
- **Kind:** struct
- **Source:** https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib/libtmux/entities.ex#L1
- **Page:** https://libtmux.org/en/elixir/pr-173/reference/libtmux-session/

An immutable session observation with explicit actions. Attachment retains tmux's client count.

## What is on here

A Session is a value captured in a `LibTmux.Snapshot`. Relationship functions
read the snapshot you pass; actions take a `LibTmux.Ref` and a Server or
Control connection. Start with these groups:

**Finding the session.** Select sessions from a captured snapshot, or look one
up by its exact ID. Neither contacts tmux. An ID that was not captured returns
`{:error, error}` with kind `:not_found`. Turn the session into a reference
tied to the server incarnation that supplied it, ready for an action.

- Select: `LibTmux.Snapshot.sessions/1`
- By ID: `LibTmux.Snapshot.fetch/3`
- Reference: `LibTmux.Ref.from_observation/1`

**Looking inside a session.** Read windows, panes and the active window from the
snapshot, without I/O. A window linked more than once appears once, and a
covered empty relation returns an empty selection. An invalid or stale
identity, or a relationship the snapshot did not capture, raises
`LibTmux.Error`. For per-session window indexes use `LibTmux.Snapshot.related/4`
with `:window_links`.

- Windows: `windows/2`
- Panes: `panes/2`
- Focused: `active_window/2`

**Creating a window.** Create a named detached window in the session through
one-shot execution. The completed value holds the new ID with `ref: nil`;
capture a fresh observation to obtain a reference. A Control connection is
unsupported, and a missing server is not started.

- Create: `new_window/4`
- Raise on failure: `new_window!/4`

**Renaming.** Rename the session through a Server or a Control connection.
A name holds 1..1024 UTF-8 bytes with no control characters, and tmux still
normalizes it. Observations you already hold keep the old name.

- Rename: `rename/4`
- Raise on failure: `rename!/4`

**Killing.** Kill the session and the windows and panes only it holds,
through a Server. A Control connection returns `unsupported_transport`.
Killing the last session ends a server that exits when empty.

- Kill: `kill/3`
- Raise on failure: `kill!/3`

## Members

### Collections and queries

- [`windows/2`](/en/elixir/pr-173/reference/libtmux-session-windows-2/) (function): Returns a selection of captured physical windows in first-link order.
- [`panes/2`](/en/elixir/pr-173/reference/libtmux-session-panes-2/) (function): Returns a selection of captured physical panes in numeric pane-ID order.

### Common operations

- [`id`](/en/elixir/pr-173/reference/libtmux-session-id/) (property): Required: building the struct without this key is an error.
- [`name`](/en/elixir/pr-173/reference/libtmux-session-name/) (property)
- [`attached`](/en/elixir/pr-173/reference/libtmux-session-attached/) (property)
- [`active_window/2`](/en/elixir/pr-173/reference/libtmux-session-active_window-2/) (function): Returns the captured active physical window, or `nil` when none is active.
- [`attached_count`](/en/elixir/pr-173/reference/libtmux-session-attached_count/) (property)

### Other members

- [`kill!/3`](/en/elixir/pr-173/reference/libtmux-session-kill-bang-3/) (function): Returns `:ok` when `kill/3` completes; raises API errors or `LibTmux.Action.CompletionError` otherwise.
- [`kill/3`](/en/elixir/pr-173/reference/libtmux-session-kill-3/) (function): Kills an exact session through one-shot execution.
- [`new_window!/4`](/en/elixir/pr-173/reference/libtmux-session-new_window-bang-4/) (function): Returns the created window value when `new_window/4` completes; raises the original error otherwise.
- [`new_window/4`](/en/elixir/pr-173/reference/libtmux-session-new_window-4/) (function): Creates a named detached window in an exact session through one-shot execution.
- [`rename!/4`](/en/elixir/pr-173/reference/libtmux-session-rename-bang-4/) (function): Returns `:ok` when `rename/4` completes; raises API errors or `LibTmux.Action.CompletionError` otherwise.
- [`rename/4`](/en/elixir/pr-173/reference/libtmux-session-rename-4/) (function): Renames an exact session; returns `{:ok, result}` on command completion.
- [`server_instance`](/en/elixir/pr-173/reference/libtmux-session-server_instance/) (property): Required: building the struct without this key is an error.
- [`t/0`](/en/elixir/pr-173/reference/libtmux-session-t-0/) (typealias): A session with explicit field coverage and an attachment count separate from its Boolean projection.

## In other ports

A tmux session

| Port | API | Differs from Elixir |
| --- | --- | --- |
| Elixir | `LibTmux.Session`. An immutable session observation with explicit actions. Attachment retains tmux's client count. | This page |
| Python | [`libtmux.Session`](/en/py/latest/reference/libtmux-session/) (class). tmux(1) Session [session_manual]. | None recorded in the model |
| Ruby | [`LibTmux::Session`](/en/ruby/latest/reference/libtmux-session-nvps/) (class). A session on one server, reached through a handle that wraps an EntityRef. A handle never caches state: each method runs one tmux command, and Entity#snapshot reads the session back as a record. Methods take timeout: and cancel:, and raise CommandError when tmux rejects the command. A listing that fails raises, so an empty array means tmux answered with nothing to list. | None recorded in the model |
| Lua | [`libtmux.Session`](/en/lua/latest/reference/libtmux-session/) (class) | None recorded in the model |
| PowerShell | [`LibTmux\Get-TmuxSession`](/en/powershell/latest/reference/libtmux-get-tmuxsession/) (cmdlet). Read sessions with optional exact selectors. | This cmdlet reads and returns shared .NET `LibTmux.Session` objects. Child windows and panes require further acquisition. |
| Julia | [`LibTmux.SessionSnapshot`](/en/julia/latest/reference/libtmux-sessionsnapshot/) (struct) | 2 overloads. `SessionSnapshot` holds captured session data. Actions use its `SessionRef`, a typed identity bound to an observed daemon generation. |
| Erlang | [`#tmux_model:session{}`](/en/erlang/latest/reference/tmux_model-session/) (struct) | None recorded in the model |
| Haskell | [`LibTmux.Snapshot.Session`](/en/haskell/latest/reference/libtmux-snapshot-t-session/) (data-type). Detached physical session. Navigate its appearances through WindowLink. | `Session` is a detached physical session. `WindowLink` records each placement of a window in it, and operations take a generation-bound `SessionRef`. |
| Common Lisp | [`libtmux:session`](/en/lisp/latest/reference/libtmux-session-type/) (class). A captured physical tmux session. | `session` is an immutable captured entity. The same name also has a relation accessor with a distinct public identity. |
| TypeScript | [`session.Session`](/en/ts/latest/reference/session-session/) (class). One session on one tmux server, as a handle rather than a copy of it. | None recorded in the model |
| Rust | [`session.Session`](/en/rs/latest/reference/session-session/) (struct). One tmux session, together with the snapshot it was discovered with. | None recorded in the model |
| Go | [`tmux.Session`](/en/go/latest/reference/tmux-session/) (struct). Session is one materialized tmux session record. It is normally returned by Server.Snapshot, Server.Session, or Session.Refresh. A zero Session is not a usable tmux target. | None recorded in the model |
| Java | [`io.github.libtmux.Session`](/en/java/latest/reference/io-github-libtmux-session-session/) (class). One tmux session, as one capture saw it. | readonly |
| Clojure | [`libtmux.core/sessions!`](/en/clojure/latest/reference/libtmux-core-sessions/) (function). Acquires captured sessions; acquisition failure throws. | Acquires a vector of captured session maps. The session value is a map, not a wrapper class. |
| Kotlin | [`io.github.libtmux.kotlin.Session`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-session/) (class). A tmux session and its captured windows and properties. | None recorded in the model |
| Scala | [`io.github.libtmux.scaladsl.Session`](/en/scala/latest/reference/io-github-libtmux-scaladsl-session/) (typealias). A captured session, opaque over the Java handle; every operation beyond equality is an extension, generated from the operation catalog or handwritten where the catalog marks it WAIT, STREAM or LIFECYCLE. | 2 overloads |
| C# | [`LibTmux.Session`](/en/csharp/latest/reference/libtmux-session/) (class). Represents an immutable session handle and snapshot. | None recorded in the model |
| F# | [`LibTmux.FSharp.Session`](/en/fsharp/latest/reference/libtmux-fsharp-session/) (module). Starts queries confined to one session. | This F# module builds deferred child queries from a shared .NET `LibTmux.Session` and its server association. `Query.list` acquires their results from tmux. |
| C++ | [`libtmux::Session`](/en/cxx/latest/reference/libtmux-session/) (class). One session, as one listing saw it. | None recorded in the model |
| Swift | [`Session`](/en/swift/latest/reference/session/) (struct). A tmux session, as it was when the listing was read. | None recorded in the model |
| OCaml | [`Libtmux.Session.t`](/en/ocaml/latest/reference/libtmux-session-t/) (typealias) | None recorded in the model |
| Perl | [`LibTmux::Session`](/en/perl/latest/reference/libtmux-session/) (class). Captured session entity | A captured read-only entity; explicit Server operations accept its stable identity. |
| Raku | [`LibTmux::Model::Session`](/en/raku/latest/reference/libtmux-model-session/) (class). Captured session with local window-link and group relationships. | None recorded in the model |
