# session.Session

- **Module:** session
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-ts/blob/46cccfef2a546de55ce8b308249b8c76339089a0/packages/libtmux/src/session.ts#L64
- **Page:** https://libtmux.org/en/ts/latest/reference/session-session/

One session on one tmux server, as a handle rather than a copy of it.

Reached from [`Server.sessions`](/en/ts/latest/reference/server-server-sessions/) or by creating one; the constructor
throws. The tmux format row the handle was built from reads back through
[`format`](/en/ts/latest/reference/session-session-format/), and by tmux's own field names directly on the handle — a snapshot
taken when the handle was made, not a live view.

A session outlives the clients attached to it: killing the last client
leaves the session running, which is the property the whole tool is built
around.

## Members

### Parent objects

- [`server`](/en/ts/latest/reference/session-session-server/) (attribute): The server this handle addresses.

### Collections and queries

- [`windows`](/en/ts/latest/reference/session-session-windows/) (method): Windows placed in this session, in listing order.
- [`panes`](/en/ts/latest/reference/session-session-panes/) (method): Panes contained by this session's windows.

### Common operations

- [`newWindow`](/en/ts/latest/reference/session-session-newwindow/) (method): Create a window in this session and resolve it as a handle.
- [`kill`](/en/ts/latest/reference/session-session-kill/) (method): Destroy this session.
- [`rename`](/en/ts/latest/reference/session-session-rename/) (method): Rename this session.
- [`showHooks`](/en/ts/latest/reference/session-session-showhooks/) (method): Every hook this session reports.
- [`showOptions`](/en/ts/latest/reference/session-session-showoptions/) (method): Every option set on this session itself, not the ones it inherits.
- [`showEnvironment`](/en/ts/latest/reference/session-session-showenvironment/) (method): Every variable in this session's environment.
- [`detach`](/en/ts/latest/reference/session-session-detach/) (method): Detach every client attached to this session.
- [`activeWindow`](/en/ts/latest/reference/session-session-activewindow/) (method): The window tmux marks active in this session.
- [`setOption`](/en/ts/latest/reference/session-session-setoption/) (method): Set an option on this session.
- [`unsetOption`](/en/ts/latest/reference/session-session-unsetoption/) (method): Remove an option from this session.
- [`setHook`](/en/ts/latest/reference/session-session-sethook/) (method): Bind a tmux command to a hook on this session.
- [`setEnvironment`](/en/ts/latest/reference/session-session-setenvironment/) (method): Set a variable in this session's environment.
- [`unsetEnvironment`](/en/ts/latest/reference/session-session-unsetenvironment/) (method): Drop a variable from this session's environment entirely.
- [`activePane`](/en/ts/latest/reference/session-session-activepane/) (method): The pane tmux marks active in this session's active window.
- [`refreshed`](/en/ts/latest/reference/session-session-refreshed/) (method): This session, read again at a new instant.
- [`unsetHook`](/en/ts/latest/reference/session-session-unsethook/) (method): Remove a hook from this session.
- [`removeEnvironment`](/en/ts/latest/reference/session-session-removeenvironment/) (method): Mark a variable in this session's environment for removal from the environment of processes tmux starts, leaving the entry in place.
- [`selectWindow`](/en/ts/latest/reference/session-session-selectwindow/) (method): Select the last, next, or previous window, or one named by target.
- [`cmd`](/en/ts/latest/reference/session-session-cmd/) (method): Run a tmux command this package does not model, addressed at this session.
- [`fromEnv`](/en/ts/latest/reference/session-session-fromenv/) (method): Resolve the session this process is running inside.
- [`getEnvironment`](/en/ts/latest/reference/session-session-getenvironment/) (method): One variable from this session's environment, or `undefined` when tmux carries no entry.
- [`equals`](/en/ts/latest/reference/session-session-equals/) (method): Whether `other` is this same session on this same server.
- [`plan`](/en/ts/latest/reference/session-session-plan/) (method): The same mutations, described instead of run.
- [`sameTmuxIdAs`](/en/ts/latest/reference/session-session-sametmuxidas/) (method): Whether `other` carries the same `$n`, wherever it came from.
- [`showResolvedOptions`](/en/ts/latest/reference/session-session-showresolvedoptions/) (method): The option values that govern this session, own and inherited together.

### Other members

- [`constructor`](/en/ts/latest/reference/session-session-constructor/) (method)
- [`format`](/en/ts/latest/reference/session-session-format/) (property): The raw tmux format row, addressed by tmux's own token names.
- [`sessionBrand`](/en/ts/latest/reference/session-session-sessionbrand/) (attribute)
- [`toString`](/en/ts/latest/reference/session-session-tostring/) (method): How this handle renders in a log line, a template literal, or an error.

## Guides

Pages that discuss `Session`.

### Concepts

- [Server, session, window, pane](/en/ts/latest/concepts/server-session-window-pane/)

### Ports

- [TypeScript workspace builder behavior](/en/ts/latest/workspace/internals/topics/)
- [TypeScript workspace builder API](/en/ts/latest/workspace/reference/)

### Topics

- [Architecture](/en/ts/latest/topics/architecture/)

## In other ports

A tmux session

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Session`](/en/py/latest/reference/libtmux-session/) (class) |
| Ruby | [`LibTmux::Session`](/en/ruby/latest/reference/libtmux-session-nvps/) (class) |
| Lua | [`libtmux.Session`](/en/lua/latest/reference/libtmux-session/) (class) |
| PowerShell | [`LibTmux\Get-TmuxSession`](/en/powershell/latest/reference/libtmux-get-tmuxsession/) (cmdlet). 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). `SessionSnapshot` holds captured session data. Actions use its `SessionRef`, a typed identity bound to an observed daemon generation. |
| Elixir | [`LibTmux.Session`](/en/elixir/latest/reference/libtmux-session/) (struct). `Session` is an immutable observation. Fields not captured read as `:unloaded`. |
| Rust | [`session.Session`](/en/rs/latest/reference/session-session/) (struct) |
| Go | [`tmux.Session`](/en/go/latest/reference/tmux-session/) (struct) |
| Java | [`io.github.libtmux.Session`](/en/java/latest/reference/io-github-libtmux-session-session/) (class) |
| Kotlin | [`io.github.libtmux.kotlin.Session`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-session/) (class) |
| Scala | [`io.github.libtmux.scaladsl.Session`](/en/scala/latest/reference/io-github-libtmux-scaladsl-session/) (typealias) |
| C# | [`LibTmux.Session`](/en/csharp/latest/reference/libtmux-session/) (class) |
| F# | [`LibTmux.FSharp.Session`](/en/fsharp/latest/reference/libtmux-fsharp-session/) (module). 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) |
| Swift | [`Session`](/en/swift/latest/reference/session/) (struct) |
