# libtmux for Elixir
> The Elixir library (libtmux). These pages include its guides, tested examples and API documentation.
- [Elixir API reference](https://libtmux.org/en/elixir/pr-173/reference/): every public symbol, generated from the source. Hosted on libtmux.org.
---
# Concepts
Source: https://libtmux.org/en/elixir/pr-173/concepts/
> Understand captured queries, object identities, and operations.
Understand captured queries, object identities, and operations.
- [Read values, execute explicitly](https://libtmux.org/en/elixir/pr-173/concepts/mental-model/): Hold one captured graph for several decisions and run a command when you need another.
- [Captured tmux state](https://libtmux.org/en/elixir/pr-173/concepts/observations/): Capture an immutable snapshot of an existing server and read it without further commands.
---
# Read values, execute explicitly
Source: https://libtmux.org/en/elixir/pr-173/concepts/mental-model/
> Hold one captured graph for several decisions and run a command when you need another.
- Capture once when several decisions need the same graph, and keep that
snapshot while you select and filter.
- Run a new command explicitly for another observation or an effect.
- Capture covers an interval, so fields can change during it. The value you
get stays fixed while tmux keeps changing.
## The values you hold
| Value | What it represents | I/O boundary |
| --- | --- | --- |
| [`LibTmux.Server`]() | Executable, socket choice and environment for an existing server | Pure descriptor construction |
| [`LibTmux.Snapshot`]() | An indexed graph captured over one interval | [`LibTmux.Server.snapshot/2`]() captures a new value |
| [`LibTmux.Selection`]() | Ordered items and their originating snapshot | Filtering and enumeration use captured values |
| [`LibTmux.Ref`]() | An observed exact ID and server instance | Pure identity data; it reserves nothing |
| [`LibTmux.Control`]() | A handle pinned to one connection epoch | Status reads are local; startup explicitly attaches a client |
| [`LibTmux.Operation`]() | Access to one retained operation record | Result/status reads are local; awaiting registers a separate waiter |
- Windows are physical objects. [`LibTmux.WindowLink`]() gives a window's session
membership, index and active state.
- A linked window can appear more than once, while its panes stay the same
physical panes.
- Choose window links when membership matters. Choose panes when an action
should address each physical pane once.
See [captured state](https://libtmux.org/en/elixir/pr-173/concepts/observations/).
## Coverage tells you which questions the graph can answer
- A loaded field holds a value, an empty string or a documented [`nil`]().
- `:unloaded` means this snapshot lacks the observation. `:unavailable` means
the capability is absent. Neither means known absence.
- Relationship predicates need complete captured join domains. A missing pane
relation cannot satisfy "no pane matches."
- Validation raises a structured coverage error before filtering, even for an
empty selection.
- Capture again explicitly for more coverage. Existing selections keep their
graph.
See [filtering](https://libtmux.org/en/elixir/pr-173/guides/filtering/).
## Server identity and connection epochs have different lifetimes
- A server instance identifies one tmux process incarnation. Native object
IDs can be reused after that process exits.
- References keep the observed instance, so qualified control requests can
reject known stale targets. One-shot commands keep a check/use race; an
observed ID reserves nothing.
- An epoch identifies one control connection and its owned transport actors.
The server instance can stay the same while the epoch changes.
- [`LibTmux.Control.reconnect/2`]() returns the ready epoch, unchanged if it is
already ready. Close first to require a replacement.
- A replacement waits for retirement and returns a new pinned handle. Old
handles cannot submit into it, and reconnect never replays work.
## Waiting, command outcomes and retirement are separate
| Result | What the caller can conclude |
| --- | --- |
| [`LibTmux.Control.submit/3`]() returns `{:ok, operation}` | Admission succeeded; inspect or await the retained operation |
| [`LibTmux.Operation.await/2`]() returns an API timeout | This waiter ended; the operation may still advance |
| A canonical outcome is `:completed` or `:failed` with `:acknowledged` certainty | tmux supplied a command reply; arbitrary programs started by that command have their own lifetimes |
| A canonical outcome is `:skipped` with `:no_write` certainty | The operation was classified before dispatch |
| A canonical outcome is `:unknown` | Available evidence cannot determine its effects |
| Operation status reports `wire: :retired` | Reply attribution has retired; the retained record may still occupy capacity |
| [`LibTmux.Control.close/2`]() returns `:ok` | The pinned connection epoch retired; its enclosing supervisor remains running |
- Each await call has its own budget. A timeout or the caller's death ends
that waiter without cancelling the operation.
- For wire-active work, [`LibTmux.Operation.stop/1`]() asks to close the whole
pinned epoch and can affect siblings. An already retired operation returns
`:ok` without closing its connection.
- [`LibTmux.Control.close/2`]() waits for connection retirement.
- Inspect retained results instead of replaying an uncertain mutation.
- A canonical outcome never changes once it exists. Bang operation APIs raise
API and context errors, and still return failed, skipped and unknown
outcomes as values.
- Wire retirement, record expiry and native process cleanup each have their
own evidence. [Ownership](https://libtmux.org/en/elixir/pr-173/topics/ownership/) covers deadlines, bounds and
remaining limits.
## Return conventions
These APIs answer different questions. Command completion does not mean that
a program started by tmux has finished.
| API | Normal return | Failure handling |
| --- | --- | --- |
| Domain actions such as [`LibTmux.Window.rename/4`]() | `{:ok, result}` only for completion, retaining value and evidence | Unsuccessful outcomes use [`LibTmux.Action.CompletionError`](); API and admitted execution errors retain their own types |
| Domain bangs such as [`LibTmux.Window.rename!/4`]() | Completed value | Raise the same errors with their evidence |
| [`LibTmux.Control.execute/3`]() and [`LibTmux.Operation.await/2`]() | `{:ok, canonical_result}`, including failed, skipped and unknown outcomes | Outer errors describe execution context or waiting; their bangs raise those errors and return canonical outcomes unchanged |
| [`LibTmux.Selection.one/2`]() and [`LibTmux.Selection.one_or_nil/2`]() | `{:ok, item}`, or allowed `{:ok, nil}` | Cardinality errors are tuples; bangs raise them. Predicate and coverage validation can raise in either form |
| Relationship helpers such as [`LibTmux.Session.panes/2`]() | Ordered selection, or observation/nil for to-one relationships; no I/O | Identity, coverage and ambiguity errors raise |
| [`LibTmux.Control.with_connection/2`]() | `{:ok, callback_value}` after cleanup, even when that value is `{:error, reason}` | Startup errors return errors; callback raise/throw/exit propagates after cleanup. Unproved cleanup returns [`LibTmux.Control.ScopeFailure`]() preserving the primary outcome |
- The [recovery example](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/recovery.md) handles lower-level execution and
cleanup separately.
- Option validation may raise. A name without a bang does not promise that
every malformed call returns an error tuple.
---
# Captured tmux state
Source: https://libtmux.org/en/elixir/pr-173/concepts/observations/
> Capture an immutable snapshot of an existing server and read it without further commands.
- [`LibTmux.Server.new/1`]() builds a descriptor with an explicit executable and a
socket choice. The choice is a path, a name, one of `LIBTMUX_SOCKET_PATH` and
`LIBTMUX_SOCKET`, or none, which leaves it to tmux. It does no I/O.
- [`LibTmux.Server.snapshot/2`]() observes that existing server and returns an
immutable [`LibTmux.Snapshot`]().
- Neither call attaches a control client or starts a missing server.
- Configured tmux hooks remain environmental effects of commands, including
list commands.
## Read one captured graph
- [`Snapshot.items/2`]() returns a plain list for an entity atom or module.
- [`Snapshot.fetch/3`]() looks up an exact ID.
- [`Snapshot.related/4`]() follows captured indexes, and raises a structured
coverage error when a relation is incomplete.
- [`Snapshot.sessions/1`](), `windows/1`, `panes/1`, `window_links/1` and
`clients/1` return materialized selections.
- None of these does I/O. See [filtering](https://libtmux.org/en/elixir/pr-173/guides/filtering/) for local predicates
and portable criteria.
For common relationships, pass the snapshot and a session or window
observation to [`Session.windows/2`](), [`Session.panes/2`](), [`Session.active_window/2`]()
or [`Window.panes/2`]():
- The plural helpers return selections for filtering and checked cardinality
with [`LibTmux.Selection`](). `active_window/2` returns a window or [`nil`]().
- They validate the observation's kind, ID and server incarnation, then use
the supplied graph's fields and coverage. An older observation from the same
incarnation is valid, and its other fields are ignored.
- Each selection keeps the supplied graph. `Enum.to_list/1` gives a plain list
without it.
- Direct traversal validates only the requested source. One session's active
window does not fail because another session has ambiguous active links.
- Relationship filters validate their whole captured source domain before
iteration, even when the selection is empty.
Sessions, physical windows, panes and clients have separate maps:
- A pane belongs to one physical window.
- [`WindowLink`]() records session membership, window index and active state. Its
key is session ID, index and window ID, which does not prove a unique
lifetime after unlink and relink.
- A window can appear at several indexes in one session, and in other
sessions. Server-wide physical maps deduplicate identical rows and reject
conflicting rows.
- Session pane traversal returns each physical pane once. Window-link
traversal keeps memberships.
- Sessions, windows and panes sort by numeric native ID. A session's windows
follow their first link's index; its panes sort by numeric pane ID. Links
sort by numeric session ID and index. Clients sort bytewise by observed
name.
Field notes:
- [`Session.attached_count`]() keeps tmux's raw client count, and [`attached`]() is
derived from it. Control clients stay counted even with `no-output` and
`ignore-size`.
- A control client's height is known [`nil`]() when tmux reports no started tty.
It is not an unavailable field.
- [`Pane.pid`]() is known [`nil`]() when tmux reports no PID, including empty and
retained dead panes on tmux 3.8. Other values stay as reported: older tmux
can report zero for an empty pane, or a historical PID for a dead one.
Neither a PID nor its absence proves a process is alive or cleaned up.
## Compare two snapshots
This example links one physical window into a second session at indexes 7
and 8. It captures the graph, unlinks index 7, then captures again.
Compare [`WindowLink.id`]() values to find added and removed memberships. Each key
contains the session ID, index and physical window ID, so replacing the
window at an index gives a removal and an addition. Require complete window
link coverage in both captures and check that they came from the same
server incarnation before comparing their IDs.
```elixir
unless before.server_instance == later.server_instance do
raise "the captures describe different tmux servers"
end
link_ids = fn snapshot ->
:ok = Snapshot.require_complete!(snapshot, :window_link)
Enum.map(Snapshot.window_links(snapshot), & &1.id)
end
before_ids = link_ids.(before)
later_ids = link_ids.(later)
removed = before_ids -- later_ids
added = later_ids -- before_ids
```
From this checkout, with tmux on `PATH`:
```console
$ mix run examples/snapshot_changes.exs
```
It prints:
```text
{"removed":[["$1",7,"@0"]],"added":[],"window":"@0","panes":["%0","%2"],"destination_indexes":[8],"held_destination_indexes":[7,8],"same_panes":true}
```
Only the membership at index 7 disappeared. Index 8 still points to the
same window with both original panes. The held snapshot still has both
memberships. The comparison reports differences between captured keys.
Changes to fields such as the active flag, and an unlink and relink of the
same key between captures, are outside that comparison.
## Coverage and construction
- [`Snapshot.new/2`]() validates fixture or adapter observations without I/O.
- [`fields`]() declares loaded fields over the supplied entity IDs. `complete`
declares complete server entity sets; omissions stay partial. `unavailable`
declares absent capabilities separately.
- Declared names and values validate before indexes or relations become
observable.
- Known empty strings, known nullable values, `:unloaded` and `:unavailable`
stay distinct. Required coverage checks run even for empty entity sets.
- Derived attachment coverage follows its source count.
- A relation to many objects needs a complete join domain, so missing
children never become an empty relation. Complete target sets reject
dangling references. A partial target set can keep unresolved foreign IDs,
but traversal fails explicitly.
The [generated schema](https://libtmux.org/en/elixir/pr-173/topics/schema/) owns field types, wire names, tmux variables
and relation cardinalities. Physical windows carry no single session, session
index or active membership flag.
## Capture consistency and bounds
- Capture reads topology, then named fields, then topology again. It checks
the tmux PID against Linux boot identity and process start ticks before and
after those reads.
- Two empty session listings from the same server incarnation yield a complete
graph with all entity sets empty. These reads use the same capture budgets.
- A replaced server or changing references trigger finite read retries, as
does a disappearing read target. Invalid encoding and other decoding errors
stay visible.
- Two attempts are the default; request one to three. All attempts share one
deadline and the original budgets.
- Defaults: 1024 contextual topology rows, 512 commands, 8 MiB total response
bytes, 64 KiB per response and 5000 ms.
- Stdout and stderr both consume the byte budget, including failed-command
output. Overload returns an error, not a truncated success.
- Topology checks and retries also consume work. An overflowing pane listing
can fall back to smaller listings or individual reads. That work stays
charged to the original budgets. See [capture rows](https://libtmux.org/en/elixir/pr-173/topics/encoding/#capture-rows).
- One-shot retirement has a separate allowance; see [ownership](https://libtmux.org/en/elixir/pr-173/topics/ownership/).
Encoding:
- Free-form fields use the qualified versioned encoder. Numeric and ID
topology columns validate their whole representation.
- Client rows combine one encoded identity with restricted scalar columns, so
tabs and newlines cannot escape the identity.
- This is a fixed capture schema, not a general raw-format row parser.
A capture records an observation, not a transaction:
- Attributes can change within the interval. Matching topology before and
after does not prove nothing changed in between.
- Holding a snapshot reserves no objects.
- Its server instance differs from a future connection epoch, and one-shot
checks keep a check/use race.
- Sending a snapshot between BEAM processes can copy terms, and keeping one
keeps its graph.
## Diagnose capture work
[`LibTmux.Server.snapshot_with_diagnostics/2`]() puts a work report in the third
tuple element on success or error. Compare two response ceilings against the
same graph:
```elixir
{:ok, narrow, narrow_report} =
Server.snapshot_with_diagnostics(server, max_response_bytes: 2500)
{:ok, wide, wide_report} =
Server.snapshot_with_diagnostics(server, max_response_bytes: 8192)
```
The runnable example creates a private server with four panes and checks
that both captures return the same long titles.
```console
$ mix run examples/capture_diagnostics.exs
```
| Capture | Commands | Pane batch reads | Individual reads |
| --- | ---: | ---: | ---: |
| 2500 bytes per response | 15 | 2 | 0 |
| 8192 bytes per response | 13 | 0 | 0 |
At 2500 bytes the full pane listing overflows. The fallback record names
`:pane` and counts two batch reads, one per ID range. The byte count
includes the retained prefix of the overflowing response. The last call
sets a command limit to stop before either batch and returns a capture
error with the report.
Use `max_response_bytes` to fit a known large row or listing. `max_bytes`
and [`timeout`]() still bound the entire capture, including every fallback. Log
the report alone to leave out captured output that may be present in the error.
---
# tmux client library for Elixir
Source: https://libtmux.org/en/elixir/pr-173/core/
> tmux client library for Elixir. Control tmux, navigate sessions, windows, and panes, watch for changes via control mode
Control tmux, navigate sessions, windows, and panes, watch for changes via control mode.
## At a glance
| Type | Wraps |
| ---- | ----- |
| [`LibTmux.Server`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-server/) | A tmux server |
| [`LibTmux.Session`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-session/) | A session, ID `$n` |
| [`LibTmux.Window`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-window/) | A window in a session, ID `@n` |
| [`LibTmux.Pane`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-pane/) | A pane in a window, ID `%n` |
## Typed API
- Typed objects instead of parsed format strings: [`LibTmux.Pane`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-pane/)
- Filtering and queries over tmux objects: [`LibTmux.Filter`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-filter/)
- Typed errors instead of exit codes and stderr: [`LibTmux.Error`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-error/)
## What you get over the tmux CLI
- Traversal from a server down to its panes: [`LibTmux.Snapshot.panes/1`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-snapshot-panes-1/)
- Watch for changes through tmux control mode: [`LibTmux.Control`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-control/)
- Arguments passed as a list, with no shell quoting: [`LibTmux.Command`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-command/)
- [Guides](https://libtmux.org/en/elixir/pr-173/guides/): Task guides for Elixir.
- [Topics](https://libtmux.org/en/elixir/pr-173/topics/): Subject-by-subject, with Elixir in every code block.
- [Examples](https://libtmux.org/en/elixir/pr-173/examples/): Complete programs, sourced from the code each port tests.
- [API reference](https://libtmux.org/en/elixir/pr-173/reference/): Types and functions of the Elixir API.
---
# API glossary
Source: https://libtmux.org/en/elixir/pr-173/reference/glossary/
> Kinds, modifiers and package labels in the Elixir API reference.
## Symbol kinds
Kinds identify declarations in the Elixir API reference.
### module
An Elixir module, a named collection of functions, macros and types defined with defmodule.
Module names are atoms, and a nested name such as LibTmux.Control.Request is one flat module rather than a child of LibTmux.Control.
References: [Elixir modules and functions](https://elixir.hexdocs.pm/modules-and-functions.html).
### interface
An Elixir behaviour, a module that declares callbacks other modules implement.
A module implements a behaviour with the @behaviour attribute and defines each required callback.
References: [Elixir behaviours](https://elixir.hexdocs.pm/typespecs.html#behaviours).
### struct
An Elixir module that defines a struct: a map with a fixed set of keys and optional defaults.
Fields hold values and are never reassigned. Functions on the module return a new struct rather than changing one.
References: [Elixir structs](https://elixir.hexdocs.pm/structs.html).
### function
An Elixir function identified by its module, name and arity.
Functions of one name and different arities are different functions. A name ending in ! raises on failure, and a name ending in ? returns a boolean.
References: [Elixir functions](https://elixir.hexdocs.pm/modules-and-functions.html).
### method
A callback that a behaviour declares and an implementing module defines.
A callback is called through the implementing module, not through the behaviour that declares it.
References: [Elixir behaviour callbacks](https://elixir.hexdocs.pm/typespecs.html#behaviours).
### property
A field of an Elixir struct, read with dot access or pattern matching.
A field has no accessor function; structs are plain maps, so the value is stored as the field holds it.
References: [Elixir structs](https://elixir.hexdocs.pm/structs.html).
### typealias
An Elixir type declared with @type or @opaque, named and given an arity.
Types document values for readers and tools. They are not checked when a function runs.
References: [Elixir user-defined types](https://elixir.hexdocs.pm/typespecs.html#user-defined-types).
### exception
An Elixir struct declared with defexception, which can be raised and rescued.
The struct also carries the fields of the error. A bang function raises it; the plain function returns it in an error tuple.
References: [Elixir exceptions](https://elixir.hexdocs.pm/Kernel.html#defexception/1).
## Modifiers
Modifiers add information about calling, implementing, or accessing a declaration. Their precise effect follows the language and the signature.
### opaque
An Elixir type declared with @opaque, whose structure callers must not depend on.
Other modules should build and inspect the value only through the declaring module’s functions.
References: [Elixir user-defined types](https://elixir.hexdocs.pm/typespecs.html#user-defined-types).
### macro
An Elixir macro, defined with defmacro and expanded at compile time.
A caller must require or import the defining module before using the macro.
References: [Elixir macros](https://elixir.hexdocs.pm/Kernel.html#defmacro/2).
### abstract
A callback of a behaviour, declared without a body.
References: [Elixir behaviour callbacks](https://elixir.hexdocs.pm/typespecs.html#behaviours).
### deprecated
A declaration marked with the @deprecated attribute.
The compiler warns at call sites of a deprecated function. The message names the replacement when the author gave one.
References: [Elixir @deprecated attribute](https://elixir.hexdocs.pm/Module.html#module-deprecated-since-v1-6-0).
### overload
A function with several @spec clauses, each describing one accepted combination of argument types.
The clauses describe one function. Which clause applies depends on the arguments, not on a separate definition.
References: [Elixir function specifications](https://elixir.hexdocs.pm/typespecs.html#defining-a-specification).
## Package context
Package labels identify where an API is supplied.
### package
The Hex package supplying this API.
A package name and its application name are the same in a Mix dependency, and the module names it defines are independent of both.
References: [Hex packages](https://hex.pm/docs/usage).
---
# Examples
Source: https://libtmux.org/en/elixir/pr-173/examples/
> Run complete programs with their documented setup and cleanup.
Run complete programs with their documented setup and cleanup.
- [Capture a pane and read it](https://libtmux.org/en/elixir/pr-173/examples/capture-and-read/): Capture a graph, select a pane and read it through one-shot and control commands.
---
# Capture a pane and read it
Source: https://libtmux.org/en/elixir/pr-173/examples/capture-and-read/
> Capture a graph, select a pane and read it through one-shot and control commands.
Capture once, then query the immutable result with no more tmux commands.
Install the published package as shown in the
[README](https://libtmux.org/en/elixir/pr-173/guides/overview/#installation), then save this program as
`capture_and_filter.exs`. It starts a private server with
[`Server.with_owned/2`](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/owned-server.md), so it runs as it is:
```elixir
alias LibTmux.{Selection, Server, Snapshot}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
Server.with_owned([executable: tmux], fn server ->
{:ok, _} = Server.new_session(server, "demo", command: {:argv, ["/bin/cat"]})
{:ok, snapshot} = Server.snapshot(server)
active_ids =
snapshot
|> Snapshot.panes()
|> Selection.where(active: true)
|> Enum.map(& &1.id)
IO.puts(JSON.encode!(%{active_panes: active_ids}))
end)
```
Run it with tmux 3.3 or newer on `PATH`:
```console
$ mix run capture_and_filter.exs
```
It prints the IDs of the active panes, in numeric order, as JSON.
- To capture a server that already runs, build the descriptor with
[`Server.new/1`]() in place of [`Server.with_owned/2`](), passing `socket:` or
`socket_name:`.
- With neither, [`Server.new/1`]() reads `LIBTMUX_SOCKET_PATH`, then
`LIBTMUX_SOCKET` (a socket name). With neither set, it passes tmux no socket,
and tmux uses its default socket.
- A pane is active within its physical window. This does not choose one
session's active window. Linked windows do not duplicate their panes.
- [`Server.new/1`]() builds a descriptor with no I/O. [`Server.snapshot/2`]() runs
bounded one-shot reads, without attaching a control client or creating a
missing server.
- [`Selection.where/2`]() and `Enum.map/2` use the captured graph.
- Capture covers an interval, not an atomic tmux transaction. Capture again
for fresh state.
- The `{:ok, snapshot}` match makes a capture error visible. Production code
can handle `{:error, %LibTmux.Error{}}`.
- Default capture budgets: 5000ms, 512 commands, 1024 contextual topology
rows, 64 KiB per response and 8 MiB in total. A limit failure returns an
error, not a partial graph.
Next: [filter and select](https://libtmux.org/en/elixir/pr-173/guides/filtering/), [one-shot actions](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/one-shot-actions.md)
or [managed control](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/managed-control.md).
## Choose a socket
Build a server descriptor from a socket path, a socket name or an environment
map. Constructing the descriptor performs no I/O.
```elixir
alias LibTmux.Server
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
by_path = Server.new(executable: tmux, socket: "/run/user/1000/work.sock")
by_name = Server.new(executable: tmux, socket_name: "work")
from_variable = Server.new(executable: tmux, env: %{"LIBTMUX_SOCKET" => "work"})
path_env = %{"LIBTMUX_SOCKET_PATH" => "/tmp/w.sock"}
from_path_variable = Server.new(executable: tmux, env: path_env)
default = Server.new(executable: tmux, env: %{})
%Server{socket: "/run/user/1000/work.sock", socket_name: nil} = by_path
%Server{socket: nil, socket_name: "work"} = by_name
%Server{socket: nil, socket_name: "work"} = from_variable
%Server{socket: "/tmp/w.sock", socket_name: nil} = from_path_variable
%Server{socket: nil, socket_name: nil} = default
IO.puts(
JSON.encode!(%{
by_path: by_path.socket,
by_name: by_name.socket_name,
from_variable: from_variable.socket_name,
from_path_variable: from_path_variable.socket,
default: "tmux chooses"
})
)
```
---
# Guides
Source: https://libtmux.org/en/elixir/pr-173/guides/
> Connect to tmux and work with its sessions, windows, and panes.
Connect to tmux and work with its sessions, windows, and panes.
- [Getting started](https://libtmux.org/en/elixir/pr-173/guides/overview/): Add the Hex package, check the Elixir, OTP and tmux requirements, and run an example.
- [Attaching to tmux](https://libtmux.org/en/elixir/pr-173/guides/attaching-to-tmux/): Connect to an existing socket and leave its server running.
- [Filter captured values](https://libtmux.org/en/elixir/pr-173/guides/filtering/): Select observed values with portable keyword and operator filters.
---
# Getting started
Source: https://libtmux.org/en/elixir/pr-173/guides/overview/
> Add the Hex package, check the Elixir, OTP and tmux requirements, and run an example.
Drive tmux from Elixir: [capture][snapshot] sessions, windows and panes as an
immutable snapshot, [filter][where] it with plain data, then rename, split and
type through domain actions.
## Packages
### [libtmux](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib)
Capture, filter and act on tmux sessions, windows and panes.
[API reference](https://libtmux.org/en/elixir/latest/reference/) · [Hex package](https://hex.pm/packages/libtmux) · [Changelog](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/CHANGELOG.md)
### [libtmux_workspace](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/packages/workspace)
Plan and apply session and window descriptions against a running tmux server. The [package guide](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/packages/workspace/README.md) is available in the source checkout.
### [libtmux_mcp](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/packages/mcp)
Let an MCP client inspect tmux and apply explicitly authorized workspace plans over standard I/O. The [package guide](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/packages/mcp/README.md) is available in the source checkout.
## Test a program in a pane
From a repository checkout with the [requirements](https://libtmux.org/en/elixir/pr-173/guides/overview/#installation) installed
and dependencies fetched, run the notebook test on a private tmux server.
```console
$ mix run examples/interactive.exs
```
The test prints `SAVED 1`. The [program](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/examples/interactive.exs) waits for
the notebook's `READY` line, types a note with [`Pane.send_text!/4`][text],
and submits it with [`Pane.send_keys!/4`][keys]. Its `await_line` helper
reads the screen until it sees the receipt or the wait expires.
```elixir
Pane.send_text!(server, pane, "buy milk")
unless omit_enter?, do: Pane.send_keys!(server, pane, ["Enter"])
InteractiveDemo.await_line(server, pane, "SAVED 1", timeout)
```
Run with `--omit-enter` to skip the named key. The text reaches the pane.
The notebook still waits for a complete line, so the test prints its last
screen and exits with status 124.
```console
$ mix run examples/interactive.exs --omit-enter
```
```text
Timed out after 650 ms waiting for SAVED 1. Last screen:
READY
Type a note and press Enter.
```
The example stops its private server and removes the notebook's temporary
data in both cases.
## Installation
Add the package to your Mix dependencies:
```elixir
{:libtmux, "~> 0.1"}
```
Fetch dependencies:
```console
$ mix deps.get
```
It needs:
- Elixir 1.20.4 or later in the 1.20 line, compiled for OTP 29
- OTP 29.1.2 or later in the 29 line
- tmux 3.3 or newer
- Linux and a C compiler, which builds a small helper
- no third-party runtime packages and no NIF
The exact floors and tested releases are in
[Packages and support](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/implementation.md#packages-and-support).
[Ship a CLI](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/ship-a-cli.md) covers a Mix consumer, a relocated release
and the escript delivery choices for owned and existing tmux servers.
## Try the examples
The snippets below form one [executable program](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/examples/readme.exs). It
starts a private tmux server and stops it afterward. Follow the
[checkout setup](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/.github/CONTRIBUTING.md#setup), then run the example with tmux on `PATH`.
```console
$ mix run examples/readme.exs
```
- Your own tmux sessions are untouched: the server has its own directory and
never sees `TMUX`.
- Examples that run tmux start their own private server. The pure examples
run directly in the VM.
No checkout? The [standalone demo](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/standalone-demo.md) installs the
package from Hex.
## Start a private server
[`Server.with_owned/2`][with-owned] starts a private tmux server, passes it
to your function and stops it when the function returns or raises. To own a
server across calls, use [`Server.start/1`][start] and [`Server.stop/2`][stop].
The [owned-server guide](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/owned-server.md) runs the complete window
creation and retirement example.
## Choose the server
Use [`Server.new/1`][server-new] to describe an existing server. Pass
`:socket` for an absolute socket path or `:socket_name` for a name.
Without either, the descriptor checks `LIBTMUX_SOCKET_PATH` and then
`LIBTMUX_SOCKET`. With both variables unset, tmux chooses the server.
See [Choose a socket](https://libtmux.org/en/elixir/pr-173/examples/capture-and-read/#choose-a-socket) for the executable example.
## Check tmux features on the daemon
### [`Server.capabilities/2`][server-capabilities]: decide from the daemon's release
[`Capabilities.require/2`][capabilities-require] returns a supported native
primitive or a refusal before dispatch. [`Control.capabilities/2`][control-capabilities]
reads through an established control connection.
Run the [capabilities example](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/examples/capabilities.exs) to check event-wait support.
It prints `"available"` on tmux 3.8 and `"refused"` on tmux 3.3.
More: [Check daemon features](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/capabilities.md).
## Find sessions, windows and panes
### [`Server.snapshot!/2`][snapshot]: what tmux has now
The snippets from here on run inside the function that
[`Server.with_owned/2`](https://libtmux.org/en/elixir/pr-173/guides/overview/#start-a-private-server) calls, so `server` is its
private server. One call captures every session, window and pane as an
immutable graph.
[`Snapshot.sessions/1`][snapshot-sessions],
[`Snapshot.windows/1`][snapshot-windows] and
[`Snapshot.panes/1`][snapshot-panes] pick a type, and
[`Selection.where/2`][where] filters it. None of them calls tmux again.
```elixir
alias LibTmux.{Selection, Snapshot}
snapshot = Server.snapshot!(server)
active_ids =
snapshot
|> Snapshot.panes()
|> Selection.where(active: true)
|> Enum.map(& &1.id)
```
`active_ids` is `["%0"]`: the demo server starts with one pane. Capture again
when you need fresh state.
More: [Captured state](https://libtmux.org/en/elixir/pr-173/concepts/observations/) and
[compare two snapshots](https://libtmux.org/en/elixir/pr-173/concepts/observations/#compare-two-snapshots).
### [`Selection.where/2`][where]: filter by data
Criteria are keywords or maps, and can test related panes.
[`Filter.from_json/3`][filter-json] reads the same criteria from JSON, so a
filter can come from a file or a request. [`Selection.filter/2`][filter] takes
an Elixir function instead.
```elixir
alias LibTmux.{Filter, Pane, Selection, Snapshot}
windows =
snapshot
|> Snapshot.windows()
|> Selection.where(panes: [some: [active: true, current_command: "cat"]])
|> Enum.map(& &1.id)
json = """
{"version":1,"entity":"pane",
"where":{"active":true,"currentCommand":{"in":["cat","nvim"]}}}
"""
{:ok, filter} = Filter.from_json(Pane, json)
pane_ids =
snapshot
|> Snapshot.panes()
|> Selection.where(filter)
|> Enum.map(& &1.id)
```
`windows` is `["@0"]` and `pane_ids` is `["%0"]`. One pane must meet both
conditions inside `some`.
More: [Filtering](https://libtmux.org/en/elixir/pr-173/guides/filtering/).
## Rename a window
### [`Window.rename!/4`][rename]: change a window's name
Continue with the same [`snapshot`][snapshot-type] and
[`server`][server-type]. [`Selection.one!/2`][one] needs exactly one match,
[`Session.active_window/2`][active-window] reads the captured link, and
[`Ref.from_observation/1`][ref] turns an observation into an action target.
```elixir
alias LibTmux.{Ref, Selection, Session, Snapshot, Window}
session = snapshot |> Snapshot.sessions() |> Selection.one!(id: session_id)
window = Session.active_window(snapshot, session)
{:ok, session_ref} = Ref.from_observation(session)
{:ok, window_ref} = Ref.from_observation(window)
Window.rename!(server, window_ref, "editor", session: session_ref)
```
It returns `:ok` once tmux acknowledges the command. `session:` names the
session whose link to the window to use. The old snapshot keeps the old name.
More: [One-shot actions](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/one-shot-actions.md).
## Split a pane, send input and read the screen
### [`Control.with_connection/2`][scope]: one connection for many commands
It attaches a control client to an existing session, runs your callback, and
closes the client. [`Pane.split!/3`][split] returns the new pane's ID and a
bound reference. [`Pane.send_text!/4`][text] sends literal text and
[`Pane.send_keys!/4`][keys] sends named keys. After the scope closes,
[`Pane.capture!/3`][capture] reads the new pane's screen through the `server`.
```elixir
alias LibTmux.{Control, Pane, Ref, Selection, Snapshot}
pane =
snapshot
|> Snapshot.panes()
|> Selection.one!(window_id: window.id, active: true)
{:ok, pane_ref} = Ref.from_observation(pane)
{:ok, {created_id, created}} =
Control.with_connection(
[server: server, session: {:existing, session.id}, lane: :host_qualified],
fn control ->
split_opts = [axis: :horizontal, command: {:argv, ["/bin/cat"]}]
%{id: id, ref: created} = Pane.split!(control, pane_ref, split_opts)
Pane.send_text!(control, created, "hello")
Pane.send_keys!(control, created, ["Enter"])
{id, created}
end
)
screen = Pane.capture!(server, created, max_bytes: 4096)
```
The program prints:
```text
{"window":"editor","active_panes":["%0"],"created_pane":"%1","connection_retired":true}
```
- `{:argv, ["/bin/cat"]}` runs a program directly; `{:shell, "command"}` goes
through a shell.
- An acknowledgement does not mean the program has read its input, so
[`screen`]() may not show `hello` yet.
- [`Pane.capture!/3`]() runs one command through the `server`; a control
connection refuses it.
- `lane: :host_qualified` says you control this server's hooks and aliases.
A server from [`Server.start/1`]() does. Read the managed-control guide before
using another host.
More: [Managed control](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/managed-control.md).
## Errors and recovery
### [`Action.CompletionError`][completion-error]: what went wrong
Actions return `{:ok, result}` only when the command completes; the bang forms
raise instead. A command that times out may still have taken effect, so
inspect it before you retry.
See [diagnose capture work](https://libtmux.org/en/elixir/pr-173/concepts/observations/#diagnose-capture-work) for
the commands and retained response bytes a snapshot used before it returned.
More: [Recovery](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/recovery.md), [Mental model](https://libtmux.org/en/elixir/pr-173/concepts/mental-model/).
## Guides
- [Worked API examples](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/api-examples.md) show the public calls for each task.
- [Filtering](https://libtmux.org/en/elixir/pr-173/guides/filtering/): predicates, relations and finding one match.
- [One-shot actions](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/one-shot-actions.md): rename, split, input and
screen capture.
- [Managed control](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/managed-control.md): one connection, many commands.
- [Daemon features](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/capabilities.md): release decisions and observation boundaries.
- [Owned programs in tmux panes](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/owned-program-concept.md). Run, wait
for and cancel an application on tmux 3.8.
- [Mental model](https://libtmux.org/en/elixir/pr-173/concepts/mental-model/): snapshots, references and results.
- [API reference](https://libtmux.org/en/elixir/latest/reference/): functions
and types.
## Support and status
- **Alpha.** Releases are numbered `0.1.N`. Any release may change or remove
exported functions; the [changelog](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/CHANGELOG.md) marks each break. Pin an
exact version to avoid one.
- **Linux.** The helper that owns tmux processes needs Linux.
- **tmux.** 3.3 or newer.
## What it leaves out
- **A query planner.** Selections run locally over a snapshot; `Query`,
`Batch` and `Plan` are planned.
- **Change notifications.** `Observation` and `Tracker` are planned.
## AI policy
The [documentation index for agents](https://libtmux.org/en/elixir/latest/llms.txt)
and [full Markdown reference](https://libtmux.org/en/elixir/latest/llms-full.txt)
cover the published Elixir API.
Use these packages with AI tools as you like. When contributing, check what you
submit and wait for a maintainer's invitation before preparing a pull request.
See the [AI policy](https://libtmux.org/en/meta/ai-policy/), also kept as
[AI_POLICY.md](https://github.com/libtmux/.github/blob/HEAD/AI_POLICY.md).
## Contributing
See [Contributing](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/.github/CONTRIBUTING.md) for development setup and checks,
and [Writing](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/.github/WRITING.md) for documentation conventions.
Part of the [libtmux.org](https://libtmux.org/) family alongside Python
[`libtmux`](https://github.com/tmux-python/libtmux), sibling
[language ports](https://github.com/libtmux), and
[tmux](https://github.com/tmux/tmux). [Artwork](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/assets/README.md) ·
[MIT License](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/LICENSE).
[with-owned]: https://libtmux.org/en/elixir/latest/reference/libtmux-server-with_owned-2/
[start]: https://libtmux.org/en/elixir/latest/reference/libtmux-server-start-1/
[stop]: https://libtmux.org/en/elixir/latest/reference/libtmux-server-stop-2/
[snapshot]: https://libtmux.org/en/elixir/latest/reference/libtmux-server-snapshot-bang-2/
[snapshot-type]: https://libtmux.org/en/elixir/latest/reference/libtmux-snapshot/
[snapshot-sessions]: https://libtmux.org/en/elixir/latest/reference/libtmux-snapshot-sessions-1/
[snapshot-windows]: https://libtmux.org/en/elixir/latest/reference/libtmux-snapshot-windows-1/
[snapshot-panes]: https://libtmux.org/en/elixir/latest/reference/libtmux-snapshot-panes-1/
[server-type]: https://libtmux.org/en/elixir/latest/reference/libtmux-server/
[server-new]: https://libtmux.org/en/elixir/latest/reference/libtmux-server-new-1/
[server-capabilities]: https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/capabilities.md#observe-the-server-and-connection
[control-capabilities]: https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/capabilities.md#preserve-the-observation-boundary
[capabilities-require]: https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/capabilities.md#check-a-named-primitive
[where]: https://libtmux.org/en/elixir/latest/reference/libtmux-selection-where-2/
[filter]: https://libtmux.org/en/elixir/latest/reference/libtmux-selection-filter-2/
[filter-json]: https://libtmux.org/en/elixir/latest/reference/libtmux-filter-from_json-3/
[one]: https://libtmux.org/en/elixir/latest/reference/libtmux-selection-one-bang-2/
[active-window]: https://libtmux.org/en/elixir/latest/reference/libtmux-session-active_window-2/
[ref]: https://libtmux.org/en/elixir/latest/reference/libtmux-ref-from_observation-1/
[rename]: https://libtmux.org/en/elixir/latest/reference/libtmux-window-rename-bang-4/
[scope]: https://libtmux.org/en/elixir/latest/reference/libtmux-control-with_connection-2/
[split]: https://libtmux.org/en/elixir/latest/reference/libtmux-pane-split-bang-3/
[text]: https://libtmux.org/en/elixir/latest/reference/libtmux-pane-send_text-bang-4/
[keys]: https://libtmux.org/en/elixir/latest/reference/libtmux-pane-send_keys-bang-4/
[capture]: https://libtmux.org/en/elixir/latest/reference/libtmux-pane-capture-bang-3/
[completion-error]: https://libtmux.org/en/elixir/latest/reference/libtmux-action-completionerror/
---
# Attaching to tmux
Source: https://libtmux.org/en/elixir/pr-173/guides/attaching-to-tmux/
> Connect to an existing tmux server and find a session with Elixir.
Select an explicit socket, capture the existing server, and find the `work`
session. The program prints its name and leaves the server running. A missing
server or session ends the program with an error.
This controls tmux from Elixir. To open a session in your terminal, use
[`tmux attach-session`](https://libtmux.org/en/tmux/latest/manual/attach-session/); the [shared guide](https://libtmux.org/en/tmux/guides/attaching-to-tmux/)
covers interactive attachment and detaching.
## Connect to an existing server
Save the complete program as `connect.exs`. The environment variable
`LIBTMUX_SOCKET_PATH` selects the existing server, and `print_work` connects
to it and finds `work`. Without the variable, the program starts a private
server of its own in a new temporary directory, creates `work` with
[`new_session!`](), and calls `print_work` with that socket through a second
[`Server`]() value. The library works on a running server and does not
start one, so the program has `tmux` start the daemon. It stops the private
server with [`Server.run/3`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-server-run-3/) and
removes the directory after success or failure. If the server does not stop,
the program reports the error and keeps the directory.
The first line installs libtmux from Hex. Its requirement, `~> 0.1`, accepts
any release from 0.1.0 up to, but not including, 1.0.0.
```elixir title="connect.exs" role="program"
Mix.install([{:libtmux, "~> 0.1"}])
alias LibTmux.{Command, Selection, Server, Snapshot}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
print_work = fn socket ->
server = Server.new(executable: tmux, socket: socket)
snapshot = Server.snapshot!(server)
session = snapshot |> Snapshot.sessions() |> Selection.one!(name: "work")
IO.puts(session.name)
end
case System.get_env("LIBTMUX_SOCKET_PATH") do
nil ->
# No server was named: start one this program owns.
id = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower)
dir = Path.join(System.tmp_dir!(), "libtmux-attach-" <> id)
socket = Path.join(dir, "tmux.sock")
owner = Server.new(executable: tmux, socket: socket)
File.mkdir!(dir)
File.chmod!(dir, 0o700)
try do
# libtmux works on a running server, so tmux starts the daemon itself.
start = ~w(start-server ; set-option -s exit-empty off)
{_, 0} = System.cmd(tmux, ["-S", socket, "-f", "/dev/null" | start])
Server.new_session!(owner, "work", command: {:argv, ["/bin/cat"]})
print_work.(socket)
after
kill = Command.new("kill-server", [])
running = File.exists?(socket)
stopped = not running or match?({:ok, _}, Server.run(owner, kill))
if stopped do
File.rm_rf!(dir)
else
IO.puts(:stderr, "Cannot stop tmux; kept #{dir}")
System.halt(1)
end
end
socket ->
print_work.(socket)
end
```
[`Server.new/1`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-server-new-1/) describes a server that
already exists and performs no I/O. [`Server.snapshot!/2`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-server-snapshot-bang-2/)
reads tmux and returns captured state, or raises the structured capture error.
[`Snapshot.sessions/1`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-snapshot-sessions-1/) selects
sessions from that state without contacting tmux again, and
[`Selection.one!/2`](https://libtmux.org/en/elixir/pr-173/reference/libtmux-selection-one-bang-2/) requires
exactly one match. Reading or filtering captured values does not refresh them.
The server value describes the daemon. It does not own a process to close, and
the program does not destroy the caller's sessions.
## Setup and run
Use an empty directory on Linux with Elixir 1.20.4 or newer, Erlang/OTP 29.1.2
or a newer 29.x release, a C11 compiler, tmux 3.3 or newer, and access to
hex.pm.
```console
$ elixir connect.exs
```
The program prints `work`. To use your own existing server, set
`LIBTMUX_SOCKET_PATH` to its socket before running the program; it prints
`work` and leaves that server running.
## Find or create a session
Reading a session does not reserve its name. If your application creates a
session after an unsuccessful lookup, another client may create the same name
between those operations. Handle the creation error as well as the lookup.
[Mental model](https://libtmux.org/en/elixir/pr-173/concepts/mental-model/) and
[Observations](https://libtmux.org/en/elixir/pr-173/concepts/observations/) explain what a snapshot holds.
[Capture a pane and read it](https://libtmux.org/en/elixir/pr-173/examples/capture-and-read/) is a complete
program that runs against an isolated server.
The [library source revision](https://github.com/libtmux/libtmux-elixir/tree/cac4252bfc52069980d47db2b7803dc9b33f36f1)
records the implementation used by this example.
---
# Filter captured values
Source: https://libtmux.org/en/elixir/pr-173/guides/filtering/
> Select observed values with portable keyword and operator filters.
Capture one [snapshot](https://libtmux.org/en/elixir/pr-173/concepts/observations/), then select from it. The examples run
on a private server from [`Server.with_owned/2`](https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/docs/owned-server.md). From a
checkout, with tmux on `PATH`:
```console
$ mix run examples/filtering.exs
```
```elixir
editors = ["cat", "nvim", "vim"]
active =
snapshot
|> Snapshot.panes()
|> Selection.where(active: true, current_command: [in: editors])
Enum.map(active, & &1.id)
```
- Selections keep their graph and order. Enumerating one does no I/O.
- `size/1` reads a cached count.
- [`Enum.member?/2`]() compares elements; [`Selection.member_id?/2`]() compares
native IDs.
## Select
- `where/2` takes validated data. Keywords are shorthand for maps, and
duplicate keys are rejected at every level.
- `filter/2` takes a unary function and uses [`Enum`]() truthiness. Predicate
exceptions propagate.
- Both validate before scanning, even when no items remain.
- `one/2` returns `{:ok, item}` or a structured `:no_match` or
`:multiple_matches` error. `one!/2` raises the same error.
- `one_or_nil/2` also allows zero matches. Both stop at the second match.
- `exists?/2` stops at the first match. `count/2` counts matches; `size/1`
returns the total.
## Predicate grammar
- A bare scalar means equality; `%{equals: value}` is the same. The
[generated schema](https://libtmux.org/en/elixir/pr-173/topics/schema/) lists each field's type and operators.
- Numbers compare numerically and strings compare case-sensitively, with no
normalization. Ordering a nullable number against a known [`nil`]() is false.
- `not` negates equality. `not_in` negates membership, including known [`nil`]().
- Portable regex is not supported. Native predicates may use [`Regex`]().
- Fields in one object conjoin. `and` and `or` take lists of criteria and
`not` takes one criteria object. An empty `and` is true; an empty `or` is
false.
- Separate relation quantifiers are never combined:
```elixir
with_cat =
Selection.where(Snapshot.sessions(snapshot), %{
panes: %{some: %{active: true, current_command: "cat"}}
})
```
That predicate needs one pane to satisfy both conditions. Two separate `some`
clauses can match different panes.
- `every` and [`none`]() are true for a known-empty relation; `some` is false.
- [`count`]() counts the relation's identities. Physical windows and panes
deduplicate; window links keep their memberships.
- To-one `is: criteria` is false for known absence, and `is_not` negates it.
`is: nil` means absent; `is_not: nil` means present.
- A session's [`active_window`]() comes from a complete link domain and loaded
active flags. Zero active links is known absence; several raise
`:ambiguous_relation`. An unresolved active target stays unloaded.
- Coverage checks run before evaluation, including fields behind a Boolean
branch that cannot match.
## External filters
- [`Filter.new/3`]() returns a validated portable value; `new!/3` raises its
structured error. Applying the value keeps its constructor validation.
- Prepared predicates may hold sets and closures. Portable filters hold only
data. [`LibTmux.Filter.to_predicate/2`]() reuses a filter as a predicate.
- [`Filter.from_json/3`]() uses built-in JSON. It rejects duplicate keys,
trailing data and unknown names.
- `from_wire/3` takes an already decoded map, which cannot show discarded
duplicate keys.
- Neither decoder creates atoms from external keys.
- Encode with [`Filter.to_wire/1`](), then [`JSON.encode!/1`]().
```elixir
alias LibTmux.{Filter, Pane}
criteria = [active: true, current_command: [in: ["nvim", "vim"]]]
{:ok, filter} = Filter.new(Pane, criteria)
json = filter |> Filter.to_wire() |> JSON.encode!()
{:ok, ^filter} = Filter.from_json(Pane, json)
```
The document is:
```json
{
"version": 1,
"entity": "pane",
"where": {
"active": true,
"currentCommand": {"in": ["nvim", "vim"]}
}
}
```
## Limits
Defaults: 65,536 bytes, depth 16, 1024 value nodes, 256 array elements and
8192 bytes per string. Positive integer options `max_bytes`, `max_depth`,
`max_nodes`, `max_list` and `max_string_bytes` narrow or widen them.
- A JSON object has at most 256 members.
- Wire depth starts at root zero and counts every member and element. The
ceiling is inclusive.
- Native input depth counts criteria objects and bounds the normalized tree.
A normalized conjunction adds no relation or Boolean nesting; disjunctions,
negations and relation children do.
- Wire budgets also cover the versioned envelope.
- Errors carry the affected path, including Boolean and membership indexes.
An early parser-limit error can name only the root.
Filters run locally on a captured snapshot. Server-side query planning is not
implemented.
---
# Linking and consuming our docs
Source: https://libtmux.org/en/elixir/pr-173/meta/linking/
> Find documentation exports for search engines, bots, LLMs and other documentation sites.
We welcome bots, search engines, SEO tools, LLMs and other clients to use our
documentation. Read a page in your browser, fetch its Markdown, discover
pages through a manifest, or link to documented objects from another site.
## Choose an export
The page footer links to the exports for its documentation tree. Use those
links to select a language, version or preview.
| File or format | Use it for |
| --- | --- |
| [llms.txt](https://libtmux.org/en/llms.txt) | Discover guides, API references and agent prompts through a Markdown index. |
| [llms-full.txt](https://libtmux.org/en/llms-full.txt) | Fetch the guides together as Markdown. API references are linked separately. |
| [docs.json](https://libtmux.org/en/docs.json) | Discover page titles, URLs, descriptions, headings and Markdown URLs in a structured manifest. |
| Markdown | Read one page as text using its footer's **Markdown** link. |
| Raw source | Inspect the source file using its footer's **Raw source** link, where available. |
| [objects-full.inv](https://libtmux.org/en/objects-full.inv) | Resolve Sphinx references across shared docs, each port's default version, or its latest until the default has published a catalog, and tmux reference versions. |
| objects.inv | Resolve Sphinx references within one port and version, or one tmux documentation tree. |
| [targets.json](https://libtmux.org/en/targets.json) | Browse inventory keys, display names and destination URLs as JSON. A scoped catalog sits beside each root inventory. The root one lists fallbacks and ports left out. |
The root exports above cover the assembled site. Port exports describe the
selected port and version. For a single API declaration, start with
`docs.json` and follow its reference and symbol-index links.
## Link from Sphinx
The [Intersphinx guide](https://libtmux.org/en/meta/intersphinx/) explains how to configure
inventories, choose native roles or portable labels, and preserve references
when a page moves or changes its title.
Browse [Intersphinx examples](https://libtmux.org/en/meta/intersphinx/examples/) for copyable RST
and MyST references to library APIs, tmux C declarations, hooks, format
variables, CLI commands and schema fields, paired with their destinations.
## Discover and index pages
Use the [sitemap](https://libtmux.org/en/sitemap-index.xml) to discover indexable pages. Follow
[robots.txt](https://libtmux.org/robots.txt) and each page's robots metadata:
pull-request previews, component demos and search-index shards are excluded
from crawling, and alternate versions can carry `noindex`.
Choose a versioned documentation tree when a reference needs a particular
release. The full inventory follows each port's advertised default; a
port's `objects.inv` describes the selected version.
---
# Link to libtmux from Sphinx
Source: https://libtmux.org/en/elixir/pr-173/meta/intersphinx/
> Use Intersphinx inventories to reference libtmux APIs and documentation.
Sphinx can resolve references to libtmux APIs, guides, headings, MCP objects,
schema fields, and other documented targets. The footer links to the full
inventory and the inventory for the page's port or tmux version.
Browse [Intersphinx examples](https://libtmux.org/en/meta/intersphinx/examples/) for copyable RST
and MyST references paired with their destinations.
For Markdown exports, manifests and crawler discovery, see
[Linking and consuming our docs](https://libtmux.org/en/meta/linking/).
## Configure Intersphinx
Enable the built-in extension in your project's `conf.py`:
Python's [`None`]() discovers `objects.inv` at the configured base URL. The port mapping
above selects the Python `latest` tree. Copy the base URL of another port
or version to select its inventory.
The full inventory includes shared documentation, the configured default
version of each assembled port, and distinct tmux reference versions.
It is generated after site assembly. Each port inventory includes the
rendered targets in that exact version.
The tmux inventory includes the shared tmux guides and the latest CLI manual,
options, hooks, formats, and C source reference. A version mapping such as
`tmux-3-7c` includes only that release's manual, catalog, and C declarations.
Manual and C reference pages link to the same version inventory in the footer.
Use mapping names without dots when writing MyST reference roles.
## Choose a reference
Every exported target has a portable label that works with `std:ref`, without
installing a language or MCP domain. Open `targets.json` beside the inventory
and copy its [`key`](). Its `href` and `display` identify the destination.
For example, the Python [`libtmux.Pane`]() declaration has this reStructuredText
reference:
```rst
:external+libtmux:ref:`Pane `
```
With MyST enabled in your project, the same label works in Markdown:
```markdown
{external+libtmux:ref}`Pane `
```
Native Python, C++, JavaScript, and C objects also have aliases for their
built-in roles. A scoped Python inventory supports:
```rst
:external+libtmux-python:py:class:`libtmux.Pane`
```
The tmux mapping provides native C roles and portable manual references:
```rst
:external+tmux:c:struct:`cmd`
:external+tmux:ref:`capture-pane `
```
Command options also work with Sphinx's program context:
```rst
.. program:: tmuxp load
:external+libtmux-python:option:`--append`
```
The full inventory qualifies native names by port, such as
[`py:libtmux.Pane`](). A fully qualified alias includes the product too:
[`py:core:libtmux.Pane`](). Short aliases are offered only when they identify
one destination. Configuration values, command options, environment
variables, and glossary terms use standard-domain types where their
renderers identify those semantics.
## Stable labels
A portable key contains `scope:product:category:identity`. Its encoding
preserves uppercase letters, punctuation, and Unicode, because `std:ref`
lowercases targets. `%50ane` and `pane` therefore remain distinct.
Copy the key from the catalog without decoding its percent escapes.
Keys are independent of display titles and destination URLs. API public IDs,
protocol wire identities, JSON Pointers, named parameters, and native method
identities supply their names. Authored documents can retain `inventoryId`
and explicit HTML fragment IDs when their titles or routes change.
Contributors preserve renamed keys in the inventory alias catalog and use
the existing page redirect mechanism for retired routes.
### Preserve published links
If `meta/intersphinx.md` moves to `meta/linking.md`, retain its logical ID
and list the retired route in the new page's frontmatter:
```yaml
inventoryId: intersphinx
aliases:
- meta/intersphinx
```
The document key remains `site:core:doc:intersphinx`, and the old route
redirects to the new page. Retain existing heading fragment IDs when their
text changes.
When an identity or fragment changes intentionally, map the former keys to
current targets in `site/src/data/inventory-aliases.json`. For example,
choosing `inventoryId: linking` and changing `stable-labels` to
`stable-references` needs these entries:
```json
[
{
"scope": "site",
"from": "site:core:doc:intersphinx",
"to": "site:core:doc:linking"
},
{
"scope": "site",
"from": "site:core:heading:intersphinx%23stable-labels",
"to": "site:core:heading:linking%23stable-references",
"fragment": "stable-labels"
}
]
```
The document entry preserves `std:ref` and `std:doc` references. The heading
entry preserves `std:ref`; `fragment` also installs the retired HTML anchor
at the new destination. Keep the route alias too: inventory aliases do not
redirect retired URLs.
Copy `to` from the current target catalog. Retain earlier `from` entries
and update their destinations when renaming again. Former native role names,
such as a Python class name, need preservation in the native metadata.
Existing `objects.inv` and `reference/objects.inv` endpoints remain compatibility
exports. New integrations should use the full inventory, a port's root
inventory, or a tmux root inventory to obtain the complete target catalog
and case-safe labels.
See the [Sphinx Intersphinx documentation](https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html)
for named inventories and cross-reference syntax.
---
# Intersphinx examples
Source: https://libtmux.org/en/elixir/pr-173/meta/intersphinx/examples/
> Compare Sphinx and MyST references to APIs, tmux C declarations, hooks, format variables, CLI commands and schema fields.
import { referenceHref } from '../../../../lib/api-models'
Copy a reference and compare its destination below. These examples cover
native language roles, portable labels, full and scoped inventories, and
links into tmux C declarations, hooks, format variables and CLI commands.
## Configure the inventories
Add these mappings to your Sphinx project's `conf.py`:
Python's [`None`]() discovers `objects.inv` at the mapping's base URL. The full inventory
uses each port's advertised default version. The `py` mapping explicitly
selects `latest`; `tmux` selects the latest tmux manual and C reference.
Use the root URL from an inventory's footer link when selecting a preview
or another release.
## Native Python roles
A named inventory selects the Python tree:
```rst
:external+py:py:class:`libtmux.Pane`
```
Destination: [Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
The full inventory qualifies native names by port:
```rst
:external+full:py:class:`py:libtmux.Pane`
```
Destination: Pane in the Python default version.
For automatic lookup, use the ordinary role. A local definition takes
precedence over Intersphinx:
```rst
:py:class:`libtmux.Pane`
```
Destination: [Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
## Portable labels
Portable labels work with the standard reference role, including languages
that have no built-in Sphinx domain. Copy the key from `targets.json`.
```rst
:external+full:ref:`Pane `
:external+py:ref:`Pane `
```
Destinations: Full inventory: Pane,
[Scoped inventory: Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
The external role searches the configured inventories without selecting one.
This native name is unqualified only in the scoped Python inventory:
```rst
:external:py:class:`libtmux.Pane`
```
Destination: [Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
## MyST roles and inventory URLs
Enable `myst_parser` alongside
[`sphinx.ext.intersphinx`](https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html)
for Markdown sources.
Named roles accept the same targets as reStructuredText:
```markdown
{external+py:py:class}`libtmux.Pane`
```
Destination: [Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
Portable labels retain their percent escapes inside reference roles:
```markdown
{external+full:ref}`Pane `
```
Destination: Pane in the Python default version.
MyST's inventory URL syntax also supports native aliases:
```markdown
[Pane](inv:py:py:class#libtmux.Pane)
```
Destination: [Pane](https://libtmux.org/en/py/latest/reference/libtmux-pane/#libtmux.Pane).
Use role syntax for percent-encoded portable keys: MyST normalizes escapes
in `inv:` URLs. Keep mapping names free of dots, as in `tmux-3-7c`, so MyST
can parse the role name. When using an inventory URL, specify its domain and
object type if a name is both a document and a label.
## tmux C declarations
The tmux mapping provides Sphinx's built-in C roles:
```rst
:external+tmux:c:struct:`cmd`
:external+tmux:c:func:`cmd_find_target`
```
Destinations: [cmd](https://libtmux.org/en/tmux/latest/reference/c-struct-cmd/#c%3Astruct%3Acmd),
[cmd_find_target](https://libtmux.org/en/tmux/latest/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target).
Select a release with its own mapping. The full inventory also offers
version-qualified native aliases:
```rst
:external+tmux-3-7c:c:func:`cmd_find_target`
:external+full:c:func:`tmux@3.7c:cmd_find_target`
:external+full:c:func:`tmux@latest:cmd_find_target`
```
Destinations: [Scoped: cmd_find_target in 3.7c](https://libtmux.org/en/tmux/3.7c/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target),
[Full: cmd_find_target in 3.7c](https://libtmux.org/en/tmux/3.7c/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target),
[Full: cmd_find_target in latest](https://libtmux.org/en/tmux/latest/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target).
MyST supports the same C roles and a typed inventory URL:
```markdown
{external+tmux:c:struct}`cmd`
{external+tmux:c:func}`cmd_find_target`
{external+full:c:func}`tmux@3.7c:cmd_find_target`
[cmd_find_target](inv:tmux:c:function#cmd_find_target)
```
Destinations: [MyST: cmd](https://libtmux.org/en/tmux/latest/reference/c-struct-cmd/#c%3Astruct%3Acmd),
[MyST: cmd_find_target](https://libtmux.org/en/tmux/latest/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target),
[MyST full: cmd_find_target in 3.7c](https://libtmux.org/en/tmux/3.7c/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target),
[Inventory URL: cmd_find_target](https://libtmux.org/en/tmux/latest/reference/c-function-cmd_find_target/#c%3Afunction%3Acmd_find_target).
The C reference links each declaration to its source file and revision.
Portable labels also address its signatures, parameters, and sections.
## tmux hooks
Link a hook name to its catalog page with a portable label. The same key
works in the scoped tmux inventory and the full inventory:
```rst
:external+tmux:ref:`after-new-session `
:external+full:ref:`after-new-session `
```
Destinations: [Scoped: after-new-session](https://libtmux.org/en/tmux/latest/catalog/hooks/after-new-session/),
[Full: after-new-session](https://libtmux.org/en/tmux/latest/catalog/hooks/after-new-session/).
In MyST, use the same key inside a reference role. Preserve its percent
escapes:
```markdown
{external+tmux:ref}`after-new-session `
{external+full:ref}`after-new-session `
```
Destinations: [MyST scoped: after-new-session](https://libtmux.org/en/tmux/latest/catalog/hooks/after-new-session/),
[MyST full: after-new-session](https://libtmux.org/en/tmux/latest/catalog/hooks/after-new-session/).
## tmux formats
Link a format variable such as [`#{session_name}`](https://libtmux.org/en/tmux/latest/catalog/formats/session_name/) to its catalog entry:
```rst
:external+tmux:ref:`session_name `
:external+full:ref:`session_name `
```
Destinations: [Scoped: session_name](https://libtmux.org/en/tmux/latest/catalog/formats/session_name/),
[Full: session_name](https://libtmux.org/en/tmux/latest/catalog/formats/session_name/).
The MyST references select the same scoped or full inventory:
```markdown
{external+tmux:ref}`session_name `
{external+full:ref}`session_name `
```
Destinations: [MyST scoped: session_name](https://libtmux.org/en/tmux/latest/catalog/formats/session_name/),
[MyST full: session_name](https://libtmux.org/en/tmux/latest/catalog/formats/session_name/).
## tmux CLI manual
The same tmux inventory covers command pages:
```rst
:external+tmux:ref:`capture-pane `
```
Destination: [capture-pane](https://libtmux.org/en/tmux/latest/manual/capture-pane/).
The document role works when the target is a whole page:
```rst
:external+tmux:doc:`Full manual `
```
Destination: [Full tmux manual](https://libtmux.org/en/tmux/latest/manual/full/).
Select a command's manual page with the document role. Its portable key
also works in the full inventory:
```rst
:external+tmux:doc:`tmux new-session `
:external+full:doc:`tmux new-session `
```
Destinations: [Scoped: new-session](https://libtmux.org/en/tmux/latest/manual/new-session/),
[Full: new-session](https://libtmux.org/en/tmux/latest/manual/new-session/).
Use the same document role in MyST:
```markdown
{external+tmux:doc}`tmux new-session `
{external+full:doc}`tmux new-session `
```
Destinations: [MyST scoped: new-session](https://libtmux.org/en/tmux/latest/manual/new-session/),
[MyST full: new-session](https://libtmux.org/en/tmux/latest/manual/new-session/).
## Command options, environment variables, and terms
The Python port's workspace documentation exports standard-domain objects.
Set the program context before referencing an option:
```rst
.. program:: tmuxp load
:external+py:option:`--append`
```
Destination: [tmuxp load --append](https://libtmux.org/en/py/latest/workspace/cli/load/#arguments-and-flags-a-append).
Environment variables and glossary terms use their own roles. Qualify the
product when a term appears in more than one glossary:
```rst
:external+py:envvar:`COLUMNS`
:external+py:term:`async `
```
Destinations: [COLUMNS](https://libtmux.org/en/py/latest/workspace/configuration/environment/#cli-and-runtime-variables-columns-lines-rows),
[async](https://libtmux.org/en/py/latest/reference/glossary/#async).
## MCP tools and schema fields
Portable labels also address protocol objects and individual JSON Schema
fields. No custom MCP domain is required:
```markdown
{external+py:ref}`Read tools batch `
{external+py:ref}`on_error `
```
Destinations: [Read tools batch](https://libtmux.org/en/py/latest/mcp/tools/call_read_tools_batch/#mcp.tool.call_read_tools_batch),
[on_error](https://libtmux.org/en/py/latest/mcp/tools/call_read_tools_batch/#mcp.tool.call_read_tools_batch.input%2Fproperties%2Fon_error).
## Shared documentation and headings
The full inventory includes the shared documentation:
```rst
:external+full:doc:`Inventory guide `
:external+full:ref:`Configure Intersphinx `
```
Destinations: [Inventory guide](https://libtmux.org/en/meta/intersphinx/),
[Configure Intersphinx](https://libtmux.org/en/meta/intersphinx/#configure-intersphinx).
## Local files and fallback locations
Download an inventory and pass its filename as the second mapping value.
The first value remains the documentation URL used in generated links:
An ordered list tries a local copy before the HTTP inventory:
See the [inventory guide](https://libtmux.org/en/meta/intersphinx/) for key stability and the
[Sphinx Intersphinx reference](https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html)
for configuration options.
---
# AI policy
Source: https://libtmux.org/en/elixir/pr-173/meta/ai-policy/
> Use the libtmux packages with AI tools. When contributing, check what you submit and wait for a maintainer's invitation before preparing a pull request.
Last revised October 25, 2026
Use these packages with AI tools as you like. When contributing, check what
you submit and wait for a maintainer's invitation before preparing a pull
request.
This policy covers the libraries, ports, and documentation in the
[libtmux](https://github.com/libtmux) and
[tmux-python](https://github.com/tmux-python) organizations, including their
issues, comments, discussions, reviews, and pull requests.
## 1. For users: About these packages
We encourage you to use AI tools with our libraries and documentation,
including to generate code that calls the libraries. We want these projects to
be useful in the way you work. Some of what we publish supports that workflow:
- [MCP integrations](https://libtmux.org/en/py/latest/mcp/) that let assistants interact with tmux.
- Markdown documentation and `llms.txt` and `llms-full.txt` resources linked
from documentation pages.
- [`AGENTS.md`]() and other repository instructions for tools working on the
codebase.
Use the documentation for the package, language, and version you are working
with.
### How the ports are made
The ports build on [tmuxp](https://tmuxp.git-pull.com/), started in 2013, and
[libtmux](https://libtmux.git-pull.com/), started in 2016. Both projects
predate today's LLM coding tools. Current work on the original projects and the
ports uses AI assistance.
Maintainers guide the design, review changes, test behavior against real tmux,
and decide what ships. They remain responsible for what the projects include
and maintain.
### Stability
Packages in the [libtmux organization](https://github.com/libtmux) are
experimental unless their README says otherwise. Names and APIs may change
between releases. Pin an exact version and review changes before upgrading.
## 2. For contributors: How to report issues, ideas, suggestions, and security issues
A useful issue is a contribution in its own right. Your experience helps us see
what breaks, what feels awkward, and what is missing. You do not need to arrive
with a patch.
Open bugs, ideas, and suggestions in the repository of the package they
concern. Report suspected security vulnerabilities privately using the route
below.
### Bugs
Tell us what you tried, what happened, and what you expected. Include a small
example we can run, the library and tmux versions, and the actual output.
Include relevant logs and error messages as they appeared, and distinguish what
you observed from possible explanations.
Bug reports are welcome whether the code you were running was handwritten or
generated. Include the code that ran. A conversation transcript is usually
unnecessary; include relevant prompts or tool calls when they are needed to
reproduce the problem.
### Ideas and suggestions
Explain what you wanted to accomplish and where the current design gets in
your way. We welcome feedback on:
- Usability: what was hard to find or get right, and where the documentation
misled you.
- Language conventions: whether a port feels natural in the language you use.
- Aesthetics: how an API, a page, or an error message reads.
- Missing capabilities: what you could not accomplish with the current API.
If an API you expected is missing, describe the task and why that API would
help.
### Security issues
Report suspected security vulnerabilities privately. Use **Report a
vulnerability** on the affected repository's security page where available.
Include the affected package and version, the tmux version, what you observed,
and reproduction steps or relevant code references if available. Distinguish
verified behavior from suspected impact. Please coordinate public disclosure
with us so we can investigate and, where needed, prepare a fix.
Command execution explicitly requested through documented features is expected
behavior and does not, by itself, establish a vulnerability. Explain any
additional failure, such as data being interpreted as commands unexpectedly or
an intended security boundary being crossed.
### Writing your report
Short reports, typos, and imperfect English are fine. Translation and writing
assistance are welcome; check that the result says what you mean and preserves
the facts you observed. Your experience matters more than a polished report.
### Using AI tools
If AI materially helped prepare your issue, comment, discussion, review, or
pull request, say which tools you used, what they did, and what you checked
yourself. Using these tools does not count against a contribution. You remain
responsible for what you submit.
Do not send generated code, reports, or explanations you have not checked.
### Pull requests
Before preparing a pull request, open an issue or comment on an existing issue
about the proposed change. Wait for a maintainer to invite a PR for an agreed
scope. Opening an issue alone is not an invitation. PRs submitted without that
agreement may be closed without review. Arrange security fixes through the
private reporting route.
Even when we agree that something should change, we may prefer to write the
implementation ourselves. Review must consider correctness, supported tmux
versions, language conventions, documentation, and ongoing maintenance.
Checking those can take more time than writing the change, whether it was
handwritten or generated.
If we invite a PR, understand the changes, test them, and be able to explain
them. Follow the project's contribution instructions, and describe the tests
you ran and the versions you used. Generated code and tests can share the same
mistake, so passing tests alone do not show that a change fits the project.
Submit only material you have the right to contribute on terms compatible with
the project's license. Identify outside code, tests, or text incorporated into
the contribution, including material adapted with AI assistance, and provide
its source and license. Keep required notices, and raise unclear permissions
before including the material. These source and licensing requirements apply
to maintainers too.