# tmux client library for OCaml

Source: https://libtmux.org/en/ocaml/latest/core/

> tmux client library for OCaml. Control tmux, connect to and create servers, navigate sessions, windows, and panes, send keys, watch for changes via control mode, capture pane contents

Use the native OCaml library to capture sessions, shared windows and panes.
Process observations with [`Iarray`](<https://ocaml.org/manual/5.5/api/Iarray.html>), [`Seq`](<https://ocaml.org/manual/5.5/api/Seq.html>) and ordinary predicates. Typed
expressions add inspection and JSON interchange; client calls perform I/O.

The core and workspace library depend on the standard library. Blocking Linux,
Eio, JSON and the workspace CLI are separate packages. This port excludes MCP.

[Installation and first use](https://libtmux.org/en/ocaml/latest/guides/getting-started/) ·
[Captured graph](https://libtmux.org/en/ocaml/latest/guides/graph/) · [API reference](https://libtmux.org/en/ocaml/latest/reference/)Control tmux, connect to and create servers, navigate sessions, windows, and panes, send keys, watch for changes via control mode, capture pane contents.

## At a glance

| Type | Wraps |
| ---- | ----- |
| [`Libtmux_unix.Client.t`](https://libtmux.org/en/ocaml/latest/reference/libtmux_unix-client-t/) | A connection to one tmux server |
| [`Libtmux.Session.t`](https://libtmux.org/en/ocaml/latest/reference/libtmux-session-t/) | A session, ID `$n` |
| [`Libtmux.Window.t`](https://libtmux.org/en/ocaml/latest/reference/libtmux-window-t/) | A shared tmux window, ID `@n` |
| [`Libtmux.Pane.t`](https://libtmux.org/en/ocaml/latest/reference/libtmux-pane-t/) | A pane in a window, ID `%n` |

## Typed API

- Typed objects instead of parsed format strings: [`Libtmux.Pane`](https://libtmux.org/en/ocaml/latest/reference/libtmux-pane/)
- Addressing by tmux ID: [`Libtmux.Pane.Id`](https://libtmux.org/en/ocaml/latest/reference/libtmux-pane-id-16to/)
- Filtering and queries over tmux objects: [`Libtmux.Expr`](https://libtmux.org/en/ocaml/latest/reference/libtmux-expr/)
- Typed errors instead of exit codes and stderr: [`Libtmux.Error`](https://libtmux.org/en/ocaml/latest/reference/libtmux-error/)

## What you get over the tmux CLI

- Connect to or start a tmux server: [`Libtmux_unix.Client.connect`](https://libtmux.org/en/ocaml/latest/reference/libtmux_unix-client-connect/)
- Traversal from a server down to its panes: [`Libtmux.Snapshot.panes`](https://libtmux.org/en/ocaml/latest/reference/libtmux-snapshot-panes/)
- Send keys to a pane: [`Libtmux_unix.Client.send_keys`](https://libtmux.org/en/ocaml/latest/reference/libtmux_unix-client-send_keys/)
- Watch for changes through tmux control mode: [`Libtmux_eio.Client.subscribe`](https://libtmux.org/en/ocaml/latest/reference/libtmux_eio-client-subscribe/)
- Capture pane contents: [`Libtmux_unix.Client.capture_text`](https://libtmux.org/en/ocaml/latest/reference/libtmux_unix-client-capture_text/)
- Arguments passed as a list, with no shell quoting: [`Libtmux.Command`](https://libtmux.org/en/ocaml/latest/reference/libtmux-command/)
- A typed error when the running tmux lacks a feature: [`Libtmux.Error.Unsupported_version`](https://libtmux.org/en/ocaml/latest/reference/libtmux-error-t-unsupported_version/)
- Async operations: [`Libtmux_eio.Client.capture`](https://libtmux.org/en/ocaml/latest/reference/libtmux_eio-client-capture/)

- [Guides](https://libtmux.org/en/ocaml/latest/guides/): Capture, query, streaming and workspace guides.
- [API reference](https://libtmux.org/en/ocaml/latest/reference/): Public modules, types and values.
