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.

MoreLess about this notice

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

Control tmux from Java code 0.x Released; the API may change. Read more Core Library home →

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();
}
}
}
}
Example details
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.

  1. Before the first call

    No tmux server is running yet.

  2. Server.open returned Server

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

    The call sent no tmux command.

  3. 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).

  4. Session.activeWindow returned Optional<Window>

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

    The call sent no tmux command.

  5. 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).

  6. Window.activePane returned Optional<Pane>

    {
    "id": "%0"
    }

    The call sent no tmux command.

  7. 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).

  8. 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).

  9. 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
  10. 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 $
  11. Pane.select returned void

    null
    1 tmux command, 1 that changes tmux
    1. select-pane -t %1 no output
  12. Window.select returned void

    null
    1 tmux command, 1 that changes tmux
    1. select-window -t $0:1 no output
  13. 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).

  14. ServerSnapshot.sessions returned List<SessionState>

    [
    "$0"
    ]

    The call sent no tmux command.

  15. ServerSnapshot.windowsOf returned List<WindowState>

    [
    "@0",
    "@1"
    ]

    The call sent no tmux command.

  16. ServerSnapshot.panesOf returned List<PaneState>

    [
    "%0",
    "%1"
    ]

    The call sent no tmux command.

  17. ServerSnapshot.panesOf returned List<PaneState>

    [
    "%2"
    ]

    The call sent no tmux command.

  18. Pane.window returned Window

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

    The call sent no tmux command.

  19. Window.session returned Session

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

    The call sent no tmux command.

  20. Server.killServer returned void

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

JDK 25, Gradle 9 and tmux 3.3a or newer on Linux or 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.
gradle --console=plain --no-daemon 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

Install io.github.libtmux:libtmux

From Git
build.gradle.kts
pom.xml
Terminal
io.github.libtmux:libtmux 0.1.2 0.x Maven Central
dependencies {
    implementation(platform("io.github.libtmux:libtmux-bom:0.1.2"))

    implementation("io.github.libtmux:libtmux")
    testImplementation("io.github.libtmux:libtmux-junit5")
}
<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>
$ git clone --branch v0.1.2 https://github.com/libtmux/libtmux-java \
  && (cd libtmux-java \
  && ./gradlew publishToMavenLocal)

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.

Pins the tagged source; the registry release is the default.

MCP

Give an assistant tmux tools concept Working example; may change without notice. Read more MCP home →

tmux through MCP

Replay Hover a call to preview the tmux state after it. Use its pin button to hold it. With the replay focused, the arrow keys, Home and End step through the calls.

tmux before the first call.

tmux window of 1 pane
%0 sh
[checks] 0:sh*

tmux after create_session.

tmux window of 1 pane
%0 sh
[checks] 0:sh*

tmux after list_panes: unchanged, the call only reads.

tmux window of 2 panes
%0 sh
%1 sh
[checks] 0:sh*

tmux after split_window.

tmux window of 2 panes
%0 sh
%1 sh
[checks] 0:sh*

tmux after get_tmux_variables: unchanged, the call only reads.

tmux window of 2 panes
%0 sh
$ pytest -q
..
                                  [100%
]
2 passed in 0.00s
%1 sh
[checks] 0:sh*

tmux after run_shell_command.

tmux window of 2 panes
%0 sh
$ pytest -q
..
                                  [100%
]
2 passed in 0.00s
%1 sh
$ cat checks.log
2026-01-01 checks started
2026-01-01 checks finished
[checks] 0:sh*

tmux after run_shell_command.

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": "89f5,80x24,0,0{39x24,0,0,0,40x24,40,0,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.33,
"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

pytest printed 2 passed and checks.log ends with checks finished. I removed the checks session.

1/7

Install libtmux-mcp

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

Terminal
Terminal
Terminal
claude_desktop_config.json
Terminal
.codex/config.toml
Terminal
Terminal
.cursor/mcp.json
~/.cursor/mcp.json
Terminal
Terminal
~/.gemini/config/mcp_config.json
Terminal
libtmux-mcp concept Maven Central
First
$ ./gradlew :libtmux-mcp:installDist
$ claude mcp add tmux -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
$ claude mcp add tmux --scope user -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
$ claude mcp add tmux --scope project -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}
First
$ ./gradlew :libtmux-mcp:installDist
$ codex mcp add tmux -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
[mcp_servers.tmux]
command = "/absolute/path/to/libtmux-mcp"
First
$ ./gradlew :libtmux-mcp:installDist
$ gemini mcp add --scope user tmux /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
$ gemini mcp add --scope project tmux /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}
First
$ ./gradlew :libtmux-mcp:installDist
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}
First
$ ./gradlew :libtmux-mcp:installDist
$ grok mcp add --scope user tmux -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
$ grok mcp add --scope project tmux -- /absolute/path/to/libtmux-mcp
First
$ ./gradlew :libtmux-mcp:installDist
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/libtmux-mcp"
        }
    }
}
First
$ ./gradlew :libtmux-mcp:installDist
$ opencode mcp add tmux -- /absolute/path/to/libtmux-mcp

Writes ~/.claude.json (this project).

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.

Writes ~/.claude.json (all projects).

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.

Writes .mcp.json (in repo, version-controlled).

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.

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.

Writes ~/.codex/config.toml.

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.

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

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.

Writes ~/.gemini/settings.json.

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.

Writes .gemini/settings.json (in repo).

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.

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.

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.

Writes ~/.grok/config.toml.

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.

Writes ./.grok/config.toml (in repo).

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.

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.

Writes ~/.config/opencode/opencode.jsonc.

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.

Embed the server in a program
examples/src/main/java/io/github/libtmux/examples/ServeTmuxOverMcp.javaExcerpt · lines 44–67
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. This program is tested on every change.

Workspace Manager

Load a workspace file concept Working example; may change without notice. Read more Workspace Manager home →

Two panes

A window of two panes.

session_name: dev
windows:
- window_name: editor
window_index: 0
layout: even-horizontal
panes:
- null
- shell_command: echo ready
{
"session_name": "dev",
"windows": [
{
"window_name": "editor",
"window_index": 0,
"layout": "even-horizontal",
"panes": [
null,
{
"shell_command": "echo ready"
}
]
}
]
}
Window 0, editor: 2 panes, even-horizontal❯ echo ready
layout even-horizontal

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/README.md. Tested by theLoadAndFreezeExamplesRunAsWritten (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ReadmeExamplesTest.java; a test runs the command).

Environment

environment sets variables for a session, a window or a pane.

session_name: booleans
options:
renumber-windows: true
global_options:
mouse: false
environment:
FLAG: true
windows:
- options:
remain-on-exit: true
options_after:
synchronize-panes: false
{
"session_name": "booleans",
"options": {
"renumber-windows": true
},
"global_options": {
"mouse": false
},
"environment": {
"FLAG": true
},
"windows": [
{
"options": {
"remain-on-exit": true
},
"options_after": {
"synchronize-panes": false
}
}
]
}
Window 0: no panes listed, one empty pane, even-vertical
no panes listed, so tmux opens one

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java. Tested by booleanOptionsUseTmuxValuesWhileEnvironmentRemainsText (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java; a test runs the command).

Focus

focus: true selects a window or a pane when the session is built.

session_name: focus
windows:
- window_name: implicit
panes: [null, null, null]
- window_name: declared
panes:
- shell_command: null
focus: true
- null
- null
{
"session_name": "focus",
"windows": [
{
"window_name": "implicit",
"panes": [
null,
null,
null
]
},
{
"window_name": "declared",
"panes": [
{
"shell_command": null,
"focus": true
},
null,
null
]
}
]
}
Window 0, implicit: 3 panes, even-vertical
no layout set
Window 1, declared: 3 panes, even-vertical
no layout set

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java. Tested by aWindowWithNoDeclaredFocusIsLeftOnItsLastPane (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java; a test runs the command).

tmux options

global_options, options and a window's options set tmux options.

session_name: pbi
options:
pane-base-index: 1
default-shell: /bin/sh
windows:
- window_name: one
panes: [null, null]
- window_name: two
panes: [null, null]
{
"session_name": "pbi",
"options": {
"pane-base-index": 1,
"default-shell": "/bin/sh"
},
"windows": [
{
"window_name": "one",
"panes": [
null,
null
]
},
{
"window_name": "two",
"panes": [
null,
null
]
}
]
}
Window 0, one: 2 panes, even-vertical
no layout set
Window 1, two: 2 panes, even-vertical
no layout set

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java. Tested by aWindowOptionUnderSessionOptionsReachesEveryWindow (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java; a test runs the command).

Shell per pane

A pane can start its own shell or program, and window_shell sets the default for a window.

session_name: launched
workspace_builder_options:
pane_readiness: always
windows:
- panes:
- shell: /bin/cat
shell_command: printed
{
"session_name": "launched",
"workspace_builder_options": {
"pane_readiness": "always"
},
"windows": [
{
"panes": [
{
"shell": "/bin/cat",
"shell_command": "printed"
}
]
}
]
}
Window 0: 1 pane, even-vertical❯ printed
no layout set

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java. Tested by blankPanesAndExplicitLaunchersSkipReadinessQueries (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java; a test runs the command).

Skip Enter for a pane

enter: false on a pane types its commands without running them.

session_name: defaults
windows:
- panes:
- enter: false
sleep_before: 0.02
sleep_after: 0.03
shell_command:
- first
- cmd: second
sleep_before: null
- cmd: third
enter: true
sleep_after: 0
- fourth
{
"session_name": "defaults",
"windows": [
{
"panes": [
{
"enter": false,
"sleep_before": 0.02,
"sleep_after": 0.03,
"shell_command": [
"first",
{
"cmd": "second",
"sleep_before": null
},
{
"cmd": "third",
"enter": true,
"sleep_after": 0
},
"fourth"
]
}
]
}
]
}
Window 0: 1 pane, even-vertical❯ first❯ second❯ third❯ fourth
no layout set

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/MainTest.java. Tested by paneCommandDefaultsCarryUntilAnExplicitOverride (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/MainTest.java; loaded by the library in a test; the command is not run).

Window index

window_index places a window at an index; a window without one takes the lowest free index.

session_name: native-java
options:
default-shell: /bin/sh
environment:
WORKSPACE_TEST: inherited
windows:
- &main
window_name: main
window_index: 0
layout: even-horizontal
panes: [null, null]
- <<: *main
window_name: other
window_index: 4
panes: [null]
{
"session_name": "native-java",
"options": {
"default-shell": "/bin/sh"
},
"environment": {
"WORKSPACE_TEST": "inherited"
},
"windows": [
{
"window_name": "main",
"window_index": 0,
"layout": "even-horizontal",
"panes": [
null,
null
]
},
{
"window_name": "other",
"window_index": 4,
"layout": "even-horizontal",
"panes": [
null
]
}
]
}
Window 0, main: 2 panes, even-horizontal
layout even-horizontal
Window 4, other: 1 pane, even-horizontal
layout even-horizontal

Save the file as workspace.yaml and load it with:

tmux-workspace load workspace.yaml

Workspace file: libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java. Tested by coldLoadCaptureAndReusePreserveIndexedTopology (libtmux-workspace-cli/src/test/java/io/github/libtmux/workspace/cli/ExecutionTest.java; a test runs the command).

Install libtmux-workspace-cli

The workspace package is separate from the core library.

Gradle
Terminal
libtmux-workspace-cli concept Maven Central
$ ./gradlew \
    --max-workers=2 \
    --no-parallel \
    :libtmux-workspace-cli:installDist
Then
$ tmux-workspace load ./workspace.yaml

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.

Packages and integrations

API references

Esc
Search in

Type to search.

Reference previewOpen reference