JavaHome

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

libtmux for Java

Java-based tmux client

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

Product
Example details
import io.github.libtmux.Server;
import io.github.libtmux.ServerConfig;
import io.github.libtmux.ServerEndpoint;
import io.github.libtmux.TextOutcome;
import java.nio.file.Path;
import java.time.Duration;
import java.util.UUID;
public final class Main {
public static void main(String[] args) throws Exception {
var socket = "libtmux-home-" + UUID.randomUUID();
var config = ServerConfig.builder()
.endpoint(ServerEndpoint.namedSocket(socket))
.configFile(Path.of("/dev/null"))
.defaultTimeout(Duration.ofSeconds(5))
.build();
try (Server server = Server.open(config)) {
var session = server.newSession("demo");
// Lay out the session: name its window, split it, add another.
var first = session.activeWindow().orElseThrow();
var editor = first.rename("editor");
var left = editor.activePane().orElseThrow();
var right = left.split(spec -> spec.toRight().detached());
var logs = session.newWindow(
spec -> spec.named("logs").detached());
// Type a command into the new pane and wait for what it prints.
right.sendLine("printf 'hello from %s\\n' tmux");
var seen = right.awaitText(
"hello from tmux", Duration.ofSeconds(5));
if (seen == TextOutcome.TIMED_OUT) {
throw new IllegalStateException("output did not arrive");
}
// Move the focus an attached client sees: pane, then window.
right.select();
logs.select();
// Walk the objects: down from the server, up from one pane.
var snapshot = server.snapshot();
var sessions = snapshot.sessions();
for (var each : sessions) {
System.out.println("session " + each.name());
var windows = snapshot.windowsOf(each.id());
for (var win : windows) {
var index = win.context().index();
System.out.printf(" window %s:%s:", index, win.name());
var panes = snapshot.panesOf(win.context());
for (var pane : panes) {
System.out.print(" " + pane.id());
}
System.out.println();
}
}
var window = right.window();
var owner = window.session();
System.out.println(
right.id() + " is in window " + window.name()
+ " of session " + owner.name());
}
}
}
import io.github.libtmux.Server;
import io.github.libtmux.ServerConfig;
import io.github.libtmux.ServerEndpoint;
import io.github.libtmux.TextOutcome;
import java.nio.file.Path;
import java.time.Duration;
import java.util.UUID;
public final class Main {
public static void main(String[] args) throws Exception {
var socket = "libtmux-home-" + UUID.randomUUID();
var config = ServerConfig.builder()
.endpoint(ServerEndpoint.namedSocket(socket))
.configFile(Path.of("/dev/null"))
.defaultTimeout(Duration.ofSeconds(5))
.build();
try (Server server = Server.open(config)) {
try {
var session = server.newSession("demo");
// Lay out the session: name its window, split it, add another.
var first = session.activeWindow().orElseThrow();
var editor = first.rename("editor");
var left = editor.activePane().orElseThrow();
var right = left.split(spec -> spec.toRight().detached());
var logs = session.newWindow(
spec -> spec.named("logs").detached());
// Type a command into the new pane and wait for what it prints.
right.sendLine("printf 'hello from %s\\n' tmux");
var seen = right.awaitText(
"hello from tmux", Duration.ofSeconds(5));
if (seen == TextOutcome.TIMED_OUT) {
throw new IllegalStateException("output did not arrive");
}
// Move the focus an attached client sees: pane, then window.
right.select();
logs.select();
// Walk the objects: down from the server, up from one pane.
var snapshot = server.snapshot();
var sessions = snapshot.sessions();
for (var each : sessions) {
System.out.println("session " + each.name());
var windows = snapshot.windowsOf(each.id());
for (var win : windows) {
var index = win.context().index();
System.out.printf(" window %s:%s:", index, win.name());
var panes = snapshot.panesOf(win.context());
for (var pane : panes) {
System.out.print(" " + pane.id());
}
System.out.println();
}
}
var window = right.window();
var owner = window.session();
System.out.println(
right.id() + " is in window " + window.name()
+ " of session " + owner.name());
} catch (Exception error) {
throw new IllegalStateException(
"tmux quickstart failed", error);
}
}
}
}
import io.github.libtmux.Server;
import io.github.libtmux.ServerConfig;
import io.github.libtmux.ServerEndpoint;
import io.github.libtmux.TextOutcome;
import java.nio.file.Path;
import java.time.Duration;
import java.util.UUID;
public final class Main {
public static void main(String[] args) throws Exception {
var socket = "libtmux-home-" + UUID.randomUUID();
var config = ServerConfig.builder()
.endpoint(ServerEndpoint.namedSocket(socket))
.configFile(Path.of("/dev/null"))
.defaultTimeout(Duration.ofSeconds(5))
.build();
try (Server server = Server.open(config)) {
try {
var session = server.newSession("demo");
// Lay out the session: name its window, split it, add another.
var first = session.activeWindow().orElseThrow();
var editor = first.rename("editor");
var left = editor.activePane().orElseThrow();
var right = left.split(spec -> spec.toRight().detached());
var logs = session.newWindow(
spec -> spec.named("logs").detached());
// Type a command into the new pane and wait for what it prints.
right.sendLine("printf 'hello from %s\\n' tmux");
var seen = right.awaitText(
"hello from tmux", Duration.ofSeconds(5));
if (seen == TextOutcome.TIMED_OUT) {
throw new IllegalStateException("output did not arrive");
}
// Move the focus an attached client sees: pane, then window.
right.select();
logs.select();
// Walk the objects: down from the server, up from one pane.
var snapshot = server.snapshot();
var sessions = snapshot.sessions();
for (var each : sessions) {
System.out.println("session " + each.name());
var windows = snapshot.windowsOf(each.id());
for (var win : windows) {
var index = win.context().index();
System.out.printf(" window %s:%s:", index, win.name());
var panes = snapshot.panesOf(win.context());
for (var pane : panes) {
System.out.print(" " + pane.id());
}
System.out.println();
}
}
var window = right.window();
var owner = window.session();
System.out.println(
right.id() + " is in window " + window.name()
+ " of session " + owner.name());
} finally {
server.killServer();
}
}
}
}
import io.github.libtmux.Server;
import io.github.libtmux.ServerConfig;
import io.github.libtmux.ServerEndpoint;
import io.github.libtmux.TextOutcome;
import java.nio.file.Path;
import java.time.Duration;
import java.util.UUID;
public final class Main {
public static void main(String[] args) throws Exception {
var socket = "libtmux-home-" + UUID.randomUUID();
var config = ServerConfig.builder()
.endpoint(ServerEndpoint.namedSocket(socket))
.configFile(Path.of("/dev/null"))
.defaultTimeout(Duration.ofSeconds(5))
.build();
try (Server server = Server.open(config)) {
try {
var session = server.newSession("demo");
// Lay out the session: name its window, split it, add another.
var first = session.activeWindow().orElseThrow();
var editor = first.rename("editor");
var left = editor.activePane().orElseThrow();
var right = left.split(spec -> spec.toRight().detached());
var logs = session.newWindow(
spec -> spec.named("logs").detached());
// Type a command into the new pane and wait for what it prints.
right.sendLine("printf 'hello from %s\\n' tmux");
var seen = right.awaitText(
"hello from tmux", Duration.ofSeconds(5));
if (seen == TextOutcome.TIMED_OUT) {
throw new IllegalStateException("output did not arrive");
}
// Move the focus an attached client sees: pane, then window.
right.select();
logs.select();
// Walk the objects: down from the server, up from one pane.
var snapshot = server.snapshot();
var sessions = snapshot.sessions();
for (var each : sessions) {
System.out.println("session " + each.name());
var windows = snapshot.windowsOf(each.id());
for (var win : windows) {
var index = win.context().index();
System.out.printf(" window %s:%s:", index, win.name());
var panes = snapshot.panesOf(win.context());
for (var pane : panes) {
System.out.print(" " + pane.id());
}
System.out.println();
}
}
var window = right.window();
var owner = window.session();
System.out.println(
right.id() + " is in window " + window.name()
+ " of session " + owner.name());
} catch (Exception error) {
throw new IllegalStateException(
"tmux quickstart failed", error);
} finally {
server.killServer();
}
}
}
}
No tmux server yet

tmux before the first call: no server is running.

No tmux server yet

tmux after Server.open: no server is running; the call sent no command.

%0 sh
[demo]

tmux after Server.newSession: added session demo.

%0 sh
[demo]

tmux after Session.activeWindow: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Window.rename: renamed window 0:sh to 0:editor.

%0 sh
[demo]

tmux after Window.activePane: unchanged, the call sent no command.

%0 sh
%1 sh
[demo]

tmux after Pane.split: added pane %1 to window 0:editor.

%0 sh
%1 sh
[demo]

tmux after Session.newWindow: added window 1:logs.

%0 sh
%1 sh
[demo]

tmux after Pane.sendLine: sent keys to pane %1.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Pane.awaitText: read pane %1.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Pane.select: selected pane %1 in window 0:editor.

%2 sh
[demo]

tmux after Window.select: selected window 1:logs.

%2 sh
[demo]

tmux after Server.snapshot: unchanged.

%2 sh
[demo]

tmux after ServerSnapshot.sessions: unchanged, the call sent no command.

%2 sh
[demo]

tmux after ServerSnapshot.windowsOf: unchanged, the call sent no command.

%2 sh
[demo]

tmux after ServerSnapshot.panesOf: unchanged, the call sent no command.

%2 sh
[demo]

tmux after ServerSnapshot.panesOf: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Pane.window: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Window.session: unchanged, the call sent no command.

No sessions

tmux after Server.killServer: the server has exited.

Before the first call

No tmux server is running yet.

Server.open returned Server

{
"configFile": "/dev/null",
"endpoint": "named socket"
}

The call sent no tmux command.

Server.newSession returned Session

{
"id": "$0",
"name": "demo"
}
2 tmux commands, 1 that changes tmux
  1. new-session -d -s demo -P -F #{session_id} $0
  2. list-sessions -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{session_name}57eb126467cffa8294689a1050a5c2c5#{session_attached}57eb126467cffa8294689a1050a5c2c5#{session_windows}0fc557c03bd011c37bdc9ee411899f33 ; display-message -p 57eb126467cffa8294689a1050a5c2c5:0 ; list-windows -a -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}57eb1264… $057eb126467cffa8294689a1050a5c2c5demo57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c510fc557c03bd011c37bdc9ee411899f33 57eb126467cffa8294689a1050a5c2c5:0 $057eb126467cffa8294689a1050a5c2c5@057eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5sh57eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050…

Before these, the library asked tmux about itself 4 times (its version, its daemon, how a control client reads escapes).

Session.activeWindow returned Optional<Window>

{
"id": "@0",
"name": "sh"
}

The call sent no tmux command.

Window.rename returned Window

{
"id": "@0",
"name": "editor"
}
2 tmux commands, 1 that changes tmux
  1. rename-window -t @0 -- editor no output
  2. list-sessions -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{session_name}57eb126467cffa8294689a1050a5c2c5#{session_attached}57eb126467cffa8294689a1050a5c2c5#{session_windows}0fc557c03bd011c37bdc9ee411899f33 ; display-message -p 57eb126467cffa8294689a1050a5c2c5:0 ; list-windows -a -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}57eb1264… $057eb126467cffa8294689a1050a5c2c5demo57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c510fc557c03bd011c37bdc9ee411899f33 57eb126467cffa8294689a1050a5c2c5:0 $057eb126467cffa8294689a1050a5c2c5@057eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5editor57eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a…

Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

Window.activePane returned Optional<Pane>

{
"id": "%0"
}

The call sent no tmux command.

Pane.split returned Pane

{
"id": "%1"
}
2 tmux commands, 1 that changes tmux
  1. split-window -h -d -t %0 -P -F #{pane_id}0fc557c03bd011c37bdc9ee411899f33 %10fc557c03bd011c37bdc9ee411899f33
  2. list-sessions -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{session_name}57eb126467cffa8294689a1050a5c2c5#{session_attached}57eb126467cffa8294689a1050a5c2c5#{session_windows}0fc557c03bd011c37bdc9ee411899f33 ; display-message -p 57eb126467cffa8294689a1050a5c2c5:0 ; list-windows -a -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}57eb1264… $057eb126467cffa8294689a1050a5c2c5demo57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c510fc557c03bd011c37bdc9ee411899f33 57eb126467cffa8294689a1050a5c2c5:0 $057eb126467cffa8294689a1050a5c2c5@057eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5editor57eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5257eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a…

Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

Session.newWindow returned Window

{
"id": "@1",
"name": "logs"
}
2 tmux commands, 1 that changes tmux
  1. new-window -d -n logs -t $0 -P -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}0fc557c03bd011c37bdc9ee411899f33 $057eb126467cffa8294689a1050a5c2c5@157eb126467cffa8294689a1050a5c2c510fc557c03bd011c37bdc9ee411899f33
  2. list-sessions -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{session_name}57eb126467cffa8294689a1050a5c2c5#{session_attached}57eb126467cffa8294689a1050a5c2c5#{session_windows}0fc557c03bd011c37bdc9ee411899f33 ; display-message -p 57eb126467cffa8294689a1050a5c2c5:0 ; list-windows -a -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}57eb1264… $057eb126467cffa8294689a1050a5c2c5demo57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c520fc557c03bd011c37bdc9ee411899f33 57eb126467cffa8294689a1050a5c2c5:0 $057eb126467cffa8294689a1050a5c2c5@057eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5editor57eb126467cffa8294689a1050a5c2c5157eb126467cffa8294689a1050a5c2c5257eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a…

Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

Pane.sendLine returned void

null
2 tmux commands, 1 that changes tmux
  1. display-message -p -t %1 -- #{version}0000-version#{pane_synchronized}57eb126467cffa8294689a1050a5c2c5-end 3.8a57eb126467cffa8294689a1050a5c2c5-version057eb126467cffa8294689a1050a5c2c5-end
  2. send-keys -l -t %1 -- 'printf '\''hello from %s\n'\'' tmux\r' no output

Pane.awaitText returned TextOutcome

"PRESENT_AT_ENTRY"
1 tmux command
  1. capture-pane -p -J -t %1 $ printf 'hello from %s\n' tmux hello from tmux $

Pane.select returned void

null
1 tmux command, 1 that changes tmux
  1. select-pane -t %1 no output

Window.select returned void

null
1 tmux command, 1 that changes tmux
  1. select-window -t $0:1 no output

Server.snapshot returned ServerSnapshot

{
"sessions": 1,
"windows": 2,
"panes": 3
}
1 tmux command
  1. list-sessions -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{session_name}57eb126467cffa8294689a1050a5c2c5#{session_attached}57eb126467cffa8294689a1050a5c2c5#{session_windows}0fc557c03bd011c37bdc9ee411899f33 ; display-message -p 57eb126467cffa8294689a1050a5c2c5:0 ; list-windows -a -F #{session_id}57eb126467cffa8294689a1050a5c2c5#{window_id}57eb126467cffa8294689a1050a5c2c5#{window_index}57eb1264… $057eb126467cffa8294689a1050a5c2c5demo57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c520fc557c03bd011c37bdc9ee411899f33 57eb126467cffa8294689a1050a5c2c5:0 $057eb126467cffa8294689a1050a5c2c5@057eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5editor57eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a1050a5c2c5257eb126467cffa8294689a1050a5c2c5057eb126467cffa8294689a…

Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

ServerSnapshot.sessions returned List<SessionState>

[
"$0"
]

The call sent no tmux command.

ServerSnapshot.windowsOf returned List<WindowState>

[
"@0",
"@1"
]

The call sent no tmux command.

ServerSnapshot.panesOf returned List<PaneState>

[
"%0",
"%1"
]

The call sent no tmux command.

ServerSnapshot.panesOf returned List<PaneState>

[
"%2"
]

The call sent no tmux command.

Pane.window returned Window

{
"id": "@0",
"name": "editor"
}

The call sent no tmux command.

Window.session returned Session

{
"id": "$0",
"name": "demo"
}

The call sent no tmux command.

Server.killServer returned void

null
1 tmux command, 1 that changes tmux
  1. display-message -p #{pid} ; kill-server 3081433
Run this example

JDK 25 and tmux on Linux/macOS

Save the program above as src/main/java/Main.java in a new directory, along with the files below.

Cleanup is omitted; the private tmux server and its temporary files may remain. Select Cleanup to remove them when the program finishes. The program stops its private tmux server and removes any temporary files it created when it finishes. Error handling adds diagnostics; every version checks required results and deadlines.

build.gradle.kts
plugins {
application
}
repositories { mavenCentral() }
dependencies {
implementation("io.github.libtmux:libtmux:0.1.2")
}
java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }
application { mainClass.set(providers.gradleProperty("exampleMain")) }
settings.gradle.kts
rootProject.name = "api-example"
gradle.properties
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8
kotlin.daemon.jvmargs=-Xmx2g
org.gradle.workers.max=2

Setup and run

# Save the files above at their displayed relative paths.
git clone https://github.com/libtmux/libtmux-java.git libtmux-source
git -C libtmux-source checkout --detach e8a39689d8d60968ac978a1dd2a89c6112333896
./libtmux-source/gradlew --project-dir . --console=plain --no-daemon --max-workers=2 \
installDist -PexampleMain=Main
SHELL=/bin/sh build/install/api-example/bin/api-example

Expected output

session demo
window 0:editor: %0 %1
window 1:logs: %2
%1 is in window editor of session demo

Library revision: e8a39689d8d6.

APIs used

Install io.github.libtmux:libtmux

dependencies {
    implementation(platform("io.github.libtmux:libtmux-bom:0.1.0"))

    implementation("io.github.libtmux:libtmux")
    testImplementation("io.github.libtmux:libtmux-junit5")
}

The platform BOM names the version once and every other coordinate follows it, which is what stops a project mixing two releases of modules built against each other.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.github.libtmux</groupId>
      <artifactId>libtmux-bom</artifactId>
      <version>0.1.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependency>
  <groupId>io.github.libtmux</groupId>
  <artifactId>libtmux</artifactId>
</dependency>

MCP

Worked example

No sessions

tmux after kill_session.

you

Create a tmux session called checks, split its window into two panes, run pytest -q in one and show checks.log in the other, show me the results, then remove the session.

agentCreate the session.

create_session Execute {"session_name":"checks"}
Result
{
"id": "$0",
"name": "checks",
"attached": false,
"windows": 1
}

agentList the panes, each with the session it belongs to.

list_panes Inspect {}
Result
{
"count": 1,
"panes": [
{
"id": "%0",
"session": "checks",
"window": "sh",
"window_id": "@0",
"command": "sh",
"path": "/home/user/project",
"size": "80x24",
"active": true
}
]
}

agentSplit the pane the list returned (%0) in two.

split_window Execute {"pane_id":"%0","direction":"right"}
Result
{
"id": "%1",
"index": 1,
"window_id": "@0",
"session_id": "$0",
"active": true,
"command": "sh",
"path": "/home/user/project",
"title": "host",
"size": "40x24"
}

agentRead the window's layout through the pane the list returned (%0).

get_tmux_variables Inspect {"names":["window_layout"],"pane":"%0"}
Result
{
"values": {
"window_layout": "{\"V\":2,\"L\":{\"t\":\"h\",\"w\":80,\"h\":24,\"x\":0,\"y\":0,\"c\":[{\"t\":\"p\",\"w\":39,\"h\":24,\"x\":0,\"y\":0,\"l\":0,\"i\":0,\"I\":\"%0\"},{\"t\":\"p\",\"w\":40,\"h\":24,\"x\":40,\"y\":0,\"a\":true,\"i\":1,\"I\":\"%1\"}]}}"
}
}

agentRun the tests in the pane the list returned (%0).

run_shell_command Execute {"pane_id":"%0","command":"pytest -q"}
Result
{
"pane_id": "%0",
"outcome": "SIGNALLED",
"exit_status": 0,
"output": [
"..",
" [100%",
"]",
"2 passed in 0.00s"
],
"truncated": false,
"lines_dropped": 0,
"framed": true,
"seconds": 0.29,
"effective_timeout": 30
}

agentShow the log in the new pane the split returned (%1).

run_shell_command Execute {"pane_id":"%1","command":"cat checks.log"}
Result
{
"pane_id": "%1",
"outcome": "SIGNALLED",
"exit_status": 0,
"output": [
"2026-01-01 checks started",
"2026-01-01 checks finished"
],
"truncated": false,
"lines_dropped": 0,
"framed": true,
"seconds": 0.01,
"effective_timeout": 30
}

agentRemove the session by the id the create result returned ($0).

kill_session Teardown {"session_id":"$0"}
Result
{
"kind": "session",
"id": "$0"
}

agent in %0 it printed 2 passed in 0.00s; in %1 it printed 2026-01-01 checks finished.

Calls and results are recorded against libtmux/libtmux-java at fe25ff5ed, on a private tmux 3.8a server, running pytest 9.2.0. The preview takes its layout and panes from the recording's own tmux server after each call, and a pane's output from the results of the calls. The agent's narration is illustrative. This page documents 873f3ac6c, a different revision. The calls have the same input and output schemas there, but the results at that revision may differ from the recorded ones. The sandbox's project directory is shown as /home/user/project.

Install libtmux-mcp

Choose your client and configuration scope, then run the command or paste the configuration.

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ claude mcp add tmux -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.claude.json (this project)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ claude mcp add tmux --scope user -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.claude.json (all projects)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ claude mcp add tmux --scope project -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: .mcp.json (in repo, version-controlled)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then use this config:

{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: claude_desktop_config.json

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ codex mcp add tmux -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.codex/config.toml

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.

[mcp_servers.tmux]
command = "/absolute/path/to/libtmux-mcp"

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: .codex/config.toml (in repo)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ gemini mcp add --scope user tmux /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.gemini/settings.json

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ gemini mcp add --scope project tmux /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: .gemini/settings.json (in repo)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then use this config:

{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: .cursor/mcp.json (in repo)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then use this config:

{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.cursor/mcp.json

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ grok mcp add --scope user tmux -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.grok/config.toml

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ grok mcp add --scope project tmux -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ./.grok/config.toml (in repo)

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then use this config:

{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.gemini/config/mcp_config.json

Build or install the server first:

$ ./gradlew :libtmux-mcp:installDist

Then register:

$ opencode mcp add tmux -- /absolute/path/to/libtmux-mcp

Nothing publishes this server as a binary yet. The build writes a launcher at libtmux-mcp/build/install/libtmux-mcp/bin/libtmux-mcp; use its absolute path.

Config file: ~/.config/opencode/opencode.jsonc

Embed the server in a program
examples/src/main/java/io/github/libtmux/examples/ServeTmuxOverMcp.java
ServerConfig config = ServerConfig.builder()
.endpoint(ServerEndpoint.socketPath(socket))
.build();
try (Server server = Server.open(config)) {
// A real client speaks over this process's stdin and stdout, which TmuxMcpServer.overStdio
// wires up. Here the streams are empty and discarded: the point is the surface, not a
// conversation, and an example that wrote JSON-RPC to stdout could not also print.
StdioServerTransportProvider transport = new StdioServerTransportProvider(
new JacksonMcpJsonMapper(new ObjectMapper()),
InputStream.nullInputStream(),
OutputStream.nullOutputStream());
// Serving hands the transport over; closing the returned server closes it.
McpSyncServer mcp = TmuxMcpServer.serving(server, transport);
try {
return mcp.listTools().stream()
.map(McpSchema.Tool::name)
.sorted()
.toList();
} finally {
mcp.close();
}
}

Excerpt of examples/src/main/java/io/github/libtmux/examples/ServeTmuxOverMcp.java, which ./gradlew :libtmux-mcp:test check runs in the repository's CI (.github/workflows/ci.yml).

Workspace Manager

Install libtmux-workspace-cli

The workspace package is separate from the core library.

$ ./gradlew \
    --max-workers=2 \
    --no-parallel \
    :libtmux-workspace-cli:installDist

Run from a libtmux-java checkout with JDK 25 or newer. The launcher is libtmux-workspace-cli/build/install/tmux-workspace/bin/tmux-workspace; keep its adjacent libraries.

Build the workspace from a program
libtmux-workspace/src/test/java/io/github/libtmux/workspace/WorkspaceBuilderTest.java
private static final String WORKSPACE = """
session_name: built
windows:
- window_name: editor
layout: even-horizontal
panes:
- shell_command: echo editor-pane-one
- shell_command: echo editor-pane-two
- window_name: server
panes:
- echo server-pane
""";
void theDescribedSessionIsWhatGetsBuilt(Server server) {
Session built = WorkspaceBuilder.build(server, WorkspaceBuilder.parse(WORKSPACE));
assertEquals("built", built.name());
assertEquals(
List.of("editor", "server"),
built.windows().stream().map(Window::name).toList(),
"the first window is renamed, not added alongside the one tmux made");
assertEquals(2, built.windows().get(0).panes().size());
assertEquals(1, built.windows().get(1).panes().size());
}

Excerpt of libtmux-workspace/src/test/java/io/github/libtmux/workspace/WorkspaceBuilderTest.java, which ./gradlew :libtmux-mcp:test check runs in the repository's CI (.github/workflows/ci.yml).

Packages and integrations

API references

All Java versions and install instructions

Esc

Type to search.

Reference previewOpen reference