AgentCreate the session.
Result
{ "name": "checks", "session_id": "$0"}Choose documentation 3
No matching documentation.
No matching versions.
Current version
latestNo matching languages.
Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.
C++-based tmux client
tmux client library for C++. Control tmux, connect to and create servers, navigate sessions, windows, and panes, send keys, watch for changes via control mode, capture pane contents
Control tmux from C++ code 0.x Released; the API may change. Read more Core Library home →
#include <chrono>#include <cstdio>#include <cstdlib>#include <filesystem>#include <iostream>#include <stdexcept>#include <libtmux/libtmux.hpp>
int main() { char directory[] = "/tmp/ltx-cxx-home-XXXXXX"; if (!mkdtemp(directory)) { std::perror("create temporary directory"); return 1; }
const auto socket = std::filesystem::path(directory) / "tmux.sock"; const auto server = libtmux::Server::startable_at_socket_path( socket, "/dev/null", {}, {.timeout = std::chrono::seconds{5}}).value();
const auto work = [&] { const auto session = server.new_session({ .name = "demo", .shell_command = "/bin/sh", }).value();
// Lay out the session: name its window, split it, add a second window. const auto editor = session.active_window().value(); editor.rename("editor").value(); const auto left = editor.active_pane().value(); const auto right = left.split({ .horizontal = true, .shell_command = "/bin/sh", }).value(); const auto logs = session.new_window({ .name = "logs", .shell_command = "/bin/sh", }).value();
// Type a command into the new pane and wait for what it prints. right.send_line("printf 'hello from %s\\n' tmux").value(); const auto ready = right.wait_for_text( "hello from tmux", {.timeout = std::chrono::seconds{5}}).value(); if (!ready.matched) throw std::runtime_error("output did not arrive");
// Move the focus an attached client sees: the pane, then the window. right.select().value(); logs.select().value();
// Walk the objects: down from the server, then up from one pane. const auto sessions = server.sessions().value(); for (const auto& each : sessions) { std::cout << "session " << each.name() << '\n'; const auto windows = each.windows().value(); for (const auto& window : windows) { std::cout << " window " << window.index() << ':' << window.name() << ':'; const auto panes = window.panes().value(); for (const auto& pane : panes) { std::cout << ' ' << pane.id().value(); } std::cout << '\n'; } } const auto window = right.window().value(); const auto owner = window.session().value(); std::cout << right.id().value() << " is in window " << window.name() << " of session " << owner.name() << '\n'; };
work();}#include <chrono>#include <cstdio>#include <cstdlib>#include <filesystem>#include <iostream>#include <stdexcept>#include <utility>#include <libtmux/libtmux.hpp>
int main() { char directory[] = "/tmp/ltx-cxx-home-XXXXXX"; if (!mkdtemp(directory)) { std::perror("create temporary directory"); return 1; }
const auto checked = [](auto result) { if (!result) throw std::runtime_error(result.error().diagnostic); return std::move(result).value(); };
const auto socket = std::filesystem::path(directory) / "tmux.sock"; const auto server = checked(libtmux::Server::startable_at_socket_path( socket, "/dev/null", {}, {.timeout = std::chrono::seconds{5}}));
const auto work = [&] { const auto session = checked(server.new_session({ .name = "demo", .shell_command = "/bin/sh", }));
// Lay out the session: name its window, split it, add a second window. const auto editor = checked(session.active_window()); checked(editor.rename("editor")); const auto left = checked(editor.active_pane()); const auto right = checked(left.split({ .horizontal = true, .shell_command = "/bin/sh", })); const auto logs = checked(session.new_window({ .name = "logs", .shell_command = "/bin/sh", }));
// Type a command into the new pane and wait for what it prints. checked(right.send_line("printf 'hello from %s\\n' tmux")); const auto ready = checked(right.wait_for_text( "hello from tmux", {.timeout = std::chrono::seconds{5}})); if (!ready.matched) throw std::runtime_error("output did not arrive");
// Move the focus an attached client sees: the pane, then the window. checked(right.select()); checked(logs.select());
// Walk the objects: down from the server, then up from one pane. const auto sessions = checked(server.sessions()); for (const auto& each : sessions) { std::cout << "session " << each.name() << '\n'; const auto windows = checked(each.windows()); for (const auto& window : windows) { std::cout << " window " << window.index() << ':' << window.name() << ':'; const auto panes = checked(window.panes()); for (const auto& pane : panes) { std::cout << ' ' << pane.id().value(); } std::cout << '\n'; } } const auto window = checked(right.window()); const auto owner = checked(window.session()); std::cout << right.id().value() << " is in window " << window.name() << " of session " << owner.name() << '\n'; };
int status = 0; try { work(); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); status = 1; } return status;}#include <chrono>#include <cstdio>#include <cstdlib>#include <filesystem>#include <iostream>#include <stdexcept>#include <utility>#include <libtmux/libtmux.hpp>
int main() { char directory[] = "/tmp/ltx-cxx-home-XXXXXX"; if (!mkdtemp(directory)) { std::perror("create temporary directory"); return 1; }
const auto socket = std::filesystem::path(directory) / "tmux.sock"; auto created = libtmux::Server::startable_at_socket_path( socket, "/dev/null", {}, {.timeout = std::chrono::seconds{5}}); if (!created) { std::fprintf(stderr, "%s\n", created.error().diagnostic.c_str()); std::filesystem::remove_all(directory); return 1; } const auto server = std::move(created).value();
const auto work = [&] { const auto session = server.new_session({ .name = "demo", .shell_command = "/bin/sh", }).value();
// Lay out the session: name its window, split it, add a second window. const auto editor = session.active_window().value(); editor.rename("editor").value(); const auto left = editor.active_pane().value(); const auto right = left.split({ .horizontal = true, .shell_command = "/bin/sh", }).value(); const auto logs = session.new_window({ .name = "logs", .shell_command = "/bin/sh", }).value();
// Type a command into the new pane and wait for what it prints. right.send_line("printf 'hello from %s\\n' tmux").value(); const auto ready = right.wait_for_text( "hello from tmux", {.timeout = std::chrono::seconds{5}}).value(); if (!ready.matched) throw std::runtime_error("output did not arrive");
// Move the focus an attached client sees: the pane, then the window. right.select().value(); logs.select().value();
// Walk the objects: down from the server, then up from one pane. const auto sessions = server.sessions().value(); for (const auto& each : sessions) { std::cout << "session " << each.name() << '\n'; const auto windows = each.windows().value(); for (const auto& window : windows) { std::cout << " window " << window.index() << ':' << window.name() << ':'; const auto panes = window.panes().value(); for (const auto& pane : panes) { std::cout << ' ' << pane.id().value(); } std::cout << '\n'; } } const auto window = right.window().value(); const auto owner = window.session().value(); std::cout << right.id().value() << " is in window " << window.name() << " of session " << owner.name() << '\n'; };
int status = 0; try { work(); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); status = 1; }
if (std::filesystem::exists(socket)) { server.kill().value(); } std::filesystem::remove_all(directory); return status;}#include <chrono>#include <cstdio>#include <cstdlib>#include <filesystem>#include <iostream>#include <stdexcept>#include <utility>#include <libtmux/libtmux.hpp>
int main() { char directory[] = "/tmp/ltx-cxx-home-XXXXXX"; if (!mkdtemp(directory)) { std::perror("create temporary directory"); return 1; }
const auto checked = [](auto result) { if (!result) throw std::runtime_error(result.error().diagnostic); return std::move(result).value(); };
const auto socket = std::filesystem::path(directory) / "tmux.sock"; auto created = libtmux::Server::startable_at_socket_path( socket, "/dev/null", {}, {.timeout = std::chrono::seconds{5}}); if (!created) { std::fprintf(stderr, "%s\n", created.error().diagnostic.c_str()); std::filesystem::remove_all(directory); return 1; } const auto server = std::move(created).value();
const auto work = [&] { const auto session = checked(server.new_session({ .name = "demo", .shell_command = "/bin/sh", }));
// Lay out the session: name its window, split it, add a second window. const auto editor = checked(session.active_window()); checked(editor.rename("editor")); const auto left = checked(editor.active_pane()); const auto right = checked(left.split({ .horizontal = true, .shell_command = "/bin/sh", })); const auto logs = checked(session.new_window({ .name = "logs", .shell_command = "/bin/sh", }));
// Type a command into the new pane and wait for what it prints. checked(right.send_line("printf 'hello from %s\\n' tmux")); const auto ready = checked(right.wait_for_text( "hello from tmux", {.timeout = std::chrono::seconds{5}})); if (!ready.matched) throw std::runtime_error("output did not arrive");
// Move the focus an attached client sees: the pane, then the window. checked(right.select()); checked(logs.select());
// Walk the objects: down from the server, then up from one pane. const auto sessions = checked(server.sessions()); for (const auto& each : sessions) { std::cout << "session " << each.name() << '\n'; const auto windows = checked(each.windows()); for (const auto& window : windows) { std::cout << " window " << window.index() << ':' << window.name() << ':'; const auto panes = checked(window.panes()); for (const auto& pane : panes) { std::cout << ' ' << pane.id().value(); } std::cout << '\n'; } } const auto window = checked(right.window()); const auto owner = checked(window.session()); std::cout << right.id().value() << " is in window " << window.name() << " of session " << owner.name() << '\n'; };
int status = 0; try { work(); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); status = 1; }
if (std::filesystem::exists(socket)) { server.kill().value(); } std::filesystem::remove_all(directory); return status;}tmux before the first call: no server is running.
tmux after Server.startable_at_socket_path: no server is running; the call sent no command.
tmux after Server.new_session: added session demo.
tmux after Session.active_window: unchanged.
tmux after Window.rename: renamed window 0:sh to 0:editor.
tmux after Window.active_pane: unchanged.
tmux after Pane.split: added pane %1 to window 0:editor.
tmux after Session.new_window: added window 1:logs.
tmux after Pane.send_line: sent keys to pane %1.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.wait_for_text: read pane %1.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.select: selected pane %1 in window 0:editor.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.select: selected window 1:logs.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Server.sessions: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Session.windows: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.panes: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.panes: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.window: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.session: unchanged.
tmux after Server.kill: the server has exited.
Before the first call
No tmux server is running yet.
Server.startable_at_socket_path returned expected<Server, CommandFailure>
{ "socketPath": "/tmp/ltx-cxx-home-AbC123/tmux.sock"}The call sent no tmux command.
Server.new_session returned expected<Session, CommandFailure>
{ "id": "$0", "name": "demo"}new-session -d -P -s demo -F #{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_attached}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_windows}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_path}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_created}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_group}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_grouped}}␞ -- /bin/sh $0␞demo␞0␞1␞/tmp/marked␞1793888732␞␞0␞ Before these, the library asked tmux about itself 2 times (its version, its daemon, how a control client reads escapes).
Session.active_window returned expected<Window, CommandFailure>
{ "id": "@0", "index": 0, "name": "sh"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; display-message -p -t $0 #{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_panes}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_width}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_height}}␞#{s/␞/␛S/:#… @0␞sh␞1␞$0␞0␞1␞80␞24␞{"V":2,"L":{"t":"p","w":80,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%0"}}␞0␞0␞0␞1␞ Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).
Window.rename returned expected<void, CommandFailure>
nullif-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; rename-window -t $0:@0 -- editor no output Window.active_pane returned expected<Pane, CommandFailure>
{ "id": "%0"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; display-message -p -t $0:@0 #{s/␞/␛S/:#{s/␛/␛E/:pane_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_current_command}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_title}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_pid}}␞#{s/␞/␛S/:#{s/␛… %0␞sh␞1␞@0␞$0␞0␞host␞3180109␞/dev/pts/14␞/tmp/marked␞80␞24␞0␞0␞1␞1␞1␞1␞0␞0␞0␞␞ Pane.split returned expected<Pane, CommandFailure>
{ "id": "%1"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; split-window -t %0 -P -d -h -F #{s/␞/␛S/:#{s/␛/␛E/:pane_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_current_command}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_title}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_pid}}␞#{s/␞/␛S/:#{… %1␞sh␞0␞@0␞$0␞1␞host␞3180399␞/dev/pts/16␞/tmp/marked␞39␞24␞0␞0␞1␞1␞0␞1␞0␞41␞0␞␞ Session.new_window returned expected<Window, CommandFailure>
{ "id": "@1", "index": 1, "name": "logs"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; new-window -t $0 -P -n logs -d -F #{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_panes}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_width}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_height}}␞#{… @1␞logs␞0␞$0␞1␞1␞80␞24␞{"V":2,"L":{"t":"p","w":80,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%2"}}␞0␞0␞0␞1␞ Pane.send_line returned expected<void, CommandFailure>
nullif-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; send-keys -t %1 -l -- 'printf '\''hello from %s\n'\'' tmux' ; send-keys -t %1 Enter no output Pane.wait_for_text returned expected<WaitResult, CommandFailure>
{ "matched": true}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; display-message -p -t %1 -- '#{cursor_y} #{pane_height}' 2 24 if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; capture-pane -p -J -t %1 $ printf 'hello from %s\n' tmux
hello from tmux
$ Pane.select returned expected<void, CommandFailure>
nullif-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; select-pane -t %1 no output Window.select returned expected<void, CommandFailure>
nullif-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; select-window -t $0:@1 no output Server.sessions returned expected<std::vector<Session>, CommandFailure>
{ "count": 1}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; list-sessions -F #{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_attached}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_windows}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_path}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_created}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_group}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_grouped}}␞ $0␞demo␞0␞2␞/tmp/marked␞1793888732␞␞0␞ Session.windows returned expected<std::vector<Window>, CommandFailure>
{ "count": 2}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; list-windows -t $0 -F #{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_panes}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_width}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_height}}␞#{s/␞/␛S/:#{s/… @0␞editor␞0␞$0␞0␞2␞80␞24␞{"V":2,"L":{"t":"h","w":80,"h":24,"x":0,"y":0,"c":[{"t":"p","w":40,"h":24,"x":0,"y":0,"l":0,"i":0,"I":"%0"},{"t":"p","w":39,"h":24,"x":41,"y":0,"a":true,"i":1,"I":"%1"}]}}␞0␞0␞0␞1␞
@1␞logs␞1␞$0␞1␞1␞80␞24␞{"V":2,"L":{"t":"p","w":80,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%2"}}␞0␞0␞0␞1␞ Window.panes returned expected<std::vector<Pane>, CommandFailure>
{ "count": 2}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; list-panes -t $0:@0 -F #{s/␞/␛S/:#{s/␛/␛E/:pane_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_current_command}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_title}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_pid}}␞#{s/␞/␛S/:#{s/␛/␛E/:… %0␞sh␞0␞@0␞$0␞0␞host␞3180109␞/dev/pts/14␞/tmp/marked␞40␞24␞0␞0␞1␞1␞1␞0␞0␞0␞0␞␞
%1␞sh␞1␞@0␞$0␞1␞host␞3180399␞/dev/pts/16␞/tmp/marked␞39␞24␞0␞0␞1␞1␞0␞1␞0␞41␞0␞␞ Window.panes returned expected<std::vector<Pane>, CommandFailure>
{ "count": 1}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; list-panes -t $0:@1 -F #{s/␞/␛S/:#{s/␛/␛E/:pane_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_current_command}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_title}}␞#{s/␞/␛S/:#{s/␛/␛E/:pane_pid}}␞#{s/␞/␛S/:#{s/␛/␛E/:… %2␞sh␞1␞@1␞$0␞0␞host␞3180426␞/dev/pts/17␞/tmp/marked␞80␞24␞0␞0␞1␞1␞1␞1␞0␞0␞0␞␞ Pane.window returned expected<Window, CommandFailure>
{ "id": "@0", "index": 0, "name": "editor"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; display-message -p -t %1 #{s/␞/␛S/:#{s/␛/␛E/:window_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_active}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_index}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_panes}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_width}}␞#{s/␞/␛S/:#{s/␛/␛E/:window_height}}␞#{s/␞/␛S/:#… @0␞editor␞0␞$0␞0␞2␞80␞24␞{"V":2,"L":{"t":"h","w":80,"h":24,"x":0,"y":0,"c":[{"t":"p","w":40,"h":24,"x":0,"y":0,"l":0,"i":0,"I":"%0"},{"t":"p","w":39,"h":24,"x":41,"y":0,"a":true,"i":1,"I":"%1"}]}}␞0␞0␞0␞1␞ Window.session returned expected<Session, CommandFailure>
{ "id": "$0", "name": "demo"}if-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; display-message -p -t $0:@0 #{s/␞/␛S/:#{s/␛/␛E/:session_id}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_name}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_attached}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_windows}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_path}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_created}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_group}}␞#{s/␞/␛S/:#{s/␛/␛E/:session_gr… $0␞demo␞0␞2␞/tmp/marked␞1793888732␞␞0␞ Server.kill returned expected<void, CommandFailure>
nullif-shell -F #{==:#{version},3.8a} '' libtmux-version-79582a27c4ebffb5d030f88c373bf276 ; kill-server no output CMake 3.25+, Clang 18 with matching libc++ development files, C++23, tmux on Linux/macOS
Save the program above as main.cpp 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.
cmake_minimum_required(VERSION 3.25)project(libtmux_api_example LANGUAGES CXX)
find_package(libtmux REQUIRED)
add_executable(api_example main.cpp)target_link_libraries(api_example PRIVATE libtmux::libtmux)# Save the files above at their displayed relative paths.git clone https://github.com/libtmux/libtmux-cxx.git libtmux-sourcegit -C libtmux-source checkout --detach 888167d2d908e7f1c0e6969f96c5582edd4ac8f2cmake -S libtmux-source -B library \ -DCMAKE_TOOLCHAIN_FILE="$PWD/libtmux-source/cmake/toolchains/clang-libcxx.cmake" \ -DCMAKE_BUILD_TYPE=Release -DLIBTMUX_BUILD_TESTS=OFF -DLIBTMUX_BUILD_EXAMPLES=OFF \ -DLIBTMUX_BUILD_TESTING_LIBRARY=OFF -DLIBTMUX_CXX_STANDARD=23 \ -DCMAKE_CXX_COMPILER=clang++cmake --build library -j 2cmake --install library --prefix "$PWD/prefix"cmake -S . -B build -DCMAKE_PREFIX_PATH="$PWD/prefix" -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23cmake --build build -j 2build/api_examplesession demo window 0:editor: %0 %1 window 1:logs: %2%1 is in window editor of session demolibtmux-cxxinclude(FetchContent)
FetchContent_Declare(
libtmux
GIT_REPOSITORY https://github.com/libtmux/libtmux-cxx.git
GIT_TAG v0.1.0-alpha.10
)
FetchContent_MakeAvailable(libtmux)
target_link_libraries(your_target PRIVATE libtmux::libtmux){
"registries": [
{
"kind": "git",
"repository": "https://github.com/libtmux/libtmux-cxx",
"baseline": "",
"packages": ["libtmux"]
}
]
}$ git submodule add \
https://github.com/libtmux/libtmux-cxx.git \
third_party/libtmuxinclude(FetchContent)
FetchContent_Declare(libtmux-cxx
GIT_REPOSITORY https://github.com/libtmux/libtmux-cxx
GIT_TAG v0.1.0)
FetchContent_MakeAvailable(libtmux-cxx)Name a tag or a commit, never a moving branch. Built this way the library brings nothing else: its tests, examples and MCP server all default off when it is not the top-level project.
This repository is a vcpkg git registry, not a curated-registry port. Put this in vcpkg-configuration.json, add "libtmux" to your manifest, and run vcpkg x-update-baseline to fill the baseline.
Then add_subdirectory(third_party/libtmux) and link libtmux::libtmux.
Pins the tagged source; the registry release is the default.
Give an assistant tmux tools concept Working example; may change without notice. Read more MCP home →
tmux before the first call.
tmux after create_session.
tmux after list_panes: unchanged, the call only reads.
tmux after split_window.
tmux after list_windows: unchanged, the call only reads.
$ pytest -q .. [100%] 2 passed in 0.01s
tmux after run_shell_command.
$ pytest -q .. [100%] 2 passed in 0.01s
$ cat checks.log 2026-01-01 checks started 2026-01-01 checks finished
tmux after run_shell_command.
tmux after kill_session.
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.
{ "name": "checks", "session_id": "$0"}AgentList the panes, each with its session id.
{ "panes": [ { "active": true, "command": "sh", "dead": false, "height": 24, "id": "%0", "index": 0, "path": "/home/user/project", "pid": 3564863, "session_id": "$0", "title": "host", "width": 80, "window_id": "@0" } ]}AgentSplit the pane the list returned (%0) in two.
{ "pane_id": "%1"}AgentRead the window's layout.
{ "windows": [ { "active": true, "height": 24, "id": "@0", "index": 0, "layout": "8205,80x24,0,0{40x24,0,0,0,39x24,41,0,1}", "name": "sh", "pane_count": 2, "session_id": "$0", "width": 80 } ]}AgentRun the tests in the pane the list returned (%0).
{ "exit_code": 0, "pane_id": "%0", "text": ".. [100%]\n2 passed in 0.01s\n"}AgentShow the log in the new pane the split returned (%1).
{ "exit_code": 0, "pane_id": "%1", "text": "2026-01-01 checks started\n2026-01-01 checks finished\n"}AgentRemove the session once the result is read.
{ "deleted": true, "session_id": "$0"}pytest printed 2 passed and checks.log ends with checks finished. I removed the checks session.
libtmux-mcp-serverChoose your client and configuration scope, then run the command or paste the configuration.
$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ claude mcp add tmux -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ claude mcp add tmux --scope user -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ claude mcp add tmux --scope project -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local{
"mcpServers": {
"tmux": {
"command": "/absolute/path/to/libtmux-mcp-server"
}
}
}$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ codex mcp add tmux -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local[mcp_servers.tmux]
command = "/absolute/path/to/libtmux-mcp-server"$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ gemini mcp add --scope user tmux /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ gemini mcp add --scope project tmux /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local{
"mcpServers": {
"tmux": {
"command": "/absolute/path/to/libtmux-mcp-server"
}
}
}$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local{
"mcpServers": {
"tmux": {
"command": "/absolute/path/to/libtmux-mcp-server"
}
}
}$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ grok mcp add --scope user tmux -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ grok mcp add --scope project tmux -- /absolute/path/to/libtmux-mcp-server$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local{
"mcpServers": {
"tmux": {
"command": "/absolute/path/to/libtmux-mcp-server"
}
}
}$ cmake \
-S . \
-B build/mcp \
-DLIBTMUX_BUILD_MCP_SERVER=ON \
-DLIBTMUX_FETCH_DEPS=ON && \
cmake --build build/mcp && \
cmake --install build/mcp --prefix ~/.local$ opencode mcp add tmux -- /absolute/path/to/libtmux-mcp-serverWrites ~/.claude.json (this project).
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ~/.claude.json (all projects).
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes .mcp.json (in repo, version-controlled).
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ~/.codex/config.toml.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ~/.gemini/settings.json.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes .gemini/settings.json (in repo).
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ~/.grok/config.toml.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ./.grok/config.toml (in repo).
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Writes ~/.config/opencode/opencode.jsonc.
The MCP server is a build option rather than a second package, off by default because it is the only component that needs the JSON dependency. The install above puts libtmux-mcp-server in ~/.local/bin; use its full path.
Load a workspace file concept Working example; may change without notice. Read more Workspace Manager home →
A window of three panes.
session_name: 3-paneswindows: - window_name: dev window layout: main-vertical shell_command_before: - cd ~/ panes: - shell_command: - cd /var/log - ls -al | grep \.log - echo hello - echo hello{ "session_name": "3-panes", "windows": [ { "window_name": "dev window", "layout": "main-vertical", "shell_command_before": [ "cd ~/" ], "panes": [ { "shell_command": [ "cd /var/log", "ls -al | grep \\.log" ] }, "echo hello", "echo hello" ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/3-pane.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A pane can be one command written as a string, and a command list can be one string.
session_name: shorthandswindows: - window_name: long form panes: - shell_command: - echo 'did you know' - echo 'you can inline' - shell_command: echo 'single commands' - echo 'for panes'{ "session_name": "shorthands", "windows": [ { "window_name": "long form", "panes": [ { "shell_command": [ "echo 'did you know'", "echo 'you can inline'" ] }, { "shell_command": "echo 'single commands'" }, "echo 'for panes'" ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/shorthands.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A window of two panes.
session_name: workstart_directory: /tmpwindows: - window_name: editor layout: main-vertical panes: - shell_command: - echo first - echo second - echo lone - window_name: logs root: / panes: - shell_command: echo tail -{ "session_name": "work", "start_directory": "/tmp", "windows": [ { "window_name": "editor", "layout": "main-vertical", "panes": [ { "shell_command": [ "echo first", "echo second" ] }, "echo lone" ] }, { "window_name": "logs", "root": "/", "panes": [ { "shell_command": "echo tail" }, null ] } ]}
Workspace file: examples/workspace/tests/tmuxp_test.cpp.
Tested by ADocumentBecomesAWorkspace
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A window of four panes.
session_name: 4-pane-splitwindows: - window_name: dev window layout: tiled shell_command_before: - cd ~/ panes: - shell_command: - cd /var/log - ls -al | grep \.log - echo hello - echo hello - echo hello{ "session_name": "4-pane-split", "windows": [ { "window_name": "dev window", "layout": "tiled", "shell_command_before": [ "cd ~/" ], "panes": [ { "shell_command": [ "cd /var/log", "ls -al | grep \\.log" ] }, "echo hello", "echo hello", "echo hello" ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/4-pane.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
The main-horizontal layout gives the first pane the top of the window and splits the rest below it.
session_name: libtmuxstart_directory: /tmpshell_command_before: - echo setupwindows: - window_name: work focus: True layout: main-horizontal options: main-pane-height: 60% panes: - focus: true - echo second - window_name: docs shell_command_before: echo docs-setup panes: - echo only{ "session_name": "libtmux", "start_directory": "/tmp", "shell_command_before": [ "echo setup" ], "windows": [ { "window_name": "work", "focus": true, "layout": "main-horizontal", "options": { "main-pane-height": "60%" }, "panes": [ { "focus": true }, "echo second" ] }, { "window_name": "docs", "shell_command_before": "echo docs-setup", "panes": [ "echo only" ] } ]}
Workspace file: examples/workspace/tests/tmuxp_test.cpp.
Tested by EveryKeyTheDocumentCarriesReachesTheWorkspace
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
environment sets variables for a session, a window or a pane.
session_name: Environment variables testenvironment: EDITOR: /usr/bin/vim DJANGO_SETTINGS_MODULE: my_app.settings.local SERVER_PORT: "8009"windows: - window_name: Django project panes: - ./manage.py runserver 0.0.0.0:${SERVER_PORT} - window_name: Another Django project environment: DJANGO_SETTINGS_MODULE: my_app.settings.local SERVER_PORT: "8010" panes: - ./manage.py runserver 0.0.0.0:${SERVER_PORT} - environment: DJANGO_SETTINGS_MODULE: my_app.settings.local-testing SERVER_PORT: "8011" shell_command: ./manage.py runserver 0.0.0.0:${SERVER_PORT}{ "session_name": "Environment variables test", "environment": { "EDITOR": "/usr/bin/vim", "DJANGO_SETTINGS_MODULE": "my_app.settings.local", "SERVER_PORT": "8009" }, "windows": [ { "window_name": "Django project", "panes": [ "./manage.py runserver 0.0.0.0:${SERVER_PORT}" ] }, { "window_name": "Another Django project", "environment": { "DJANGO_SETTINGS_MODULE": "my_app.settings.local", "SERVER_PORT": "8010" }, "panes": [ "./manage.py runserver 0.0.0.0:${SERVER_PORT}", { "environment": { "DJANGO_SETTINGS_MODULE": "my_app.settings.local-testing", "SERVER_PORT": "8011" }, "shell_command": "./manage.py runserver 0.0.0.0:${SERVER_PORT}" } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/session-environment.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
start_directory chooses where a session, a window or a pane starts.
session_name: start directorystart_directory: /var/windows: - window_name: should be /var/ panes: - shell_command: - echo "\033c - it trickles down from session-level" - echo hello - window_name: should be /var/log start_directory: log panes: - shell_command: - echo '\033c - window start_directory concatenates to session start_directory - if it is not absolute' - echo hello - window_name: should be ~ start_directory: "~" panes: - shell_command: - 'echo \\033c ~ has precedence. note: remember to quote ~ in YAML' - echo hello - window_name: should be /bin start_directory: /bin panes: - echo '\033c absolute paths also have precedence.' - echo hello - window_name: should be workspace file's dir
start_directory: ./ panes: - shell_command: - echo '\033c - ./ is relative to workspace file location - ../ will be parent of workspace file - ./test will be \"test\" dir inside dir of workspace file' - shell_command: - echo '\033c - This way you can load up workspaces from projects and maintain - relative paths.'{ "session_name": "start directory", "start_directory": "/var/", "windows": [ { "window_name": "should be /var/", "panes": [ { "shell_command": [ "echo \"\\033c", "it trickles down from session-level\"" ] }, "echo hello" ] }, { "window_name": "should be /var/log", "start_directory": "log", "panes": [ { "shell_command": [ "echo '\\033c", "window start_directory concatenates to session start_directory", "if it is not absolute'" ] }, "echo hello" ] }, { "window_name": "should be ~", "start_directory": "~", "panes": [ { "shell_command": [ "echo \\\\033c ~ has precedence. note: remember to quote ~ in YAML" ] }, "echo hello" ] }, { "window_name": "should be /bin", "start_directory": "/bin", "panes": [ "echo '\\033c absolute paths also have precedence.'", "echo hello" ] }, { "window_name": "should be workspace file's dir", "start_directory": "./", "panes": [ { "shell_command": [ "echo '\\033c", "./ is relative to workspace file location", "../ will be parent of workspace file", "./test will be \\\"test\\\" dir inside dir of workspace file'" ] }, { "shell_command": [ "echo '\\033c", "This way you can load up workspaces from projects and maintain", "relative paths.'" ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/start-directory.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
options_after sets synchronize-panes once the panes exist, so typing in one pane reaches the others.
session_name: 2-pane-synchronizedwindows: - window_name: Two synchronized panes panes: - ssh server1 - ssh server2 options_after: synchronize-panes: on{ "session_name": "2-pane-synchronized", "windows": [ { "window_name": "Two synchronized panes", "panes": [ "ssh server1", "ssh server2" ], "options_after": { "synchronize-panes": "on" } } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/2-pane-synchronized.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
An empty entry, null, pane or blank opens a pane with no command.
session_name: Blank pane testwindows: # Emptiness will simply open a blank pane, if no shell_command_before. # All these are equivalent - window_name: Blank pane test panes: - - pane - blank - window_name: More blank panes panes: - null - shell_command: - shell_command: - # an empty string will be treated as a carriage return - window_name: Empty string (return) panes: - "" - shell_command: "" - shell_command: - "" # a pane can have other options but still be blank - window_name: Blank with options panes: - focus: true - start_directory: /tmp{ "session_name": "Blank pane test", "windows": [ { "window_name": "Blank pane test", "panes": [ null, "pane", "blank" ] }, { "window_name": "More blank panes", "panes": [ null, { "shell_command": null }, { "shell_command": [ null ] } ] }, { "window_name": "Empty string (return)", "panes": [ "", { "shell_command": "" }, { "shell_command": [ "" ] } ] }, { "window_name": "Blank with options", "panes": [ { "focus": true }, { "start_directory": "/tmp" } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/blank-panes.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
focus: true selects a window or a pane when the session is built.
session_name: focuswindows: - window_name: attached window focus: true panes: - shell_command: - echo hello - echo 'this pane should be selected on load' focus: true - shell_command: - cd /var/log - echo hello - window_name: second window shell_command_before: cd /var/log panes: - pane - shell_command: - echo 'this pane should be focused, when window switched to first time' focus: true - pane{ "session_name": "focus", "windows": [ { "window_name": "attached window", "focus": true, "panes": [ { "shell_command": [ "echo hello", "echo 'this pane should be selected on load'" ], "focus": true }, { "shell_command": [ "cd /var/log", "echo hello" ] } ] }, { "window_name": "second window", "shell_command_before": "cd /var/log", "panes": [ "pane", { "shell_command": [ "echo 'this pane should be focused, when window switched to first time'" ], "focus": true }, "pane" ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/focus-window-and-panes.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
main-pane-height takes a percentage of the window as well as a row count.
session_name: main-pane-heightstart_directory: "~"windows: - layout: main-horizontal options: main-pane-height: 67% panes: - shell_command: - top start_directory: "~" - shell_command: - echo "hey" - shell_command: - echo "moo" window_name: my window name{ "session_name": "main-pane-height", "start_directory": "~", "windows": [ { "layout": "main-horizontal", "options": { "main-pane-height": "67%" }, "panes": [ { "shell_command": [ "top" ], "start_directory": "~" }, { "shell_command": [ "echo \"hey\"" ] }, { "shell_command": [ "echo \"moo\"" ] } ], "window_name": "my window name" } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/main-pane-height-percentage.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A session name and one window with one blank pane.
session_name: My tmux sessionwindows: - panes: -{ "session_name": "My tmux session", "windows": [ { "panes": [ null ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/minimal.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
global_options, options and a window's options set tmux options.
session_name: test window optionsstart_directory: "~"global_options: default-shell: /bin/sh default-command: /bin/shoptions: main-pane-height: ${MAIN_PANE_HEIGHT} # works with env variableswindows: - layout: main-horizontal options: automatic-rename: on panes: - shell_command: - man echo start_directory: "~" - shell_command: - echo "hey" - shell_command: - echo "moo"{ "session_name": "test window options", "start_directory": "~", "global_options": { "default-shell": "/bin/sh", "default-command": "/bin/sh" }, "options": { "main-pane-height": "${MAIN_PANE_HEIGHT}" }, "windows": [ { "layout": "main-horizontal", "options": { "automatic-rename": "on" }, "panes": [ { "shell_command": [ "man echo" ], "start_directory": "~" }, { "shell_command": [ "echo \"hey\"" ] }, { "shell_command": [ "echo \"moo\"" ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/options.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A pane can start its own shell or program, and window_shell sets the default for a window.
session_name: Pane shell examplewindows: - window_name: first window_shell: /usr/bin/python2 layout: even-vertical suppress_history: false options: remain-on-exit: true panes: - shell: /usr/bin/python3 shell_command: - print('This is python 3') - shell: /usr/bin/vim -u none shell_command: - iAll panes have the `remain-on-exit` setting on. - When you exit out of the shell or application, the panes will remain. - Use tmux command `:kill-pane` to remove the pane. - Use tmux command `:respawn-pane` to restart the shell in the pane. - Use <Escape> and then `:q!` to get out of this vim window. :-) - shell_command: - print('Hello World 2') - shell: /usr/bin/top{ "session_name": "Pane shell example", "windows": [ { "window_name": "first", "window_shell": "/usr/bin/python2", "layout": "even-vertical", "suppress_history": false, "options": { "remain-on-exit": true }, "panes": [ { "shell": "/usr/bin/python3", "shell_command": [ "print('This is python 3')" ] }, { "shell": "/usr/bin/vim -u none", "shell_command": [ "iAll panes have the `remain-on-exit` setting on.", "When you exit out of the shell or application, the panes will remain.", "Use tmux command `:kill-pane` to remove the pane.", "Use tmux command `:respawn-pane` to restart the shell in the pane.", "Use <Escape> and then `:q!` to get out of this vim window. :-)" ] }, { "shell_command": [ "print('Hello World 2')" ] }, { "shell": "/usr/bin/top" } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/pane-shell.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
enter: false types a command without running it.
session_name: Skip command execution (command-level)windows: - panes: - shell_command: # You can see this - echo "___$((11 + 1))___" # This is skipped - cmd: echo "___$((1 + 3))___" enter: false{ "session_name": "Skip command execution (command-level)", "windows": [ { "panes": [ { "shell_command": [ "echo \"___$((11 + 1))___\"", { "cmd": "echo \"___$((1 + 3))___\"", "enter": false } ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/skip-send.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
enter: false on a pane types its commands without running them.
session_name: Skip command execution (pane-level)windows: - panes: - shell_command: echo "___$((1 + 3))___" enter: false - shell_command: - echo "___$((1 + 3))___"\; - echo "___$((1 + 3))___" enter: false{ "session_name": "Skip command execution (pane-level)", "windows": [ { "panes": [ { "shell_command": "echo \"___$((1 + 3))___\"", "enter": false }, { "shell_command": [ "echo \"___$((1 + 3))___\"\\;", "echo \"___$((1 + 3))___\"" ], "enter": false } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/skip-send-pane-level.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
sleep_before and sleep_after delay a command or the one after it.
session_name: Pause / skip command execution (command-level)windows: - panes: - shell_command: # Executes immediately - echo "___$((11 + 1))___" # Delays before sending 2 seconds - cmd: echo "___$((1 + 3))___" sleep_before: 2 # Executes immediately - cmd: echo "___$((1 + 3))___" # Pauses 2 seconds after - cmd: echo "Stuff rendering here!" sleep_after: 2 # Executes after earlier commands (after 2 sec) - cmd: echo "2 seconds later"{ "session_name": "Pause / skip command execution (command-level)", "windows": [ { "panes": [ { "shell_command": [ "echo \"___$((11 + 1))___\"", { "cmd": "echo \"___$((1 + 3))___\"", "sleep_before": 2 }, { "cmd": "echo \"___$((1 + 3))___\"" }, { "cmd": "echo \"Stuff rendering here!\"", "sleep_after": 2 }, { "cmd": "echo \"2 seconds later\"" } ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/sleep.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
sleep_before on a pane waits before it sends any of its commands.
session_name: Pause / skip command execution (pane-level)windows: - panes: - # Wait 2 seconds before sending all commands in this pane sleep_before: 2 shell_command: - echo "___$((11 + 1))___" - cmd: echo "___$((1 + 3))___" - cmd: echo "___$((1 + 3))___" - cmd: echo "Stuff rendering here!" - cmd: echo "2 seconds later"{ "session_name": "Pause / skip command execution (pane-level)", "windows": [ { "panes": [ { "sleep_before": 2, "shell_command": [ "echo \"___$((11 + 1))___\"", { "cmd": "echo \"___$((1 + 3))___\"" }, { "cmd": "echo \"___$((1 + 3))___\"" }, { "cmd": "echo \"Stuff rendering here!\"" }, { "cmd": "echo \"2 seconds later\"" } ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/sleep-pane-level.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
A setup command with sleep_before and sleep_after gives a virtualenv time to activate before the commands run.
session_name: virtualenvshell_command_before: # - cmd: source $(poetry env info --path)/bin/activate # - cmd: source `pipenv --venv`/bin/activate - cmd: source .venv/bin/activate sleep_before: 1 sleep_after: 1windows: - panes: - shell_command: - ./manage.py runserver{ "session_name": "virtualenv", "shell_command_before": [ { "cmd": "source .venv/bin/activate", "sleep_before": 1, "sleep_after": 1 } ], "windows": [ { "panes": [ { "shell_command": [ "./manage.py runserver" ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/sleep-virtualenv.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
suppress_history chooses whether commands reach the shell history, per session, window, pane or command.
session_name: suppresssuppress_history: falsewindows: - window_name: appended focus: true suppress_history: false panes: - echo "window in the history!"
- window_name: suppressed suppress_history: true panes: - echo "window not in the history!"
- window_name: default panes: - echo "session in the history!"
- window_name: mixed suppress_history: false panes: - shell_command: - echo "command in the history!" suppress_history: false - shell_command: - echo "command not in the history!" suppress_history: true - shell_command: - echo "window in the history!"{ "session_name": "suppress", "suppress_history": false, "windows": [ { "window_name": "appended", "focus": true, "suppress_history": false, "panes": [ "echo \"window in the history!\"" ] }, { "window_name": "suppressed", "suppress_history": true, "panes": [ "echo \"window not in the history!\"" ] }, { "window_name": "default", "panes": [ "echo \"session in the history!\"" ] }, { "window_name": "mixed", "suppress_history": false, "panes": [ { "shell_command": [ "echo \"command in the history!\"" ], "suppress_history": false }, { "shell_command": [ "echo \"command not in the history!\"" ], "suppress_history": true }, { "shell_command": [ "echo \"window in the history!\"" ] } ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/suppress-history.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
window_index places a window at an index; a window without one takes the lowest free index.
session_name: Window index examplewindows: - window_name: zero panes: - echo "this window's index will be zero" - window_name: five panes: - echo "this window's index will be five" window_index: 5 - window_name: one panes: - echo "this window's index will be one"{ "session_name": "Window index example", "windows": [ { "window_name": "zero", "panes": [ "echo \"this window's index will be zero\"" ] }, { "window_name": "five", "panes": [ "echo \"this window's index will be five\"" ], "window_index": 5 }, { "window_name": "one", "panes": [ "echo \"this window's index will be one\"" ] } ]}
Workspace file: examples/workspace/tests/fixtures/tmuxp/window-index.yaml.
Tested by EveryTmuxpExampleParses
(examples/workspace/tests/tmuxp_test.cpp; loaded by the library in a test; the command is not run).
tmux-workspaceThe workspace package is separate from the core library.
$ cmake --preset cxx-dev -DLIBTMUX_BUILD_WORKSPACE_CLI=ON && \
cmake --build --preset cxx-dev --target tmux-workspace --parallel 2$ tmux-workspace load ./workspace.yamlRun from a libtmux-cxx checkout with Clang 18.1.3, libc++ 18.1, CMake 3.25 or newer, and Ninja. The command is build/cxx-dev/apps/workspace/tmux-workspace.
Subject-by-subject, with C++ in every code block.
Task guides for C++.
Complete programs, sourced from the code each port tests.
The domain model every port shares.
Reference preview