API reference for the MuxWindow object in WezTerm’s Lua configuration
Available since version 20220624-141144-bd1b7c5d.
A MuxWindow object represents a window that is managed by the WezTerm multiplexer. It contains tabs and provides methods to manage them and the window’s state.MuxWindow objects represent the logical window in the multiplexer layer, as opposed to the GUI Window object which represents the physical GUI window.
local wezterm = require 'wezterm'wezterm.on('update-status', function(window, pane) local mux_win = window:mux_window() if mux_win then local tabs = mux_win:tabs() endend)
Returns the GUI Window object for this multiplexer window, if one exists.This is an async method because the GUI window may not exist yet (e.g., in a headless multiplexer scenario).Returns:Window | nil
wezterm.action_callback(function(window, pane) local mux_win = window:mux_window() if mux_win then -- This is async, so use in async context local gui_win = mux_win:gui_window() endend)
Returns an array of all tabs in this window.Returns:MuxTab[]
local tabs = mux_win:tabs()wezterm.log_info('Window has ', #tabs, ' tabs')for i, tab in ipairs(tabs) do wezterm.log_info('Tab ', i, ': ', tab:get_title())end
local tabs_info = mux_win:tabs_with_info()for _, info in ipairs(tabs_info) do local marker = info.is_active and '*' or ' ' wezterm.log_info( marker, ' Tab ', info.index, ': ', info.tab:get_title() )end
local wezterm = require 'wezterm'wezterm.on('update-status', function(window, pane) local mux_win = window:mux_window() if not mux_win then return end local workspace = mux_win:get_workspace() local tabs = mux_win:tabs() local status = string.format( 'WS:%s | Tabs:%d', workspace, #tabs ) window:set_left_status(status)end)
local wezterm = require 'wezterm'return { keys = { { key = 't', mods = 'CTRL|SHIFT', action = wezterm.action_callback(function(window, pane) local mux_win = window:mux_window() if mux_win then -- Get CWD from current pane local cwd_uri = pane:get_current_working_dir() local cwd = cwd_uri and cwd_uri.file_path or nil -- Spawn new tab in same directory local new_tab = mux_win:spawn_tab{ cwd = cwd, } new_tab:set_title('New Tab') end end), }, },}
local wezterm = require 'wezterm'local act = wezterm.actionreturn { keys = { { key = 'w', mods = 'CTRL|SHIFT', action = wezterm.action_callback(function(window, pane) local mux_win = window:mux_window() if not mux_win then return end local workspaces = {'default', 'development', 'testing', 'production'} local current_ws = mux_win:get_workspace() -- Find next workspace local current_idx = 1 for i, ws in ipairs(workspaces) do if ws == current_ws then current_idx = i break end end local next_idx = (current_idx % #workspaces) + 1 local next_ws = workspaces[next_idx] mux_win:set_workspace(next_ws) window:toast_notification( 'Workspace', 'Switched to: ' .. next_ws, nil, 2000 ) end), }, },}
local wezterm = require 'wezterm'wezterm.on('user-var-changed', function(window, pane, name, value) if name == 'LIST_TABS' then local mux_win = window:mux_window() if not mux_win then return end local tabs_info = mux_win:tabs_with_info() wezterm.log_info('=== Window Tabs ===') wezterm.log_info('Title: ', mux_win:get_title()) wezterm.log_info('Workspace: ', mux_win:get_workspace()) wezterm.log_info('Tab count: ', #tabs_info) wezterm.log_info('') for _, info in ipairs(tabs_info) do local marker = info.is_active and '→' or ' ' local tab = info.tab local panes = tab:panes() wezterm.log_info( string.format( '%s [%d] %s (%d panes)', marker, info.index, tab:get_title(), #panes ) ) end endend)
The MuxWindow is the logical window in the multiplexer, while the GUI Window is the physical window you see on screen:
MuxWindow: Exists in the multiplexer layer, can exist without a GUI (e.g., in wezterm cli contexts)
GUI Window: The actual rendered window with GUI-specific methods like set_right_status(), get_appearance(), etc.
In most GUI scenarios, you’ll have both:
wezterm.on('update-status', function(window, pane) -- window is the GUI Window local mux_win = window:mux_window() -- Get the MuxWindow -- GUI-specific operations window:set_right_status('Status') local appearance = window:get_appearance() -- Mux-specific operations local tabs = mux_win:tabs() local workspace = mux_win:get_workspace()end)