# LibTmux.Server.snapshot/2

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Elixir
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib/libtmux/server.ex#L628
- **Page:** https://libtmux.org/en/elixir/pr-173/reference/libtmux-server-snapshot-2/

```
snapshot(server, options \\ [])
@spec snapshot(t(), [LibTmux.Capture.option()]) ::
        {:ok, LibTmux.Snapshot.t()}
        | {:error, LibTmux.Error.t()}
```

Captures a new graph explicitly, with bounded work and read retries.

A live server with zero sessions returns a complete graph with empty
sessions, windows, window links, panes and clients.

See the [worked example](first-task.html).

## Parameters

- `server` (`t()`)
- `options` (`[LibTmux.Capture.option()]`)
  Default: `[]`.

## tmux command

The tmux commands behind `snapshot/2`.

- [`display-message`](/en/tmux/latest/manual/display-message/)
- [`list-clients`](/en/tmux/latest/manual/list-clients/)
- [`list-panes`](/en/tmux/latest/manual/list-panes/) `-a` server scope, [`cmd_list_panes_server`](/en/tmux/latest/reference/c-function-cmd-list-panes-c-cmd_list_panes_server/) (source: `lib/libtmux/capture.ex:177`)
- [`list-sessions`](/en/tmux/latest/manual/list-sessions/)
- [`list-windows`](/en/tmux/latest/manual/list-windows/) `-a` server scope, [`cmd_list_windows_exec`](/en/tmux/latest/reference/c-function-cmd-list-windows-c-cmd_list_windows_exec/) (source: `lib/libtmux/capture.ex:164`)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_display_message_entry`](/en/tmux/latest/reference/c-variable-cmd_display_message_entry/) (attribute)
- [`cmd_display_message_exec`](/en/tmux/latest/reference/c-function-cmd-display-message-c-cmd_display_message_exec/) (function)
- [`cmd_list_clients_entry`](/en/tmux/latest/reference/c-variable-cmd_list_clients_entry/) (attribute)
- [`cmd_list_clients_exec`](/en/tmux/latest/reference/c-function-cmd-list-clients-c-cmd_list_clients_exec/) (function)
- [`cmd_list_panes_entry`](/en/tmux/latest/reference/c-variable-cmd_list_panes_entry/) (attribute)
- [`cmd_list_panes_server`](/en/tmux/latest/reference/c-function-cmd-list-panes-c-cmd_list_panes_server/) (function)
- [`cmd_list_sessions_entry`](/en/tmux/latest/reference/c-variable-cmd_list_sessions_entry/) (attribute)
- [`cmd_list_sessions_exec`](/en/tmux/latest/reference/c-function-cmd-list-sessions-c-cmd_list_sessions_exec/) (function)
- [`cmd_list_windows_entry`](/en/tmux/latest/reference/c-variable-cmd_list_windows_entry/) (attribute)
- [`cmd_list_windows_exec`](/en/tmux/latest/reference/c-function-cmd-list-windows-c-cmd_list_windows_exec/) (function)

## Guides

Pages that discuss `snapshot/2`.

### Concepts

- [Read values, execute explicitly](/en/elixir/pr-173/concepts/mental-model/)
- [Captured tmux state](/en/elixir/pr-173/concepts/observations/)

### Examples

- [Capture a pane and read it](/en/elixir/pr-173/examples/capture-and-read/)

## In other ports

Capture the tmux hierarchy

| Port | API | Differs from Elixir |
| --- | --- | --- |
| Elixir | `LibTmux.Server.snapshot/2`. Captures a new graph explicitly, with bounded work and read retries. | This page |
| Ruby | [`LibTmux::Server#snapshot`](/en/ruby/latest/reference/libtmux-server-snapshot/) (method). Behavior: Snapshot acquisition. | None recorded in the model |
| Lua | [`libtmux.Server:snapshot`](/en/lua/latest/reference/libtmux-server-snapshot/) (method) | None recorded in the model |
| PowerShell | [`LibTmux\Get-TmuxSnapshot`](/en/powershell/latest/reference/libtmux-get-tmuxsnapshot/) (cmdlet). Capture a replacement tmux hierarchy. | free function. Acquires a replacement `LibTmux.Server` to [`-Depth`](/en/powershell/latest/reference/libtmux-get-tmuxsnapshot/#LibTmux%5CGet-TmuxSnapshot.parameter.Depth) (panes by default). Acquisition is not atomic; retained handles do not refresh. |
| Julia | [`LibTmux.snapshot`](/en/julia/latest/reference/libtmux-snapshot-1gv6/) (function) | free function. 2 overloads. Acquires a new `Snapshot` over an observation interval. Topology checks do not make it a transaction; earlier snapshots do not refresh. |
| Erlang | [`tmux_server:snapshot/1`](/en/erlang/latest/reference/tmux_server-snapshot-1/) (function). Capture a complete immutable graph with default capture limits. Performs I/O. See snapshot/2 for bounds, consistency and conflict errors. | free function. Captures a new graph over an observation interval. Retained snapshots never refresh. |
| Common Lisp | [`libtmux:fetch-snapshot`](/en/lisp/latest/reference/libtmux-fetch-snapshot/) (function). Acquire an eager native graph; all later accessors on it are local. TIMEOUT controls one acquisition deadline and OUTPUT-LIMIT caps combined output, including at most two retries after contradictory observations. Synchronous setup and additional cleanup can extend caller wall time. ROW-LIMIT bounds each listing; ENTITY-LIMIT bounds the complete graph; FIELD-LIMIT bounds encoded field bytes. No daemon is started. A live daemon with zero sessions yields empty vectors; connection/listing failures remain errors. Closing CLIENT leaves this snapshot usable. This is an interval observation, not a transactional snapshot. | on client. `fetch-snapshot` acquires a new interval observation. Retained snapshots never refresh in place. |
| TypeScript | [`server.Server.snapshot`](/en/ts/latest/reference/server-server-snapshot/) (method). Acquire an immutable view of the server at this instant. | None recorded in the model |
| Rust | [`server.Server.hierarchy`](/en/rs/latest/reference/server-server-hierarchy/) (method). Fetch the whole hierarchy in three commands. | async. Fetches the whole hierarchy with `list-sessions`, `list-windows -a` and `list-panes -a`, and stitches the rows by winlink. The three listings are separate commands, so the capture is not an atomic transaction. |
| Go | [`tmux.Server.Snapshot`](/en/go/latest/reference/tmux-server-snapshot/) (method). Snapshot materializes sessions, winlinks, panes, and clients. Its sequential commands produce an observationally consistent result, not an atomic transaction. Failures remain errors rather than empty snapshots; cancellation may occur after earlier listings completed. | None recorded in the model |
| Java | [`io.github.libtmux.Server.snapshot`](/en/java/latest/reference/io-github-libtmux-server-server-snapshot/) (method). Captures the whole hierarchy in at most four listings, retrying once if the server is replaced. | None recorded in the model |
| Clojure | [`libtmux.core/snapshot!`](/en/clojure/latest/reference/libtmux-core-snapshot/) (function). Acquires an eager captured graph from an explicit server. | free function. Acquires a captured graph of persistent values. Retained values do not refresh after mutation or close. |
| Kotlin | [`io.github.libtmux.kotlin.Server.snapshot`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-server-snapshot/) (method). Captures the whole hierarchy in at most four listings, retrying once if the server is replaced. | async |
| Scala | [`io.github.libtmux.scaladsl.Server.snapshot`](/en/scala/latest/reference/io-github-libtmux-scaladsl-server-snapshot/) (method). Captures the whole hierarchy in at most four listings, retrying once if the server is replaced. | None recorded in the model |
| C# | [`LibTmux.Server.CaptureSnapshotAsync`](/en/csharp/latest/reference/libtmux-server-capturesnapshotasync/) (method). Reads the server and answers a handle carrying what it found. | None recorded in the model |
| F# | [`LibTmux.FSharp.Server.capture`](/en/fsharp/latest/reference/libtmux-fsharp-server-capture/) (function). Returns a new server handle captured to the requested depth. | free function. Acquires a replacement shared .NET `LibTmux.Server` to the requested depth. Acquisition is not atomic; retained handles do not refresh. |
| Swift | [`Server.snapshot()`](/en/swift/latest/reference/server-snapshot()/) (method). Reads every object from one daemon incarnation. | async |
| OCaml | [`Libtmux_unix.Client.capture`](/en/ocaml/latest/reference/libtmux_unix-client-capture/) (function). Acquire a complete graph over a recorded interval, with a fixed number of listing commands. Races fail validation. Access to returned values performs no I/O, including after closing the client. | free function. Acquires a complete immutable graph over an interval. Earlier observations remain readable without refreshing. |
| Perl | [`LibTmux::Server::snapshot`](/en/perl/latest/reference/libtmux-server-snapshot/) (method). snapshot(). | Strict acquisition observes an interval, not an atomic transaction; retained handles do not refresh. |
| Raku | [`LibTmux::Server.snapshot`](/en/raku/latest/reference/libtmux-server-snapshot/) (method). Acquire a captured graph explicitly. Existing snapshots remain unchanged. | Explicit I/O captures an observation interval. Existing views and relationships remain local. |

No Python equivalent. no equivalent on `Server`

No Haskell equivalent. No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.

No C++ equivalent. no equivalent on `Server`: `sessions`, `windows`, `panes` and `clients` each take a snapshot of one listing, and `Snapshot::take` needs the internal `detail::Backend`, so no public call reads the whole hierarchy at once
