# LibTmux::Server

- **Package:** LibTmux
- **Language:** Raku
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-raku/blob/e76160bcce6e03976d49424da15b7c31afb2c68e/lib/LibTmux/Server.rakumod#L3
- **Page:** https://libtmux.org/en/raku/latest/reference/libtmux-server/

# Server ownership

` new ` captures a borrowed endpoint without I/O. ` snapshot ` and ` capabilities `
acquire daemon state explicitly. [`new-session`](/en/tmux/latest/manual/new-session/) requires an existing daemon,
creates a detached session, and returns a SessionRef from tmux's returned ID.
Names are literal Unicode text; controls, backslash, dot and colon are refused
before creation because supported tmux releases normalize them differently.
A shell-command explicitly requests tmux's shell-command interpretation.

` start ` creates a clean foreground daemon on an exclusive temporary socket,
verifies its executable profile before launch, binds its actual process identity,
and creates the initial session. The startup timeout covers all stages. Linux
inotify socket attributes signal listener readiness; pidfds bind termination to
the original process, independently of socket reuse.

Close is idempotent and joins owned work. Borrowed daemons remain running.
Owned daemons receive TERM followed by bounded KILL escalation and are reaped.
Cleanup removes only the original socket and empty original directory; unknown
files and replacement sockets are preserved. References retain values only and
are not clients owned by the Server. A stopped owned daemon invalidates them.

Configuration factories perform one explicit identity observation. The returned
facades retain endpoint and incarnation values, and each subsequent configuration
operation owns its temporary command client. ` open-control ` and ` attach ` return
separate lifecycle owners: callers must close them. Closing a borrowed Server
does not close those owners; closing an owned daemon causes its attached clients
to disconnect. ` attach ` proves process creation, not terminal readiness.

` command ` is an explicit tmux-syntax escape hatch with a daemon fence. It does
not insert an entity target or interpret shell syntax on the caller's behalf.
` run-batch ` reports partial outcomes and never promises rollback.



# Explicit environment and health

` from-env ` is the only factory that interprets ` TMUX `. It parses its final
PID and session components from the right, so commas in the socket path remain
literal. It requires an absolute socket path, validates ` TMUX_PANE ` when
present, observes the actual daemon and rejects a different PID. The returned
borrowed facade is bound to that incarnation. Child processes still receive
neither ambient variable. Imported object IDs are observations from the supplied
environment, not evidence that those objects still exist:

use LibTmux;
my $server = LibTmux::Server.from-env(:environment(%*ENV));
LEAVE $server.close;
my $snapshot = $server.snapshot;
my $pane = $snapshot.panes.where(%(id => $server.environment-pane-id)).single;
my $window = $pane.window;
my $session = $snapshot.sessions
    .where(%(id => $server.environment-session-id)).single;

The selection throws for a vanished object or absent imported ID. A window can
belong to several sessions; the imported session ID supplies that context.
` capabilities ` is the explicit native health observation: success returns
verified daemon evidence, while connection, identity and permission failures
retain their original typed exceptions. [`has-session(:name)`](/en/tmux/latest/manual/has-session/) and
[`has-session(:id)`](/en/tmux/latest/manual/has-session/) return false only after a successful exact listing finds
no match. [`kill-server`](/en/tmux/latest/manual/kill-server/) deliberately terminates the observed daemon, including
a borrowed one; ` close ` continues to preserve borrowed daemons. An owner must
still close after [kill-server](/en/tmux/latest/manual/kill-server/) to join its process and filesystem cleanup.



# Jobs and channels

[`run-shell`](/en/tmux/latest/manual/run-shell/) receives literal shell source; tmux FORMAT-looking text is escaped
before dispatch. [`if-shell`](/en/tmux/latest/manual/if-shell/) follows the same rule for its shell condition and
accepts bounded Invocation values for both branches. Its explicit ` :format `
option instead evaluates a native tmux FORMAT condition. [`source-file`](/en/tmux/latest/manual/source-file/) reads
one literal pathname, escaping native glob metacharacters; it does not expand
FORMAT, tilde or a caller shell. Relative paths use the captured command cwd.
` :parse-only ` parses configuration without executing it.

Each request shares one admission, observation and dispatch deadline. A
background job acknowledges scheduling. Foreground completion follows tmux's
job/command queue contract, not an application-specific postcondition; command
output availability also depends on the declared daemon profile. Timing out or
cancelling a client does not undo a job, configuration effect or channel lock
already accepted by the daemon. [`wait-for`](/en/tmux/latest/manual/wait-for/) offers only wait, signal, lock and
unlock; it does not claim that a signal proves another process's application
work completed.



# Administrative commands

Diagnostics and administrative commands intentionally use the explicit bounded
Invocation surface rather than separate wrappers. These complete calls retain
raw stdout/stderr in Result, enforce the server deadline and throw typed command
errors. [`list-commands`](/en/tmux/latest/manual/list-commands/), [`show-messages`](/en/tmux/latest/manual/show-messages/), [`lock-server`](/en/tmux/latest/manual/lock-server/) and [`server-access`](/en/tmux/latest/manual/server-access/)
are deliberate replacements for named Python helpers, not claims of identical
typed parameters. ` switch-mode ` is also available through Invocation.

use LibTmux;
my $server = LibTmux::Server.start(:name<inspection>);
LEAVE $server.close;
my $commands = $server.command(Invocation.new(:argv(['[list-commands](/en/tmux/latest/manual/list-commands/)'])));
my $access = $server.command(Invocation.new(:argv(['[server-access](/en/tmux/latest/manual/server-access/)', '-l'])));
my $messages = $server.command(Invocation.new(:argv(['[show-messages](/en/tmux/latest/manual/show-messages/)', '-T'])));
$server.command(Invocation.new(:argv(['[lock-server](/en/tmux/latest/manual/lock-server/)'])));

Administrative flags keep tmux's native semantics and errors; arbitrary
Invocation values do not acquire a typed catalogue guarantee. Locking may run
configured lock commands on attached clients. Access changes affect other users.
Use only an endpoint whose administration the caller owns or has authorized.
To detach captured clients, iterate ` $snapshot.clients ` and call each
` .ref.detach `. Each target is identity guarded; a changing client set is not
an atomic detach-all operation, and acknowledgement does not prove terminal
rendering or child-process exit.

## Members

### Collections and queries

- [`buffers`](/en/raku/latest/reference/libtmux-server-buffers/) (method): Observe daemon identity and return its named binary-buffer facade.
- [`snapshot`](/en/raku/latest/reference/libtmux-server-snapshot/) (method): Acquire a captured graph explicitly. Existing snapshots remain unchanged.

### Common operations

- [`new-session`](/en/raku/latest/reference/libtmux-server-new-session/) (method): Create a detached session and return its value-only, identity-scoped reference.
- [`kill-server`](/en/raku/latest/reference/libtmux-server-kill-server/) (method): Explicitly terminate this observed daemon. Owned callers must still close to join cleanup.
- [`source-file`](/en/raku/latest/reference/libtmux-server-source-file/) (method): Source one literal local pathname; parse-only validates without running its commands.
- [`command`](/en/raku/latest/reference/libtmux-server-command/) (method): Execute explicit tmux command syntax in the currently observed daemon.
- [`wait-for`](/en/raku/latest/reference/libtmux-server-wait-for/) (method): Wait, signal, lock or unlock a named channel; timeout cannot undo server-side effects.
- [`run-shell`](/en/raku/latest/reference/libtmux-server-run-shell/) (method): Run literal shell source through tmux. Background acknowledgement is not job completion.
- [`has-session`](/en/raku/latest/reference/libtmux-server-has-session/) (method): Test one exact session ID or name. Acquisition and identity failures still throw.
- [`capabilities`](/en/raku/latest/reference/libtmux-server-capabilities/) (method): Observe the daemon's capabilities explicitly; this performs tmux I/O.
- [`attach`](/en/raku/latest/reference/libtmux-server-attach/) (method): Spawn a separately owned interactive client on the caller's explicit terminal.
- [`start`](/en/raku/latest/reference/libtmux-server-start/) (method): Start an owned foreground daemon on a fresh private socket and create its first session.
- [`if-shell`](/en/raku/latest/reference/libtmux-server-if-shell/) (method): Execute one of two bounded commands after a shell test, or an explicit FORMAT condition.
- [`run-batch`](/en/raku/latest/reference/libtmux-server-run-batch/) (method): Run a declared batch with one observed incarnation and a shared deadline.
- [`from-env`](/en/raku/latest/reference/libtmux-server-from-env/) (method): Import an explicit TMUX environment, verify its daemon PID and bind that incarnation.

### Other members

- [`attach-async`](/en/raku/latest/reference/libtmux-server-attach-async/) (method): Resolve a separately owned terminal client; process creation is not attachment proof.
- [`capabilities-async`](/en/raku/latest/reference/libtmux-server-capabilities-async/) (method): Resolve to one fresh immutable daemon capability observation.
- [`clone`](/en/raku/latest/reference/libtmux-server-clone/) (method): Refuse cloning of runtime admission and daemon ownership state.
- [`close`](/en/raku/latest/reference/libtmux-server-close/) (method): Join idempotent shutdown; borrowed daemons remain running.
- [`close-async`](/en/raku/latest/reference/libtmux-server-close-async/) (method): Join admitted work; owned servers additionally terminate and reap their original daemon.
- [`command-async`](/en/raku/latest/reference/libtmux-server-command-async/) (method): Copy input before scheduling one guarded command; retain exit status and raw streams.
- [`endpoint`](/en/raku/latest/reference/libtmux-server-endpoint/) (property): Captured connection settings; retaining them owns no process.
- [`environment`](/en/raku/latest/reference/libtmux-server-environment/) (method): Observe daemon identity and return its global environment facade.
- [`environment-pane-id`](/en/raku/latest/reference/libtmux-server-environment-pane-id/) (property): Pane ID explicitly imported from TMUX_PANE; undefined for ordinary construction.
- [`environment-session-id`](/en/raku/latest/reference/libtmux-server-environment-session-id/) (property): Session ID explicitly imported from TMUX; undefined when tmux supplied -1.
- [`explain`](/en/raku/latest/reference/libtmux-server-explain/) (method): Observe capabilities and explain an explicit source query without executing its listing.
- [`explain-panes`](/en/raku/latest/reference/libtmux-server-explain-panes/) (method): Explain pane acquisition, pushed restrictions and residual local work.
- [`hooks`](/en/raku/latest/reference/libtmux-server-hooks/) (method): Observe daemon identity and return global session/window hooks.
- [`key-bindings`](/en/raku/latest/reference/libtmux-server-key-bindings/) (method): Observe daemon identity and return its key-binding facade.
- [`max-command-bytes`](/en/raku/latest/reference/libtmux-server-max-command-bytes/) (property): Maximum encoded command size in bytes, including tmux quoting.
- [`max-output-bytes`](/en/raku/latest/reference/libtmux-server-max-output-bytes/) (property): Combined output-byte limit for one owned command response.
- [`new`](/en/raku/latest/reference/libtmux-server-new/) (method): Capture a borrowed endpoint without I/O. Closing it closes clients only.
- [`open-control`](/en/raku/latest/reference/libtmux-server-open-control/) (method): Open a separately owned control connection attached to an explicit session ID.
- [`open-control-async`](/en/raku/latest/reference/libtmux-server-open-control-async/) (method): Resolve a separately owned verified control connection; the caller must close it.
- [`options`](/en/raku/latest/reference/libtmux-server-options/) (method): Observe daemon identity and return server options or global session/window defaults.
- [`owned`](/en/raku/latest/reference/libtmux-server-owned/) (method): Whether this facade owns the foreground daemon it started.
- [`query`](/en/raku/latest/reference/libtmux-server-query/) (method): Acquire a typed selection; only requested relationship predicates load the full graph.
- [`query-async`](/en/raku/latest/reference/libtmux-server-query-async/) (method): Copy and validate query data before scheduling acquisition within one shared deadline.
- [`query-panes`](/en/raku/latest/reference/libtmux-server-query-panes/) (method): Acquire panes explicitly; the resulting selection is local and replayable.
- [`query-sessions`](/en/raku/latest/reference/libtmux-server-query-sessions/) (method): Acquire sessions explicitly under the selected pushdown policy.
- [`query-window-links`](/en/raku/latest/reference/libtmux-server-query-window-links/) (method): Acquire session/index associations without deduplicating repeated window placements.
- [`query-windows`](/en/raku/latest/reference/libtmux-server-query-windows/) (method): Acquire unique physical windows, preserving link context separately.
- [`run-batch-async`](/en/raku/latest/reference/libtmux-server-run-batch-async/) (method): Resolve per-operation outcomes with one deadline spanning observation and dispatch.
- [`run-shell-async`](/en/raku/latest/reference/libtmux-server-run-shell-async/) (method): Resolve the bounded tmux job request; cancellation does not undo a server-side job.
- [`snapshot-async`](/en/raku/latest/reference/libtmux-server-snapshot-async/) (method): Resolve a fresh captured graph; cancellation propagates through every acquisition stage.
- [`wait-for-async`](/en/raku/latest/reference/libtmux-server-wait-for-async/) (method): Resolve one channel operation within the Server deadline, without readiness polling.

## In other ports

A tmux server

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Server`](/en/py/latest/reference/libtmux-server/) (class) |
| Ruby | [`LibTmux::Server`](/en/ruby/latest/reference/libtmux-server/) (class) |
| Lua | [`libtmux.Server`](/en/lua/latest/reference/libtmux-server/) (class) |
| PowerShell | [`LibTmux\New-TmuxServer`](/en/powershell/latest/reference/libtmux-new-tmuxserver/) (cmdlet). This cmdlet constructs a shared .NET `LibTmux.Server` handle without contacting tmux. |
| Julia | [`LibTmux.Server`](/en/julia/latest/reference/libtmux-server/) (struct). `Server` describes an endpoint without contacting tmux. Read its hierarchy with `snapshot`. |
| Erlang | [`tmux_server`](/en/erlang/latest/reference/tmux_server/) (module). `open/1` observes an existing daemon and starts an endpoint owner. Domain rows remain immutable values. |
| Elixir | [`LibTmux.Server`](/en/elixir/latest/reference/libtmux-server/) (struct). `Server` describes an existing server by executable and socket. It neither connects nor reserves the server’s identity. |
| Haskell | [`LibTmux.Server`](/en/haskell/latest/reference/libtmux-server/) (module). `LibTmux.Server` owns the `Server` handle. `withServer` adopts an existing socket for the length of a callback and releases its own resources afterwards without sending `kill-server`. Operations such as `capture` and `renameSession` are functions of this module that take the handle. |
| Common Lisp | [`libtmux:client`](/en/lisp/latest/reference/libtmux-client/) (class). `client` is a connection scope with one external-operation lease. Closing it cancels owned work and leaves the tmux daemon alive; `daemon` owns a daemon the library started. |
| TypeScript | [`server.Server`](/en/ts/latest/reference/server-server/) (class) |
| Rust | [`server.Server`](/en/rs/latest/reference/server-server/) (struct) |
| Go | [`tmux.Server`](/en/go/latest/reference/tmux-server/) (struct) |
| Java | [`io.github.libtmux.Server`](/en/java/latest/reference/io-github-libtmux-server-server/) (class) |
| Clojure | [`libtmux.core/open!`](/en/clojure/latest/reference/libtmux-core-open/) (function). Opens a closeable Java server client for an explicit endpoint. Acquisitions return persistent maps with explicit Java references for effects. |
| Kotlin | [`io.github.libtmux.kotlin.Server`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-server/) (class) |
| Scala | [`io.github.libtmux.scaladsl.Server`](/en/scala/latest/reference/io-github-libtmux-scaladsl-server/) (typealias) |
| C# | [`LibTmux.Server`](/en/csharp/latest/reference/libtmux-server/) (class) |
| F# | [`LibTmux.FSharp.Server`](/en/fsharp/latest/reference/libtmux-fsharp-server/) (module). This F# module provides functions over the shared .NET `LibTmux.Server` type. |
| C++ | [`libtmux::Server`](/en/cxx/latest/reference/libtmux-server/) (class) |
| Swift | [`Server`](/en/swift/latest/reference/server/) (struct) |
| OCaml | [`Libtmux_unix.Client.t`](/en/ocaml/latest/reference/libtmux_unix-client-t/) (typealias). A client is a live, generation-bound server connection. Endpoint describes a socket without connecting; closing a client releases its resources. |
| Perl | [`LibTmux::Server`](/en/perl/latest/reference/libtmux-server/) (class). Construction records connection settings without tmux I/O. Optional LibTmux::Async::Server returns standard Future results for operations. |
