# Libtmux

- **Package:** libtmux
- **Language:** OCaml
- **Kind:** module
- **Source:** https://github.com/libtmux/libtmux-ocaml/blob/205dfda49742592b479247049d186956e4a4cfe9/lib/libtmux.mli#L1
- **Page:** https://libtmux.org/en/ocaml/latest/reference/libtmux/

```ocaml
module Libtmux
```

Native captured values, typed queries and explicit command descriptions.

A [`Snapshot.t`](/en/ocaml/latest/reference/libtmux-snapshot-t/) owns immutable observations. Entity accessors and query evaluation perform no I/O, preserve captured order and remain usable after client closure. Use `Libtmux_unix.Client` or `Libtmux_eio.Client` to acquire or mutate state.

Retaining any entity retains its complete snapshot graph. Copy scalar summaries when captured relationships are no longer needed. Targets omit the graph but remain restricted to their original [`Source.t`](/en/ocaml/latest/reference/libtmux-source-t/).

## Typical flow

Capture explicitly, traverse [`Session.window_links`](/en/ocaml/latest/reference/libtmux-session-window_links/) and [`Window.panes`](/en/ocaml/latest/reference/libtmux-window-panes/), filter with `Seq.filter` or [`Query.matching`](/en/ocaml/latest/reference/libtmux-query-matching/), establish cardinality with [`Query.exactly_one`](/en/ocaml/latest/reference/libtmux-query-exactly_one/), then submit a command with a bound target.

The core depends only on the standard library. Its abstract observations are safe to share; live clients and subscriptions belong to their backend.

See the [graph guide](https://github.com/libtmux/libtmux-ocaml/blob/master/docs/graph.md) for window links and the [query guide](https://github.com/libtmux/libtmux-ocaml/blob/master/docs/queries.md) for native predicates and typed expressions.

## Members

### Other members

- [`Captured_text`](/en/ocaml/latest/reference/libtmux-captured_text/) (module)
- [`Cardinality`](/en/ocaml/latest/reference/libtmux-cardinality/) (module)
- [`Client_name`](/en/ocaml/latest/reference/libtmux-client_name/) (module)
- [`Client_observation`](/en/ocaml/latest/reference/libtmux-client_observation/) (module)
- [`Command`](/en/ocaml/latest/reference/libtmux-command/) (module): Typed descriptions of explicit acquisition and mutation operations. Construction performs no I/O; a backend validates and admits the command.
- [`Created`](/en/ocaml/latest/reference/libtmux-created/) (module): IDs reported by a successful creation reply. Only the requested kind is newly created; the other fields can describe existing containers.
- [`Endpoint`](/en/ocaml/latest/reference/libtmux-endpoint/) (module): An explicit socket description. Constructing an endpoint neither reads the environment nor starts a daemon. {!Source.t} adds the observed daemon and connection generation.
- [`Environment`](/en/ocaml/latest/reference/libtmux-environment/) (module)
- [`Error`](/en/ocaml/latest/reference/libtmux-error/) (module): Expected input, capture, capability and transport failures. Cancellation belongs to the chosen backend and is not converted into an ordinary error.
- [`Expr`](/en/ocaml/latest/reference/libtmux-expr/) (module): Inspectable predicates whose entity and operand types are checked by the compiler. Combine native closures separately with `Seq.filter`. Evaluation follows captured relationships without acquisition or hidden caches.
- [`Field`](/en/ocaml/latest/reference/libtmux-field/) (module): Sealed scalar descriptors carrying entity and value types. Descriptors read captured data and provide trusted identities for {!Expr} values. Use {!Relation} for graph edges.
- [`Formats`](/en/ocaml/latest/reference/libtmux-formats/) (module)
- [`Generation`](/en/ocaml/latest/reference/libtmux-generation/) (module): A random connection-generation identifier. Reconnecting creates a new generation even when the socket and server PID are unchanged.
- [`Geometry`](/en/ocaml/latest/reference/libtmux-geometry/) (module)
- [`Hook`](/en/ocaml/latest/reference/libtmux-hook/) (module)
- [`ID`](/en/ocaml/latest/reference/libtmux-id/) (interface)
- [`Key`](/en/ocaml/latest/reference/libtmux-key/) (module)
- [`Layout`](/en/ocaml/latest/reference/libtmux-layout/) (module)
- [`Model`](/en/ocaml/latest/reference/libtmux-model/) (module): Built-in model witnesses and canonical field lookup for typed codecs. Untrusted field names must resolve against the selected model.
- [`Operations`](/en/ocaml/latest/reference/libtmux-operations/) (module): Construct typed tmux operations for a backend client. Observations are immutable, mutations use explicit targets, and no command retries a mutation against another connection generation. Construction performs no I/O; the descriptions below state what execution does.
- [`Options`](/en/ocaml/latest/reference/libtmux-options/) (module): Version-aware option descriptors and captured scoped values. Sparse array indexes and inherited entries retain their tmux meaning.
- [`Output`](/en/ocaml/latest/reference/libtmux-output/) (module): Future observed pane bytes, local cursors and explicit continuity loss. Output cursors are unrelated to snapshot times or server-side history.
- [`Pane`](/en/ocaml/latest/reference/libtmux-pane/) (module): A captured pane with local geometry, process metadata and a window relationship. Use {!Pane.val-target} for explicit actions; reading the observation never refreshes it.
- [`Plan`](/en/ocaml/latest/reference/libtmux-plan/) (module): Explicit source-filter planning for a new acquisition. A plan separates supported tmux predicates from residual local evaluation; it never changes the I/O-free contract of {!Query.matching}. Backend capture operations acquire a complete graph and do not consume these plans.
- [`Query`](/en/ocaml/latest/reference/libtmux-query/) (module): Sequence adapters and bounded cardinality checks over captured values. Matching preserves order and duplicates. Expected absence and ambiguity remain ordinary result values.
- [`Relation`](/en/ocaml/latest/reference/libtmux-relation/) (module): Typed edges in a captured graph. Many, one and optional relations are distinct; an unacquired relationship is never represented as an empty one.
- [`Session`](/en/ocaml/latest/reference/libtmux-session/) (module): A captured session and its ordered window-link contexts. A session can contain repeated links to the same global window.
- [`Snapshot`](/en/ocaml/latest/reference/libtmux-snapshot/) (module): A complete immutable graph captured over an acquisition interval. Collections are replayable immutable arrays. Capturing several tmux commands does not establish an atomic transaction.
- [`Source`](/en/ocaml/latest/reference/libtmux-source/) (module): Endpoint and observed daemon identity for one connection generation. Constructing metadata alone does not establish a live binding.
- [`Spawn`](/en/ocaml/latest/reference/libtmux-spawn/) (module): A process description with explicit argv or shell semantics, working directory and environment. Describing a process performs no I/O.
- [`Window`](/en/ocaml/latest/reference/libtmux-window/) (module): A global window shared by its session links. Window index and current state belong to a link, while panes and geometry belong to the window.
- [`Window_link`](/en/ocaml/latest/reference/libtmux-window_link/) (module): One captured session/index/window context. It is not a stable link incarnation across unlinking, movement or reindexing.
