Server
Manages sessions, windows, and panes on a tmux server.
Source and package
- Qualified name
-
io.github .libtmux .kotlin. Server - Package
- io.github.libtmux.kotlin
- Distribution
- io.github.libtmux:libtmux-kotlin
- Source
- libtmux-kotlin/src/main/kotlin/io/github/libtmux/kotlin/Server.kt
- public class Server : Auto
Closeable -
Description
Use
openwith aServerConfigto select a server by socket name or path. From this object, create sessions or query the server's existing sessions, windows, and panes. EachSessioncontains windows, and eachWindowcontains panes.Operations that contact tmux are
suspendfunctions dispatched throughpolicy. Callcloseafter the last operation to release resources owned by this object. The tmux server and its sessions keep running.asJavaexposes the underlyingJavaServerfor interoperability. Both objects share the same resources, so closing either closes both.What is on here
A tmux server does a great many things, so this class has a great many members. They fall into a few groups:
- Connecting
openmakes a server over a transport it owns,withServerdoes so for the length of a block and closes it however the block ends, andfromJavawraps a server opened in Java.configsays how it was configured,identitywhich server it is, andversionwhich tmux.isAliveandrequireAliveanswer whether anything is listening.admissionBoundsays how many commands run at once, andpolicydecides how thesuspendfunctions are dispatched.controlattaches a control client, whose output and events arrive as coldFlows, andwithControlscopes one to a block.closereleases what the server owns.- Finding one thing
- Given a filter,
session,window, andpanethrow unless exactly one object matches, andsessionOrNull,windowOrNull, andpaneOrNullreturn null when none does; several matches throw either way.sessionby name orSessionId,panebyPaneId, andwindowbyWindowContextreturn null when tmux does not have it.hasSessionanswers by name without returning the session. - Listing everything
sessions,windows,panes,clients, andattachedSessionseach return aListcaptured now. A failed read throws, so an outage does not read as an empty server.windowsalso takes aWindowIdand answers every link to that window.snapshotcaptures the whole tree with one listing per kind of object rather than one command per object, andliveStatepublishes it again as aStateFlowwhenever tmux announces a change;withLiveStatescopes that to a block.- Querying things and getting around
- Hand
sessions,windows,panes,session,window, orpanea filter built from the field properties on the handle companions, such asPane.command startsWith "nvim", and tmux does the filtering when it can. To move between levels, go down withSession.windowsandWindow.panes, up withPane.windowandWindow.session, and across to the focused child withSession.activeWindowandWindow.activePane. Each is a pure read of the capture, so none suspends or asks tmux again. - Changing things
newSessioncreates a detached session from a name, aSessionSpec, or a builder block, and returns the session tmux made.killSessionends a session by name,killServerends the tmux server and every session on it, whichclosedeliberately does not, andlocklocks every attached client.- Options and hooks
optionsholds the server-wide options,globalOptionsthe session options every session inherits unless it sets its own,hooksthe global hooks, andenvironmentthe variables every new process is given. Each returns a wrapper whose own operations aresuspend.- Everything else tmux keeps
- Paste buffers (
buffers), key bindings (keys), a file of tmux commands to run (sourceFile), shell commands (shell), the command list (commands), the message log (messageLog), prompt history (prompt), and wait-for channels (channel).expandexpands a format against the server,variablesreads named variables in one expansion, andpaneFieldsreads chosen fields of every pane from one listing.
Examples
Connect to a private tmux server. Use JDK 25, Gradle 9 or newer, and tmux 3.3a or newer on Linux, with
/bin/catand/bin/shavailable. In an empty directory, save this consumer setup assettings.gradle.kts:rootProject.name = "api-example"Save this consumer setup as
build.gradle.kts. It depends on the 0.1.2 release from Maven Central:plugins {kotlin("jvm") version "2.4.10"application}repositories { mavenCentral() }dependencies {implementation("io.github.libtmux:libtmux-kotlin:0.1.2")}java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }kotlin { jvmToolchain(25) }application { mainClass.set(providers.gradleProperty("exampleMain")) }Save this consumer setup as
gradle.properties: View sourcegradle.properties org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8kotlin.daemon.jvmargs=-Xmx2gorg.gradle.workers.max=2Save this complete program as
src/main/kotlin/Connect.kt. It starts a private tmux server of its own and stops it when the program closes it. View sourcesrc/main/kotlin/Connect.ktComplete program package io.github.libtmux.examples.api.kotlinimport io.github.libtmux.kotlin.*import kotlin.system.exitProcessimport kotlinx.coroutines.runBlocking/** Connect to a private tmux server. */fun main() {try {runBlocking {withPrivateServer { server ->println("connected=${server.isAlive()}")}}} catch (error: Exception) {if (error is InterruptedException) Thread.currentThread().interrupt()System.err.println("Example failed: ${error.message}")exitProcess(1)}}Build the minimal consumer with Gradle and run the saved program. An operation or cleanup error makes the command exit unsuccessfully:
Terminal window $ gradle --console=plain --quiet installDist -PexampleMain=io.github.libtmux.examples.api.kotlin.ConnectKt && \build/install/api-example/bin/api-exampleExpected output:
connected=true
Members51 members
Collections and queries6
- sessions method Every session, captured now.
- windows method Captures every winlink, preserving each session and index placement.
- panes method Captures every pane on the server.
- clients method Captures every attached client.
- buffers method The server's paste buffers, which every session shares.
- snapshot method Captures the whole hierarchy in at most four listings, retrying once if the server is replaced.
Common operations15
- newSession method Creates a detached session and returns that exact session.
- killServer method Ends the tmux server and every session on it.
- liveState method A live, continuously rebuilt view of
server, as aStateFlow. - batch method Collects several commands to run in one tmux invocation.
- chain method Starts a chain of commands where each one acts on what the last one made.
- channel method One of this server's wait-for channels, which is where a signal is sent and waited for.
- commands method The commands this tmux knows.
- hooks method The global hooks every session inherits.
- keys method The server's key bindings:
prefixwhen binding, every table when listing. - messageLog method The server's message log.
- prompt method The command prompt's history.
- session method The one session this expression matches, captured now.
- sessionOrNull method The one session this expression matches, or null when none does.
- shell method Shell commands run by tmux, and tmux commands chosen by a shell exit status.
- withLiveState method As
liveState, scoped toblock: opens the live view, runsblockagainst it, and cancels the background pump before returning — the samewithServer/withControlshape, for the one resourceliveStateitself cannot close on its own.
Other members30
- admissionBound property How many tmux commands this server's transport runs at once, from
ExecutionPolicy.default. - asJava property The Java server this wraps, for an operation this class does not mirror or a Java API that takes one. The same object, not a copy: closing either closes both.
- attachedSessions method Captures every session a client is attached to.
- captureServer method Captures metadata and entity handles from one observed hierarchy.
- close method Releases an owned transport. Idempotent, and never kills tmux, except on a server from
start, whose close ends the tmux server it owns. - cmd method Runs one tmux command against this server.
- Companion module
- config property How this server was configured.
- control method Attaches a control client to this session's server, and only to the process this capture named.
- environment method The server's environment, which every session inherits and every new process is given.
- expand method Expands a tmux format against the server, and answers with what it came to.
- globalOptions method The global session options every session inherits unless it sets its own.
- hasSession method Whether a session with this name exists.
- identity property Which server this is. Every handle taken from it is scoped by this.
- isAlive method Whether the server is running and answering.
- killSession method Ends the session with this name, and everything in it.
- lock method Locks every client attached to this server.
- options method The server-wide options, the ones tmux keeps once per server.
- pane method The one pane this expression matches, captured now.
- paneFields method Chosen fields for every pane on the server, from one listing.
- paneOrNull method The one pane this expression matches, or null when none does.
- policy property
- requireAlive method Requires a running tmux daemon that answers the liveness probe.
- requireCompatibleTmux method Requires a compatible daemon, or a compatible executable when this endpoint is unused.
- run method Runs a command that is expected to work, and raises when it did not.
- sourceFile method Runs a file of tmux commands, as a configuration file would be run.
- variables method Reads only validated tmux variable names, never caller-authored format syntax.
- version method Which tmux this server is running.
- window method The one window link this expression matches, captured now.
- windowOrNull method The one window link this expression matches, or null when none does.
No members of Server match . The filter searches only this type. Search the whole API.
Order: the accessors that walk the hierarchy, the operations the ports share, then the rest.
Guides
task materialPages that discuss Server.
- Concepts
In other ports
task equivalence 22 other ports mappedSource-verified mappings for A tmux server. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.
| Port | API | Differs from Kotlin |
|---|---|---|
| Kotlin | io Manages sessions, windows, and panes on a tmux server. | This page |
| Python | libtmux tmux(1) Server [server_manual]. | None recorded in the model |
| Ruby | Lib Connects to an existing endpoint. Closing retires clients, never the daemon. | None recorded in the model |
| Lua | libtmux | None recorded in the model |
| PowerShell | Lib Construct a tmux endpoint handle without contacting it. | 2 overloads This cmdlet constructs a shared .NET LibTmux.Server handle without contacting tmux. |
| Julia | Lib Describe a tmux endpoint without contacting it. Supply exactly one socket selector. A description does not own a daemon or any sessions. Use from_env to opt into the ambient tmux endpoint. | |
| Erlang | tmux Open tmux endpoints and execute explicit command values. | open/1 observes an existing daemon and starts an endpoint owner. Domain rows remain immutable values. |
| Elixir | Lib An explicit local tmux server descriptor. | Server describes an existing server by executable and socket. It neither connects nor reserves the server’s identity. |
| Haskell | Lib Start, observe and change a tmux daemon through a scoped handle. | LibTmux.Server owns the Server handle. withOwnedServer starts and retires a private daemon; withServer borrows an existing endpoint and releases its own resources afterwards. killServer retires the admitted daemon generation explicitly. Operations such as capture and renameSession are functions of this module that take the handle. |
| Common Lisp | libtmux: A connection scope with one external-operation lease.
Closing cancels owned work and leaves the tmux daemon alive. Captured data may
outlive the client. Public operations never expose its mutable storage. | |
| TypeScript | server One tmux server, addressed by the socket it listens on. | None recorded in the model |
| Rust | server A cloneable handle to one captured tmux server endpoint. | None recorded in the model |
| Go | tmux Server is an immutable handle to one tmux configuration. Its zero value is invalid. Copying a configured Server preserves its configuration and shares its mutex-guarded version cache and checked daemon identity, so a Server and the values derived from it are safe for concurrent method calls (see the package documentation). | None recorded in the model |
| Java | io Manages sessions, windows, and panes on a tmux server. | readonly |
| Clojure | libtmux Opens local resources for an explicit :socket-path or :socket-name endpoint. | Opens a closeable Java server client for an explicit endpoint. Acquisitions return persistent maps with explicit Java references for effects. |
| Scala | io The Java client, opaque: every member beyond java.lang.AutoCloseable#close is an extension, generated from the operation catalog or handwritten where the catalog marks it WAIT, STREAM or LIFECYCLE. Closing an owned client releases its transport, not tmux; close() comes from the AutoCloseable bound with no forwarding of its own, so Using.resource(server) { ... } works. | 2 overloads |
| C# | Lib Represents an immutable server handle and snapshot. | None recorded in the model |
| F# | Lib Starts server reads and queries with the caller's cancellation token. | This F# module provides functions over the shared .NET LibTmux.Server type. |
| C++ | libtmux:: One tmux server, addressed by the socket it listens on. | None recorded in the model |
| Swift | Server A tmux server, addressed by its endpoint. | None recorded in the model |
| OCaml | Libtmux An explicit generation-bound connection. Applications retain ownership of the endpoint choice and resource lifetime. | A client is a live, generation-bound server connection. Endpoint describes a socket without connecting; closing a client releases its resources. |
| Perl | Lib Explicit tmux acquisition and commands | Construction records connection settings without tmux I/O. Optional LibTmux::Async::Server returns standard Future results for operations. |
| Raku | Lib | None recorded in the model |