SwiftHome

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 Swift

Swift-based tmux client

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

Product
import Foundation
import LibTmux
@main
struct Quickstart {
static func main() async throws {
let server = try Server(
socketName: "libtmux-home-\(UUID().uuidString)",
configurationFile: "/dev/null"
)
try await work(server)
}
static func work(_ server: Server) async throws {
let session = try await server.newSession(
named: "demo",
shell: "/bin/sh"
)
let layout = try await server.snapshot()
guard let editor = layout.windows(of: session).first,
let left = layout.panes(of: editor).first(where: \.isActive)
else {
throw QuickstartError.missing
}
try await server.rename(editor, to: "editor")
let right = try await server.split(
left,
direction: .right,
shell: "/bin/sh"
)
let logs = try await server.newWindow(
in: session,
named: "logs",
shell: "/bin/sh"
)
try await server.run("printf 'hello from %s\\n' tmux", in: right)
let ready = try RegexPattern("^hello from tmux$")
let result = try await server.waitForOutput(
in: right,
matching: [ready]
)
guard result.outcome == .matched else {
throw QuickstartError.outputTimedOut
}
try await server.select(right)
try await server.select(logs.link)
let snapshot = try await server.snapshot()
for session in snapshot.sessions {
print("session \(session.name)")
let windows = snapshot.windows(of: session)
let links = snapshot.windowLinks(of: session)
for (window, link) in zip(windows, links) {
let panes = snapshot.panes(of: window)
let ids = panes.map { $0.id.rawValue }.joined(separator: " ")
print(" window \(link.index):\(window.name): \(ids)")
}
}
let home = right.windowID
guard let window = snapshot.windows.first(where: { $0.id == home }),
let owner = snapshot.sessions(of: window).first
else {
throw QuickstartError.missing
}
print("\(right.id.rawValue) is in window \(window.name)"
+ " of session \(owner.name)")
}
enum QuickstartError: Error {
case missing
case outputTimedOut
}
}
import Foundation
import LibTmux
@main
struct Quickstart {
static func main() async throws {
let server = try Server(
socketName: "libtmux-home-\(UUID().uuidString)",
configurationFile: "/dev/null"
)
do {
try await work(server)
} catch {
print("tmux quickstart failed: \(error)")
throw error
}
}
static func work(_ server: Server) async throws {
let session = try await server.newSession(
named: "demo",
shell: "/bin/sh"
)
let layout = try await server.snapshot()
guard let editor = layout.windows(of: session).first,
let left = layout.panes(of: editor).first(where: \.isActive)
else {
throw QuickstartError.missing
}
try await server.rename(editor, to: "editor")
let right = try await server.split(
left,
direction: .right,
shell: "/bin/sh"
)
let logs = try await server.newWindow(
in: session,
named: "logs",
shell: "/bin/sh"
)
try await server.run("printf 'hello from %s\\n' tmux", in: right)
let ready = try RegexPattern("^hello from tmux$")
let result = try await server.waitForOutput(
in: right,
matching: [ready]
)
guard result.outcome == .matched else {
throw QuickstartError.outputTimedOut
}
try await server.select(right)
try await server.select(logs.link)
let snapshot = try await server.snapshot()
for session in snapshot.sessions {
print("session \(session.name)")
let windows = snapshot.windows(of: session)
let links = snapshot.windowLinks(of: session)
for (window, link) in zip(windows, links) {
let panes = snapshot.panes(of: window)
let ids = panes.map { $0.id.rawValue }.joined(separator: " ")
print(" window \(link.index):\(window.name): \(ids)")
}
}
let home = right.windowID
guard let window = snapshot.windows.first(where: { $0.id == home }),
let owner = snapshot.sessions(of: window).first
else {
throw QuickstartError.missing
}
print("\(right.id.rawValue) is in window \(window.name)"
+ " of session \(owner.name)")
}
enum QuickstartError: Error {
case missing
case outputTimedOut
}
}
import Foundation
import LibTmux
@main
struct Quickstart {
static func main() async throws {
let server = try Server(
socketName: "libtmux-home-\(UUID().uuidString)",
configurationFile: "/dev/null"
)
do {
try await work(server)
} catch {
if try await server.isRunning() {
try await server.killServer()
}
throw error
}
try await server.killServer()
}
static func work(_ server: Server) async throws {
let session = try await server.newSession(
named: "demo",
shell: "/bin/sh"
)
let layout = try await server.snapshot()
guard let editor = layout.windows(of: session).first,
let left = layout.panes(of: editor).first(where: \.isActive)
else {
throw QuickstartError.missing
}
try await server.rename(editor, to: "editor")
let right = try await server.split(
left,
direction: .right,
shell: "/bin/sh"
)
let logs = try await server.newWindow(
in: session,
named: "logs",
shell: "/bin/sh"
)
try await server.run("printf 'hello from %s\\n' tmux", in: right)
let ready = try RegexPattern("^hello from tmux$")
let result = try await server.waitForOutput(
in: right,
matching: [ready]
)
guard result.outcome == .matched else {
throw QuickstartError.outputTimedOut
}
try await server.select(right)
try await server.select(logs.link)
let snapshot = try await server.snapshot()
for session in snapshot.sessions {
print("session \(session.name)")
let windows = snapshot.windows(of: session)
let links = snapshot.windowLinks(of: session)
for (window, link) in zip(windows, links) {
let panes = snapshot.panes(of: window)
let ids = panes.map { $0.id.rawValue }.joined(separator: " ")
print(" window \(link.index):\(window.name): \(ids)")
}
}
let home = right.windowID
guard let window = snapshot.windows.first(where: { $0.id == home }),
let owner = snapshot.sessions(of: window).first
else {
throw QuickstartError.missing
}
print("\(right.id.rawValue) is in window \(window.name)"
+ " of session \(owner.name)")
}
enum QuickstartError: Error {
case missing
case outputTimedOut
}
}
import Foundation
import LibTmux
@main
struct Quickstart {
static func main() async throws {
let server = try Server(
socketName: "libtmux-home-\(UUID().uuidString)",
configurationFile: "/dev/null"
)
do {
try await work(server)
} catch {
print("tmux quickstart failed: \(error)")
if try await server.isRunning() {
try await server.killServer()
}
throw error
}
try await server.killServer()
}
static func work(_ server: Server) async throws {
let session = try await server.newSession(
named: "demo",
shell: "/bin/sh"
)
let layout = try await server.snapshot()
guard let editor = layout.windows(of: session).first,
let left = layout.panes(of: editor).first(where: \.isActive)
else {
throw QuickstartError.missing
}
try await server.rename(editor, to: "editor")
let right = try await server.split(
left,
direction: .right,
shell: "/bin/sh"
)
let logs = try await server.newWindow(
in: session,
named: "logs",
shell: "/bin/sh"
)
try await server.run("printf 'hello from %s\\n' tmux", in: right)
let ready = try RegexPattern("^hello from tmux$")
let result = try await server.waitForOutput(
in: right,
matching: [ready]
)
guard result.outcome == .matched else {
throw QuickstartError.outputTimedOut
}
try await server.select(right)
try await server.select(logs.link)
let snapshot = try await server.snapshot()
for session in snapshot.sessions {
print("session \(session.name)")
let windows = snapshot.windows(of: session)
let links = snapshot.windowLinks(of: session)
for (window, link) in zip(windows, links) {
let panes = snapshot.panes(of: window)
let ids = panes.map { $0.id.rawValue }.joined(separator: " ")
print(" window \(link.index):\(window.name): \(ids)")
}
}
let home = right.windowID
guard let window = snapshot.windows.first(where: { $0.id == home }),
let owner = snapshot.sessions(of: window).first
else {
throw QuickstartError.missing
}
print("\(right.id.rawValue) is in window \(window.name)"
+ " of session \(owner.name)")
}
enum QuickstartError: Error {
case missing
case outputTimedOut
}
}
Example details
No tmux server yet

tmux before the first call: no server is running.

No tmux server yet

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

%0 sh
[demo]

tmux after Server.newSession: added session demo.

%0 sh
[demo]

tmux after Server.snapshot: unchanged.

%0 sh
[demo]

tmux after Snapshot.windows(of:): unchanged, the call sent no command.

%0 sh
[demo]

tmux after Snapshot.panes(of:): unchanged, the call sent no command.

%0 sh
[demo]

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

%0 sh
%1 sh
[demo]

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

%0 sh
%1 sh
[demo]

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

%0 sh
%1 sh
[demo]

tmux after Server.run: sent keys to pane %1.

%0 sh
%1 sh
[demo]

tmux after RegexPattern.init: unchanged, the call sent no command.

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

tmux after Server.waitForOutput: read pane %1.

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

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

%2 sh
[demo]

tmux after Server.select(WindowLink): selected window 1:logs.

%2 sh
[demo]

tmux after Server.snapshot: unchanged.

%2 sh
[demo]

tmux after Snapshot.windows(of:): unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.windowLinks(of:): unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.panes(of:): unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.panes(of:): unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.windows: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.sessions(of:): 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.init returned Server

{
"socketName": "libtmux-home-00000000-0000-0000-0000-000000000000"
}

The call sent no tmux command.

Server.newSession returned Session

{
"id": "$0",
"name": "demo"
}
2 tmux commands, 2 that change tmux
  1. run-shell -C libtmux-version-6691bf5607ee461f9bcef6f3090768be-#{version} error connecting to /tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000 (No such file or directory)
  2. new-session -d -P -F #{session_id}␞#{session_name}␞#{session_windows}␞#{session_attached}␞#{session_created}␞#{socket_path}␞#{pid}␞#{start_time} -s demo /bin/sh $0␞demo␞1␞0␞1793889970␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970

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

Server.snapshot returned Snapshot

{
"sessions": 1,
"windows": 1,
"panes": 1
}
7 tmux commands, 3 that change tmux
  1. run-shell -C libtmux-version-421257856dca4a6a859a9b665cb52dba-#{version} unknown command: libtmux-version-421257856dca4a6a859a9b665cb52dba-3.8a
  2. run-shell -C libtmux-version-a3bd5014baf1406aa91ff5d081083dcb-#{pid},#{start_time},#{q:socket_path} unknown command: libtmux-version-a3bd5014baf1406aa91ff5d081083dcb-3367525,1793889970,/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000
  3. list-sessions -F #{session_id}␞#{session_name}␞#{session_windows}␞#{session_attached}␞#{session_created}␞#{socket_path}␞#{pid}␞#{start_time} $0␞demo␞1␞0␞1793889970␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970
  4. list-windows -a -F #{window_id}␞#{window_name}␞#{window_index}␞#{window_panes}␞#{window_active}␞#{window_width}␞#{window_height}␞#{session_id}␞#{socket_path}␞#{pid}␞#{start_time} @0␞sh␞0␞1␞1␞80␞24␞$0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970
  5. list-panes -a -F #{pane_id}␞#{pane_index}␞#{pane_width}␞#{pane_height}␞#{pane_active}␞#{pane_dead}␞#{pane_input_off}␞#{pane_in_mode}␞#{pane_synchronized}␞#{pane_current_command}␞#{pane_current_path}␞#{pane_at_top}␞#{pane_at_bottom}␞#{pane_at_left}␞#{pane_at_right}␞#{window_id}␞#{socket_path}␞#{pid}␞#{start_time} %0␞0␞80␞24␞1␞0␞0␞0␞0␞sh␞/tmp/marked␞1␞1␞1␞1␞@0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970
  6. list-clients -F #{client_name}␞#{client_tty}␞#{client_pid}␞#{client_width}␞#{client_height}␞#{client_control_mode}␞#{session_id}␞#{pane_id}␞#{window_zoomed_flag}␞#{client_flags}␞#{socket_path}␞#{pid}␞#{start_time} no output
  7. run-shell -C libtmux-version-4b34e8f5afeb440ba72abd2466d048c0-#{pid},#{start_time},#{q:socket_path} unknown command: libtmux-version-4b34e8f5afeb440ba72abd2466d048c0-3367525,1793889970,/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000

Snapshot.windows(of:) returned Window

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

The call sent no tmux command.

Snapshot.panes(of:) returned Pane

{
"id": "%0"
}

The call sent no tmux command.

Server.rename returned Void

null
1 tmux command, 1 that changes tmux
  1. rename-window -t @0 -- editor no output

Server.split returned Pane

{
"id": "%1"
}
2 tmux commands, 1 that changes tmux
  1. split-window -d -P -F #{pane_id} -t %0 -h /bin/sh %1
  2. list-panes -a -f #{==:#{pane_id},%1} -F #{pane_id}␞#{pane_index}␞#{pane_width}␞#{pane_height}␞#{pane_active}␞#{pane_dead}␞#{pane_input_off}␞#{pane_in_mode}␞#{pane_synchronized}␞#{pane_current_command}␞#{pane_current_path}␞#{pane_at_top}␞#{pane_at_bottom}␞#{pane_at_left}␞#{pane_at_right}␞#{window_id}␞#{socket_path}␞#{pid}␞#{start_time} %1␞1␞39␞24␞0␞0␞0␞0␞0␞sh␞/tmp/marked␞1␞1␞0␞1␞@0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970

Server.newWindow returned WindowAppearance

{
"id": "@1",
"index": 1,
"name": "logs"
}
1 tmux command, 1 that changes tmux
  1. new-window -d -P -F #{window_id}␞#{window_name}␞#{window_index}␞#{window_panes}␞#{window_active}␞#{window_width}␞#{window_height}␞#{session_id}␞#{socket_path}␞#{pid}␞#{start_time} -t $0 -n logs /bin/sh @1␞logs␞1␞1␞0␞80␞24␞$0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970

Server.run returned Void

null
1 tmux command, 1 that changes tmux
  1. send-keys -t %1 -- 'printf '\''hello from %s\n'\'' tmux' Enter no output

RegexPattern.init returned RegexPattern

{
"source": "^hello from tmux$"
}

The call sent no tmux command.

Server.waitForOutput returned OutputWait

{
"outcome": "matched",
"matched": "^hello from tmux$",
"tail": [
"$ printf 'hello from %s\\n' tmux",
"hello from tmux",
"$"
]
}
2 tmux commands
  1. display-message -p -t %1 #{pane_id}␞#{history_size}␞#{cursor_y}␞#{pane_pid}␞#{pane_height}␞#{history_bytes}␞#{history_limit}␞#{pane_width}␞#{alternate_on} %1␞0␞2␞3367770␞24␞1295␞2000␞39␞0
  2. capture-pane -p -t %1 -S 0 -E 2 $ printf 'hello from %s\n' tmux hello from tmux $

Server.select(Pane) returned Void

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

Server.select(WindowLink) returned Void

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

Server.snapshot returned Snapshot

{
"sessions": 1,
"windows": 2,
"panes": 3
}
6 tmux commands, 2 that change tmux
  1. run-shell -C libtmux-version-9ef137956f844270bad84806a2c2dc7e-#{pid},#{start_time},#{q:socket_path} unknown command: libtmux-version-9ef137956f844270bad84806a2c2dc7e-3367525,1793889970,/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000
  2. list-sessions -F #{session_id}␞#{session_name}␞#{session_windows}␞#{session_attached}␞#{session_created}␞#{socket_path}␞#{pid}␞#{start_time} $0␞demo␞2␞0␞1793889970␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970
  3. list-windows -a -F #{window_id}␞#{window_name}␞#{window_index}␞#{window_panes}␞#{window_active}␞#{window_width}␞#{window_height}␞#{session_id}␞#{socket_path}␞#{pid}␞#{start_time} @0␞editor␞0␞2␞0␞80␞24␞$0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970 @1␞logs␞1␞1␞1␞80␞24␞$0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970
  4. list-panes -a -F #{pane_id}␞#{pane_index}␞#{pane_width}␞#{pane_height}␞#{pane_active}␞#{pane_dead}␞#{pane_input_off}␞#{pane_in_mode}␞#{pane_synchronized}␞#{pane_current_command}␞#{pane_current_path}␞#{pane_at_top}␞#{pane_at_bottom}␞#{pane_at_left}␞#{pane_at_right}␞#{window_id}␞#{socket_path}␞#{pid}␞#{start_time} %0␞0␞40␞24␞0␞0␞0␞0␞0␞sh␞/tmp/marked␞1␞1␞1␞0␞@0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970 %1␞1␞39␞24␞1␞0␞0␞0␞0␞sh␞/tmp/marked␞1␞1␞0␞1␞@0␞/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000␞3367525␞1793889970 %2␞0␞80␞24␞1␞0␞0␞0␞0␞sh␞/tmp/marked␞1␞…
  5. list-clients -F #{client_name}␞#{client_tty}␞#{client_pid}␞#{client_width}␞#{client_height}␞#{client_control_mode}␞#{session_id}␞#{pane_id}␞#{window_zoomed_flag}␞#{client_flags}␞#{socket_path}␞#{pid}␞#{start_time} no output
  6. run-shell -C libtmux-version-ead3bee558414981b0b13c584c0854a7-#{pid},#{start_time},#{q:socket_path} unknown command: libtmux-version-ead3bee558414981b0b13c584c0854a7-3367525,1793889970,/tmp/tmux-1000/libtmux-home-00000000-0000-0000-0000-000000000000

Snapshot.windows(of:) returned [Window]

[
"@0",
"@1"
]

The call sent no tmux command.

Snapshot.windowLinks(of:) returned [WindowLink]

[
"$0:0",
"$0:1"
]

The call sent no tmux command.

Snapshot.panes(of:) returned [Pane]

[
"%0",
"%1"
]

The call sent no tmux command.

Snapshot.panes(of:) returned [Pane]

[
"%2"
]

The call sent no tmux command.

Snapshot.windows returned Window

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

The call sent no tmux command.

Snapshot.sessions(of:) 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. kill-server no output
0/20
Run this example

Swift 6.2+, tmux on Linux/macOS

Save the program above as Sources/Main.swift 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.

Package.swift
// swift-tools-version: 6.2
import PackageDescription
let package = Package(
name: "ApiExample",
platforms: [.macOS(.v13)],
dependencies: [
.package(
url: "https://github.com/libtmux/libtmux-swift.git",
from: "0.1.1"
)
],
targets: [
.executableTarget(
name: "ApiExample",
dependencies: [
.product(name: "LibTmux", package: "libtmux-swift"),
],
path: "Sources"
)
]
)

Setup and run

# Save the files above at their displayed relative paths.
swift build --jobs 2 --product ApiExample
unset TMUX TMUX_PANE
export ENV=/dev/null BASH_ENV=/dev/null SHELL=/bin/sh
.build/debug/ApiExample

Expected output

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

Install libtmux-swift

.package(
    url: "https://github.com/libtmux/libtmux-swift.git",
    from: "0.1.0"
)

A range from 0.1.0 up to the next major version. Any 0.1.N release may change the API, so pin `exact:` instead to avoid a break.

MCP

tmux through MCP

Replay Hover a call to preview the tmux state after it. Click to pin it.

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 {"name":"checks"}
Result
{
"id": "$0",
"name": "checks",
"ref": "tmux1_AQ3atHtng1Jj30-gqW-Fv541MVcZ4sFXqPNXZIudQNAT",
"isAttached": false,
"windowCount": 1,
"createdAt": 1793757185
}

agentList the panes in the new session.

list_panes Inspect {"session":"checks"}
Result
{
"panes": [
{
"ref": "tmux1_BA3atHtng1Jj30-gqW-Fv56j-w_GfT5lw2c-1M9eytN5",
"isAtLeft": true,
"isActive": true,
"width": 80,
"height": 24,
"isAtBottom": true,
"isSynchronized": false,
"windowID": "@0",
"isAtTop": true,
"isDead": false,
"id": "%0",
"modeCount": 0,
"…": "4 more"
}
]
}

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

split_window Execute {"paneId":"%0","direction":"right"}
Result
{
"id": "%1",
"isSynchronized": false,
"currentPath": "/home/user/project",
"isAtTop": true,
"currentCommand": "sh",
"height": 24,
"isActive": false,
"ref": "tmux1_BA3atHtng1Jj30-gqW-Fv57PdeYPGTOQg9noVSe2N4-7",
"isAtLeft": false,
"isAtBottom": true,
"index": 1,
"isDead": false,
"…": "4 more"
}

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

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

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

run_shell_command Execute {"paneId":"%0","command":"pytest -q"}
Result
{
"droppedLines": 0,
"effectiveTimeout": 30,
"output": [
".. [100%]",
"2 passed in 0.00s"
],
"paneRef": "tmux1_BA3atHtng1Jj30-gqW-Fv56j-w_GfT5lw2c-1M9eytN5",
"seconds": 0.346968068,
"pane": "%0",
"exitStatus": 0,
"timedOut": false,
"linesMissed": false
}

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

run_shell_command Execute {"paneId":"%1","command":"cat checks.log"}
Result
{
"seconds": 0.087398972,
"exitStatus": 0,
"paneRef": "tmux1_BA3atHtng1Jj30-gqW-Fv57PdeYPGTOQg9noVSe2N4-7",
"pane": "%1",
"effectiveTimeout": 30,
"linesMissed": false,
"output": [
"2026-01-01 checks started",
"2026-01-01 checks finished"
],
"droppedLines": 0,
"timedOut": false
}

agentRemove the session once the result is read.

kill_session Teardown {"session":"checks"}
Result
{
"deleted": true,
"sessionId": "$0"
}

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

0/7

Install libtmux-mcp

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

$ claude mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

$ claude mcp add tmux --scope project -- \
    /absolute/path/to/.build/debug/libtmux-mcp

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then use this config:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Config file: claude_desktop_config.json

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

$ codex mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Config file: ~/.codex/config.toml

Build or install the server first:

$ swift build --product libtmux-mcp

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/.build/debug/libtmux-mcp"

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Config file: ~/.gemini/settings.json

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then use this config:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then use this config:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Config file: ~/.cursor/mcp.json

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Config file: ~/.grok/config.toml

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

$ grok mcp add --scope project tmux -- \
    /absolute/path/to/.build/debug/libtmux-mcp

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then use this config:

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

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Build or install the server first:

$ swift build --product libtmux-mcp

Then register:

$ opencode mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

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

Embed the server in a program
Examples/Sources/ExampleCode/MCPEmbedding.swift
public func useEmbeddedTools(on server: Server) async throws(ToolError) -> Int {
let tools = TmuxTools(server: server)
for definition in tools.visibleDefinitions {
print(definition.name, definition.summary)
}
let result = try await tools.call(ToolCall(name: "list_panes"))
return result.structured["panes"]?.arrayValue?.count ?? 0
}

Excerpt of Examples/Sources/ExampleCode/MCPEmbedding.swift, which swift test --package-path Examples runs in the repository's CI (.github/workflows/ci.yml).

Workspace Manager

Install tmux-workspace

The workspace package is separate from the core library.

$ swift build \
    --jobs 2 \
    --traits YAMLWorkspaces \
    --force-resolved-versions \
    --product tmux-workspace

Run from a libtmux-swift checkout with Swift 6.2 or newer on Linux, or Xcode Swift 6.3 or newer on macOS. The command is .build/debug/tmux-workspace.

Build the workspace from a program
Examples/Sources/ExampleCode/Workspaces.swift
public func describeAWorkspaceInSwift() -> Workspace {
let workspace = Workspace(
sessionName: "work",
windows: [
WindowPlan(
windowName: "editor",
layout: "even-horizontal",
panes: [PanePlan(), PanePlan()]
),
WindowPlan(
windowName: "logs",
panes: [PanePlan(shellCommands: ["tail -f /tmp/build.log"])]
),
]
)
return workspace
}

Excerpt of Examples/Sources/ExampleCode/Workspaces.swift, which swift test --package-path Examples runs in the repository's CI (.github/workflows/ci.yml).

Packages and integrations

API references

All Swift versions and install instructions

Esc

Type to search.

Reference previewOpen reference