AgentCreate the session.
libtmux for TypeScript
TypeScript-based tmux client
tmux client library for TypeScript. 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 TypeScript code 0.x Released; the API may change. Read more Core Library home →
import { mkdtemp } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { setTimeout as delay } from "node:timers/promises";import { PaneDirection, Server } from "libtmux";
const directory = await mkdtemp(join(tmpdir(), "ltx-home-"));const server = new Server({ socketPath: join(directory, "tmux.sock"), configFile: "/dev/null", timeoutMs: 5_000,});
const signal = AbortSignal.timeout(5_000);const session = await server.newSession({ name: "demo", signal });
// Lay out the session: name its window, split it, add a second window.const editor = session.activeWindow;if (!editor) throw new Error("The session has no active window");await editor.rename("editor");
const left = editor.activePane;if (!left) throw new Error("The window has no active pane");const right = await left.split({ direction: PaneDirection.Right, signal,});const logs = await session.newWindow({ name: "logs", signal });
// Type a command into the new pane and wait for what it prints.await right.sendKeys("printf 'hello from %s\\n' tmux", { signal });
for (;;) { const lines = await right.capture({ signal }); if (lines.some((line) => line.includes("hello from tmux"))) break;
await delay(20, undefined, { signal });}
// Move the focus an attached client sees: the pane, then the window.await right.select();await logs.select();
// Walk the objects: down from the server, then up from one pane.const snapshot = await server.snapshot({ signal });for (const each of snapshot.sessions) { console.log("session", each.name); for (const window of each.windows) { const ids = window.panes.map((pane) => pane.id).join(" "); console.log(` window ${window.index}:${window.name}: ${ids}`); }}
const pane = snapshot.panes.one({ id: right.id });const home = pane.window;const owner = pane.session;if (!home || !owner) throw new Error("The pane has no window or session");console.log(pane.id, "is in window", home.name, "of session", owner.name);import { mkdtemp } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { setTimeout as delay } from "node:timers/promises";import { PaneDirection, Server } from "libtmux";
const directory = await mkdtemp(join(tmpdir(), "ltx-home-"));const server = new Server({ socketPath: join(directory, "tmux.sock"), configFile: "/dev/null", timeoutMs: 5_000,});
try { const signal = AbortSignal.timeout(5_000); const session = await server.newSession({ name: "demo", signal });
// Lay out the session: name its window, split it, add a second window. const editor = session.activeWindow; if (!editor) throw new Error("The session has no active window"); await editor.rename("editor");
const left = editor.activePane; if (!left) throw new Error("The window has no active pane"); const right = await left.split({ direction: PaneDirection.Right, signal, }); const logs = await session.newWindow({ name: "logs", signal });
// Type a command into the new pane and wait for what it prints. await right.sendKeys("printf 'hello from %s\\n' tmux", { signal });
for (;;) { const lines = await right.capture({ signal }); if (lines.some((line) => line.includes("hello from tmux"))) break;
await delay(20, undefined, { signal }); }
// Move the focus an attached client sees: the pane, then the window. await right.select(); await logs.select();
// Walk the objects: down from the server, then up from one pane. const snapshot = await server.snapshot({ signal }); for (const each of snapshot.sessions) { console.log("session", each.name); for (const window of each.windows) { const ids = window.panes.map((pane) => pane.id).join(" "); console.log(` window ${window.index}:${window.name}: ${ids}`); } }
const pane = snapshot.panes.one({ id: right.id }); const home = pane.window; const owner = pane.session; if (!home || !owner) throw new Error("The pane has no window or session"); console.log(pane.id, "is in window", home.name, "of session", owner.name);} catch (error) { throw new Error("tmux quickstart failed", { cause: error });}import { mkdtemp, readdir, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { setTimeout as delay } from "node:timers/promises";import { PaneDirection, Server } from "libtmux";
const directory = await mkdtemp(join(tmpdir(), "ltx-home-"));const server = new Server({ socketPath: join(directory, "tmux.sock"), configFile: "/dev/null", timeoutMs: 5_000,});
try { const signal = AbortSignal.timeout(5_000); const session = await server.newSession({ name: "demo", signal });
// Lay out the session: name its window, split it, add a second window. const editor = session.activeWindow; if (!editor) throw new Error("The session has no active window"); await editor.rename("editor");
const left = editor.activePane; if (!left) throw new Error("The window has no active pane"); const right = await left.split({ direction: PaneDirection.Right, signal, }); const logs = await session.newWindow({ name: "logs", signal });
// Type a command into the new pane and wait for what it prints. await right.sendKeys("printf 'hello from %s\\n' tmux", { signal });
for (;;) { const lines = await right.capture({ signal }); if (lines.some((line) => line.includes("hello from tmux"))) break;
await delay(20, undefined, { signal }); }
// Move the focus an attached client sees: the pane, then the window. await right.select(); await logs.select();
// Walk the objects: down from the server, then up from one pane. const snapshot = await server.snapshot({ signal }); for (const each of snapshot.sessions) { console.log("session", each.name); for (const window of each.windows) { const ids = window.panes.map((pane) => pane.id).join(" "); console.log(` window ${window.index}:${window.name}: ${ids}`); } }
const pane = snapshot.panes.one({ id: right.id }); const home = pane.window; const owner = pane.session; if (!home || !owner) throw new Error("The pane has no window or session"); console.log(pane.id, "is in window", home.name, "of session", owner.name);} finally { if ((await readdir(directory)).includes("tmux.sock")) { await server.kill(); } await rm(directory, { recursive: true });}import { mkdtemp, readdir, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { setTimeout as delay } from "node:timers/promises";import { PaneDirection, Server } from "libtmux";
const directory = await mkdtemp(join(tmpdir(), "ltx-home-"));const server = new Server({ socketPath: join(directory, "tmux.sock"), configFile: "/dev/null", timeoutMs: 5_000,});
const failures: unknown[] = [];try { const signal = AbortSignal.timeout(5_000); const session = await server.newSession({ name: "demo", signal });
// Lay out the session: name its window, split it, add a second window. const editor = session.activeWindow; if (!editor) throw new Error("The session has no active window"); await editor.rename("editor");
const left = editor.activePane; if (!left) throw new Error("The window has no active pane"); const right = await left.split({ direction: PaneDirection.Right, signal, }); const logs = await session.newWindow({ name: "logs", signal });
// Type a command into the new pane and wait for what it prints. await right.sendKeys("printf 'hello from %s\\n' tmux", { signal });
for (;;) { const lines = await right.capture({ signal }); if (lines.some((line) => line.includes("hello from tmux"))) break;
await delay(20, undefined, { signal }); }
// Move the focus an attached client sees: the pane, then the window. await right.select(); await logs.select();
// Walk the objects: down from the server, then up from one pane. const snapshot = await server.snapshot({ signal }); for (const each of snapshot.sessions) { console.log("session", each.name); for (const window of each.windows) { const ids = window.panes.map((pane) => pane.id).join(" "); console.log(` window ${window.index}:${window.name}: ${ids}`); } }
const pane = snapshot.panes.one({ id: right.id }); const home = pane.window; const owner = pane.session; if (!home || !owner) throw new Error("The pane has no window or session"); console.log(pane.id, "is in window", home.name, "of session", owner.name);} catch (error) { failures.push(error);}
try { if ((await readdir(directory)).includes("tmux.sock")) { await server.kill(); }
await rm(directory, { recursive: true });} catch (error) { failures.push(new Error(`Cleanup failed: ${directory}`, { cause: error, }));}
if (failures.length) throw new AggregateError(failures);tmux before the first call: no server is running.
tmux after Server: no server is running; the call sent no command.
tmux after Server.newSession: added session demo.
tmux after Session.activeWindow: unchanged, the call sent no command.
tmux after Window.rename: renamed window 0:sh to 0:editor.
tmux after Window.activePane: unchanged, the call sent no command.
tmux after Pane.split: added pane %1 to window 0:editor.
tmux after Session.newWindow: added window 1:logs.
tmux after Pane.sendKeys: sent keys to pane %1.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.capture: 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.snapshot: unchanged.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.panes: unchanged, the call sent no command.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Window.panes: unchanged, the call sent no command.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Selection.one: unchanged, the call sent no command.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.window: unchanged, the call sent no command.
$ printf 'hello from %s\n' tmux hello from tmux $
tmux after Pane.session: unchanged, the call sent no command.
tmux after Server.kill: the server has exited.
-
Before the first call
No tmux server is running yet.
- {"socketPath": "/tmp/tmp/ltx-home-ssDQbg/tmux.sock","configFile": "/dev/null"}
The call sent no tmux command.
-
Server.newSessionreturnedPromise<Session>{"id": "$0","name": "demo"}5 tmux commands, 3 that change tmux
-
run-shell -C libtmux-version-11bb768ca3864f8eabfe834a5d20993c-#{version}/#{pid}/#{start_time}error connecting to /tmp/tmp/ltx-home-ssDQbg/tmux.sock (No such file or directory) -
display-message -p #{version}tmux 3.8a -
new-session -d -P -F #{session_id} -s demo$0 -
run-shell -C libtmux-version-26d13899b699466dbdeaf7e49a137ed0-#{version}/#{pid}/#{start_time}unknown command: libtmux-version-26d13899b699466dbdeaf7e49a137ed0-3.8a/2953902/1793886660 -
display-message -p 'ltxI#{pid};#{start_time}' ; list-sessions '-FltxSa7b5fc4bcf264d51a1318868#{q:active_window_index};#{q:alternate_on};#{q:alternate_saved_x};#{q:alternate_saved_y};#{q:bracket_paste_flag};#{q:config_files};#{q:cursor_blinking};#{q:cursor_character};#{q:cursor_colour};#{q:cursor_flag};#{q:cursor_shape};#{q:cursor_very_visible};#{q:cursor_x};#{q:cursor_y};#{q:history_all_bytes};#{q…ltxI2953902;1793886660 ltxSa7b5fc4bcf264d51a13188680;0;4294967295;4294967295;0;/dev/null;0;\ ;none;1;default;0;2;0;24,960,20,100,0,0;1060;2000;0;0;0;0;0;0;0;0;0;0;0;\$1;0;1;1;1;1;1;default;23;sh;/tmp/marked;0;;;;default;\*;0;0;24;\%0;0;0;0;VT10x;0;0;0;0;;;0;hidden;2953903;0;;79;;;/tmp/marked;0;8,16,24,32,40,48,56,64,72;host;0;/dev/pts/14;0;80;0;0;1;0;2953902;23…
-
-
Session.activeWindowreturnedWindow | undefined{"id": "@0","index": 0,"name": "sh"}The call sent no tmux command.
-
Window.renamereturnedPromise<void>null1 tmux command, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-6c3cedd2c0d648faa7feed4e38a15083 ; rename-window -t @0 -- editorno output
-
-
Window.activePanereturnedPane | undefined{"id": "%0"}The call sent no tmux command.
-
Pane.splitreturnedPromise<Pane>{"id": "%1"}2 tmux commands, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-a2dd59b3d4be414fa474ecea75efbd52 ; split-window -d -P -F #{pane_id} -h -t %0%1 -
display-message -p 'ltxI#{pid};#{start_time}' ; list-sessions '-FltxS522ac4d5c0084153add34415#{q:active_window_index};#{q:alternate_on};#{q:alternate_saved_x};#{q:alternate_saved_y};#{q:bracket_paste_flag};#{q:config_files};#{q:cursor_blinking};#{q:cursor_character};#{q:cursor_colour};#{q:cursor_flag};#{q:cursor_shape};#{q:cursor_very_visible};#{q:cursor_x};#{q:cursor_y};#{q:history_all_bytes};#{q…ltxI2953902;1793886660 ltxS522ac4d5c0084153add344150;0;4294967295;4294967295;0;/dev/null;0;\ ;none;1;default;0;2;0;24,960,20,100,0,0;1060;2000;0;0;0;0;0;0;0;0;0;0;0;\$1;0;1;1;1;0;1;default;23;sh;/tmp/marked;0;;;;default;\*;0;0;24;\%0;0;0;0;VT10x;0;0;0;0;;;0;hidden;2953903;0;;39;;;/tmp/marked;0;8,16,24,32;host;0;/dev/pts/14;0;40;0;0;1;0;2953902;23;0;0;1793886660…
-
-
Session.newWindowreturnedPromise<Window>{"id": "@1","index": 1,"name": "logs"}2 tmux commands, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-cac7e03aabca4d1598edecfeecd1903b ; new-window -d -P -F #{window_id} -t $0 -n logs@1 -
display-message -p 'ltxI#{pid};#{start_time}' ; list-sessions '-FltxSca11577966ac4aeaa51bda2c#{q:active_window_index};#{q:alternate_on};#{q:alternate_saved_x};#{q:alternate_saved_y};#{q:bracket_paste_flag};#{q:config_files};#{q:cursor_blinking};#{q:cursor_character};#{q:cursor_colour};#{q:cursor_flag};#{q:cursor_shape};#{q:cursor_very_visible};#{q:cursor_x};#{q:cursor_y};#{q:history_all_bytes};#{q…ltxI2953902;1793886660 ltxSca11577966ac4aeaa51bda2c0;0;4294967295;4294967295;0;/dev/null;0;\ ;none;1;default;0;2;0;24,960,20,100,0,0;1060;2000;0;0;0;0;1;0;0;0;0;0;0;\$1;0;1;1;1;0;1;default;23;sh;/tmp/marked;0;;;;default;\*;0;0;24;\%0;0;0;0;VT10x;0;0;0;0;;;0;hidden;2953903;0;;39;;;/tmp/marked;0;8,16,24,32;host;0;/dev/pts/14;0;40;0;0;1;0;2953902;23;0;0;1793886660…
-
-
Pane.sendKeysreturnedPromise<void>null1 tmux command, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-414e7427b7394844a0d628873848587b ; send-keys -t %1 -- 'printf '\''hello from %s\n'\'' tmux' ; send-keys -t %1 Enterno output
-
-
Pane.capturereturnedPromise<readonly string[]>["$ printf 'hello from %s\\n' tmux","hello from tmux","$"]1 tmux command
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-f5c9a2f59fdd4914bb3f881033f728d6 ; capture-pane -p -t %1$ printf 'hello from %s\n' tmux hello from tmux $
-
-
Pane.selectreturnedPromise<void>null1 tmux command, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-6cad1a8ba26a4aad9e5d15d56cef0e23 ; select-pane -t %1no output
-
-
Window.selectreturnedPromise<void>null1 tmux command, 1 that changes tmux
-
if-shell -F #{==:#{version},3.8a} '' libtmux-version-872e70632d4045a5b2012d3388e29fbb ; select-window -t $0:1no output
-
-
Server.snapshotreturnedPromise<ServerSnapshot>{"sessions": 1,"windows": 2,"panes": 3}1 tmux command
-
display-message -p 'ltxI#{pid};#{start_time}' ; list-sessions '-FltxSbee1dee5ae984eec847e19cf#{q:active_window_index};#{q:alternate_on};#{q:alternate_saved_x};#{q:alternate_saved_y};#{q:bracket_paste_flag};#{q:config_files};#{q:cursor_blinking};#{q:cursor_character};#{q:cursor_colour};#{q:cursor_flag};#{q:cursor_shape};#{q:cursor_very_visible};#{q:cursor_x};#{q:cursor_y};#{q:history_all_bytes};#{q…ltxI2953902;1793886660 ltxSbee1dee5ae984eec847e19cf1;0;4294967295;4294967295;0;/dev/null;0;\ ;none;1;default;0;2;0;24,960,20,100,0,0;1060;2000;0;0;0;0;1;0;0;0;0;0;0;\$1;0;1;1;1;1;1;default;23;sh;/tmp/marked;0;;;;default;\*;0;0;24;\%2;0;0;0;VT10x;0;0;0;0;;;0;hidden;2954248;0;;79;;;/tmp/marked;0;8,16,24,32,40,48,56,64,72;host;0;/dev/pts/17;0;80;0;0;1;0;2953902;23…
-
-
Window.panesreturnedSelection<Pane>{"panes": "%0 %1"}The call sent no tmux command.
-
Window.panesreturnedSelection<Pane>{"panes": "%2"}The call sent no tmux command.
-
Selection.onereturnedPane{"id": "%1"}The call sent no tmux command.
-
Pane.windowreturnedWindow | undefined{"id": "@0","index": 0,"name": "editor"}The call sent no tmux command.
-
Pane.sessionreturnedSession | undefined{"id": "$0","name": "demo"}The call sent no tmux command.
-
Server.killreturnedPromise<void>null1 tmux command, 1 that changes tmux
-
kill-serverno output
-
Run this example
POSIX shell, tmux 3.3a or newer and Bun 1.4.2.
Save the program above as quickstart.ts 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.json
{"type":"module","private":true,"dependencies":{"libtmux":"0.1.2"}}Setup and run
bun installunset TMUX TMUX_PANEexport ENV=/dev/null BASH_ENV=/dev/null SHELL=/bin/shbun run quickstart.tsExpected output
session demo window 0:editor: %0 %1 window 1:logs: %2%1 is in window editor of session demoInstall libtmux
$ npm install libtmux$ npm install \
--min-release-age=7 \
--min-release-age-exclude=libtmux \
libtmux$ npm install --min-release-age=0 libtmux$ pnpm add libtmux$ pnpm_config_minimum_release_age=10080 \
pnpm_config_minimum_release_age_exclude='["libtmux"]' \
pnpm add libtmux$ pnpm_config_minimum_release_age=0 pnpm add libtmux$ yarn add libtmux$ YARN_NPM_MINIMAL_AGE_GATE=7d \
YARN_NPM_PREAPPROVED_PACKAGES=libtmux \
yarn add libtmux$ YARN_NPM_MINIMAL_AGE_GATE=0 yarn add libtmux$ bun add libtmux$ bun add libtmux$ bun add --minimum-release-age=0 libtmux$ git clone --branch v0.1.2 https://github.com/libtmux/libtmux-ts \
&& bun add ./libtmux-ts/packages/libtmuxPins 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
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.
AgentSplit the pane the create result returned (%0) in two.
AgentRead the window's layout.
AgentRun the tests in the pane the create result returned (%0).
AgentShow the log in the new pane the split returned (%1).
AgentRemove the session once the result is read.
Requests only: no recorded results for TypeScript yet.
Install @libtmux/mcp
Choose your client and configuration scope, then run the command or paste the configuration.
$ claude mcp add tmux -- npx -y @libtmux/mcp$ claude mcp add tmux -- npx -y @libtmux/mcp$ claude mcp add tmux -- npx -y --min-release-age=0 @libtmux/mcp$ claude mcp add tmux --scope user -- npx -y @libtmux/mcp$ claude mcp add tmux --scope user -- npx -y @libtmux/mcp$ claude mcp add tmux --scope user -- npx -y --min-release-age=0 @libtmux/mcp$ claude mcp add tmux --scope project -- npx -y @libtmux/mcp$ claude mcp add tmux --scope project -- npx -y @libtmux/mcp$ claude mcp add tmux --scope project -- npx -y --min-release-age=0 @libtmux/mcp$ npm install --global @libtmux/mcp$ claude mcp add tmux -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ claude mcp add tmux -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ claude mcp add tmux -- libtmux-mcp$ npm install --global @libtmux/mcp$ claude mcp add tmux --scope user -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ claude mcp add tmux --scope user -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ claude mcp add tmux --scope user -- libtmux-mcp$ npm install --global @libtmux/mcp$ claude mcp add tmux --scope project -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ claude mcp add tmux --scope project -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ claude mcp add tmux --scope project -- libtmux-mcp{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "--min-release-age=0", "@libtmux/mcp"]
}
}
}$ npm install --global @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global --min-release-age=0 @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ codex mcp add tmux -- npx -y @libtmux/mcp$ codex mcp add tmux -- npx -y @libtmux/mcp$ codex mcp add tmux -- npx -y --min-release-age=0 @libtmux/mcp[mcp_servers.tmux]
command = "npx"
args = ["-y", "@libtmux/mcp"][mcp_servers.tmux]
command = "npx"
args = ["-y", "@libtmux/mcp"][mcp_servers.tmux]
command = "npx"
args = ["-y", "--min-release-age=0", "@libtmux/mcp"]$ npm install --global @libtmux/mcp$ codex mcp add tmux -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ codex mcp add tmux -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ codex mcp add tmux -- libtmux-mcp$ npm install --global @libtmux/mcp[mcp_servers.tmux]
command = "libtmux-mcp"$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp[mcp_servers.tmux]
command = "libtmux-mcp"$ npm install --global --min-release-age=0 @libtmux/mcp[mcp_servers.tmux]
command = "libtmux-mcp"$ gemini mcp add --scope user tmux npx -- -y @libtmux/mcp$ gemini mcp add --scope user tmux npx -- -y @libtmux/mcp$ gemini mcp add --scope user tmux npx -- -y --min-release-age=0 @libtmux/mcp$ gemini mcp add --scope project tmux npx -- -y @libtmux/mcp$ gemini mcp add --scope project tmux npx -- -y @libtmux/mcp$ gemini mcp add --scope project tmux npx -- -y --min-release-age=0 @libtmux/mcp$ npm install --global @libtmux/mcp$ gemini mcp add --scope user tmux libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ gemini mcp add --scope user tmux libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ gemini mcp add --scope user tmux libtmux-mcp$ npm install --global @libtmux/mcp$ gemini mcp add --scope project tmux libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ gemini mcp add --scope project tmux libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ gemini mcp add --scope project tmux libtmux-mcp{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "--min-release-age=0", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "--min-release-age=0", "@libtmux/mcp"]
}
}
}$ npm install --global @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global --min-release-age=0 @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global --min-release-age=0 @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ grok mcp add --scope user tmux -- npx -y @libtmux/mcp$ grok mcp add --scope user tmux -- npx -y @libtmux/mcp$ grok mcp add --scope user tmux -- npx -y --min-release-age=0 @libtmux/mcp$ grok mcp add --scope project tmux -- npx -y @libtmux/mcp$ grok mcp add --scope project tmux -- npx -y @libtmux/mcp$ grok mcp add --scope project tmux -- npx -y --min-release-age=0 @libtmux/mcp$ npm install --global @libtmux/mcp$ grok mcp add --scope user tmux -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ grok mcp add --scope user tmux -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ grok mcp add --scope user tmux -- libtmux-mcp$ npm install --global @libtmux/mcp$ grok mcp add --scope project tmux -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ grok mcp add --scope project tmux -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ grok mcp add --scope project tmux -- libtmux-mcp{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "@libtmux/mcp"]
}
}
}{
"mcpServers": {
"tmux": {
"command": "npx",
"args": ["-y", "--min-release-age=0", "@libtmux/mcp"]
}
}
}$ npm install --global @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ npm install --global --min-release-age=0 @libtmux/mcp{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ opencode mcp add tmux -- npx -y @libtmux/mcp$ opencode mcp add tmux -- npx -y @libtmux/mcp$ opencode mcp add tmux -- npx -y --min-release-age=0 @libtmux/mcp$ npm install --global @libtmux/mcp$ opencode mcp add tmux -- libtmux-mcp$ npm install --global \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/mcp \
--min-release-age-exclude=libtmux \
@libtmux/mcp$ opencode mcp add tmux -- libtmux-mcp$ npm install --global --min-release-age=0 @libtmux/mcp$ opencode mcp add tmux -- libtmux-mcpWrites ~/.claude.json (this project).
Writes ~/.claude.json (this project).
Writes ~/.claude.json (this project).
Writes ~/.claude.json (all projects).
Writes ~/.claude.json (all projects).
Writes ~/.claude.json (all projects).
Writes .mcp.json (in repo, version-controlled).
Writes .mcp.json (in repo, version-controlled).
Writes .mcp.json (in repo, version-controlled).
Writes ~/.claude.json (this project).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.claude.json (this project).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.claude.json (this project).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.claude.json (all projects).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.claude.json (all projects).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.claude.json (all projects).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .mcp.json (in repo, version-controlled).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .mcp.json (in repo, version-controlled).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .mcp.json (in repo, version-controlled).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.codex/config.toml.
Writes ~/.codex/config.toml.
Writes ~/.codex/config.toml.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
Writes ~/.codex/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.codex/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.codex/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.gemini/settings.json.
Writes ~/.gemini/settings.json.
Writes ~/.gemini/settings.json.
Writes .gemini/settings.json (in repo).
Writes .gemini/settings.json (in repo).
Writes .gemini/settings.json (in repo).
Writes ~/.gemini/settings.json.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.gemini/settings.json.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.gemini/settings.json.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .gemini/settings.json (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .gemini/settings.json (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes .gemini/settings.json (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.grok/config.toml.
Writes ~/.grok/config.toml.
Writes ~/.grok/config.toml.
Writes ./.grok/config.toml (in repo).
Writes ./.grok/config.toml (in repo).
Writes ./.grok/config.toml (in repo).
Writes ~/.grok/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.grok/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.grok/config.toml.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ./.grok/config.toml (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ./.grok/config.toml (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ./.grok/config.toml (in repo).
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.config/opencode/opencode.jsonc.
Writes ~/.config/opencode/opencode.jsonc.
Writes ~/.config/opencode/opencode.jsonc.
Writes ~/.config/opencode/opencode.jsonc.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.config/opencode/opencode.jsonc.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Writes ~/.config/opencode/opencode.jsonc.
The package installs a libtmux-mcp binary. Requires Node 22 or newer, or Bun 1.3.14 or newer.
Embed the server in a program
export async function connectAgent(server: Server): Promise<Client> { const client = new Client({ name: "example", version: "0.0.0" }); const [clientSide, serverSide] = InMemoryTransport.createLinkedPair(); await Promise.all([ createTmuxMcpServer(server, { environment: { LIBTMUX_TOOLSETS: "inspect,execute" }, }).connect(serverSide), client.connect(clientSide), ]); return client;}
Excerpt of examples/mcp-agent/mcp-agent.ts.
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 →
Three panes
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" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/3-pane.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Short-hand panes
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'" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/shorthands.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Two panes
A window of two panes.
session_name: 2-pane-verticalwindows: - window_name: my test window panes: - echo hello - echo hello{ "session_name": "2-pane-vertical", "windows": [ { "window_name": "my test window", "panes": [ "echo hello", "echo hello" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/2-pane-vertical.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Four panes
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" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/4-pane.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Main-horizontal layout
The main-horizontal layout gives the first pane the top of the window and splits the rest below it.
session_name: main-pane-heightstart_directory: "~"windows: - layout: main-horizontal options: main-pane-height: 30 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": 30 }, "panes": [ { "shell_command": [ "top" ], "start_directory": "~" }, { "shell_command": [ "echo \"hey\"" ] }, { "shell_command": [ "echo \"moo\"" ] } ], "window_name": "my window name" } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/main-pane-height.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Environment
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}" } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/session-environment.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Start directory
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.'" ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/start-directory.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Synchronized panes
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" } } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/2-pane-synchronized.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Blank panes
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" } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/blank-panes.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Variables in values
A ${VAR} in a name, a path or an option expands from the environment of the loading process.
start_directory: "${PWD}/test"shell_command_before: "echo ${PWD}"before_script: "${MY_ENV_VAR}/test3.sh"session_name: session - ${USER} (${MY_ENV_VAR})windows: - window_name: editor panes: - shell_command: - tail -F /var/log/syslog start_directory: /var/log - window_name: logging for ${USER} options: automatic-rename: true panes: - shell_command: - htop - ls $PWD{ "start_directory": "${PWD}/test", "shell_command_before": "echo ${PWD}", "before_script": "${MY_ENV_VAR}/test3.sh", "session_name": "session - ${USER} (${MY_ENV_VAR})", "windows": [ { "window_name": "editor", "panes": [ { "shell_command": [ "tail -F /var/log/syslog" ] } ], "start_directory": "/var/log" }, { "window_name": "logging for ${USER}", "options": { "automatic-rename": true }, "panes": [ { "shell_command": [ "htop", "ls $PWD" ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/env-variables.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Focus
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" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/focus-window-and-panes.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Main pane height as a percentage
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" } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/main-pane-height-percentage.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Minimal workspace
A session name and one window with one blank pane.
session_name: My tmux sessionwindows: - panes: -{ "session_name": "My tmux session", "windows": [ { "panes": [ null ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/minimal.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
tmux options
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\"" ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/options.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; 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: 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" } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/pane-shell.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Skip Enter for a command
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 } ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/skip-send.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Skip Enter for a pane
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 } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/skip-send-pane-level.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Pause around a command
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\"" } ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/sleep.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Pause before a pane
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\"" } ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/sleep-pane-level.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Wait for a virtualenv
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" ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/sleep-virtualenv.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Keep commands out of history
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!\"" ] } ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/suppress-history.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Window index
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\"" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: packages/workspace-cli/tests/fixtures/tmuxp-examples/window-index.yaml.
Tested by every tmuxp example workspace loads through the CLI
(packages/workspace-cli/tests/tmuxp-examples.test.ts; a test runs the command).
Install @libtmux/workspace-cli
The workspace package is separate from the core library.
$ npx -y @libtmux/workspace-cli --help$ npx -y @libtmux/workspace-cli --help$ npx -y --min-release-age=0 @libtmux/workspace-cli --help$ bunx --bun @libtmux/workspace-cli --help$ bunx --bun @libtmux/workspace-cli --help$ bunx --bun --minimum-release-age=0 @libtmux/workspace-cli --help$ pnpm dlx @libtmux/workspace-cli --help$ EXCLUDE='["@libtmux/workspace-cli","libtmux"]' && \
pnpm_config_minimum_release_age=10080 \
pnpm_config_minimum_release_age_exclude="$EXCLUDE" \
pnpm dlx @libtmux/workspace-cli --help$ pnpm_config_minimum_release_age=0 pnpm dlx @libtmux/workspace-cli --help$ yarn dlx @libtmux/workspace-cli --help$ YARN_NPM_MINIMAL_AGE_GATE=7d \
YARN_NPM_PREAPPROVED_PACKAGES=@libtmux/workspace-cli,libtmux \
yarn dlx @libtmux/workspace-cli --help$ YARN_NPM_MINIMAL_AGE_GATE=0 yarn dlx @libtmux/workspace-cli --help$ npm install -g @libtmux/workspace-cli$ npm install -g \
--min-release-age=7 \
--min-release-age-exclude=@libtmux/workspace-cli \
--min-release-age-exclude=libtmux \
@libtmux/workspace-cli$ npm install -g --min-release-age=0 @libtmux/workspace-cli$ tmux-workspace load ./workspace.yaml$ pnpm add -g @libtmux/workspace-cli$ EXCLUDE='["@libtmux/workspace-cli","libtmux"]' && \
pnpm_config_minimum_release_age=10080 \
pnpm_config_minimum_release_age_exclude="$EXCLUDE" \
pnpm add -g @libtmux/workspace-cli$ pnpm_config_minimum_release_age=0 pnpm add -g @libtmux/workspace-cli$ tmux-workspace load ./workspace.yaml$ bun add -g @libtmux/workspace-cli$ bun add -g @libtmux/workspace-cli$ bun add -g --minimum-release-age=0 @libtmux/workspace-cli$ tmux-workspace load ./workspace.yamlRuns tmux-workspace without installing it. Pass a command such as load ./workspace.yaml in place of --help.
--bun runs the command on Bun. Without it, bunx runs the command on Node when Node is installed, because its shebang names node.
Yarn refuses a release younger than its npmMinimalAgeGate, one day by default.
Puts tmux-workspace on PATH, so a workspace loads with tmux-workspace load ./workspace.yaml.
Build the workspace from a program
export const DEVELOPMENT_WORKSPACE = { session_name: "workspace-example", windows: [ { panes: ["sleep 30", "sleep 30"], window_name: "editor" }, { panes: ["sleep 30"], window_name: "server" }, { window_name: "logs" }, ],} satisfies WorkspaceInput;
/** Apply the package's declarative workspace to a server. */export function buildWorkspace(server: Server): Promise<Session> { return applyWorkspace(server, DEVELOPMENT_WORKSPACE);}
Excerpt of examples/workspace/workspace.ts.
This program is tested on every change.
Topics
Subject-by-subject, with TypeScript in every code block.
Guides
Task guides for TypeScript.
Examples
Complete programs, sourced from the code each port tests.
Concepts
The domain model every port shares.