AgentCreate the session.
Result
{ "sessionId": "$0", "sessionName": "checks"}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.
Go-based tmux client
tmux client library for Go. 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 Go code 0.x Released; the API may change. Read more Core Library home →
// Command quickstart lays out a tmux session, then walks it as objects.package main
import ( "context" "fmt" "log" "os"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := run(context.Background()); err != nil { log.Fatal(err) }}
func run(ctx context.Context) error { // A private server: a socket and an empty config of its own, so this // neither touches nor is changed by a tmux you already use. // The process ID in the socket name keeps one run apart from the next. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: fmt.Sprintf("libtmux-quickstart-%d", os.Getpid()), ConfigFile: os.DevNull, }) if err != nil { return err } session, err := server.NewSession(ctx, tmux.NewSessionRequest{ Name: "demo", }) if err != nil { return err }
// Lay out the session: name its window, split it, add a second window. editor, err := session.ResolveActiveWindow(ctx) if err != nil { return err } editor, err = editor.Rename(ctx, "editor") if err != nil { return err } left, err := editor.ResolveActivePane(ctx) if err != nil { return err } right, err := left.Split(ctx, tmux.SplitPaneRequest{ Direction: tmux.PaneDirectionRight, }) if err != nil { return err } name := "logs" logs, err := session.NewWindow(ctx, tmux.NewWindowRequest{ Name: &name, }) if err != nil { return err }
// Type a command into the new pane and wait for what it prints. command := "printf 'hello from %s\\n' tmux" err = right.SendKeys(ctx, tmux.SendKeysRequest{Command: &command}) if err != nil { return err } _, err = right.WaitForText(ctx, tmux.WaitForTextRequest{ Text: "hello from tmux", }) if err != nil { return err }
// Move the focus an attached client sees: the pane, then the window. _, err = right.Select(ctx, tmux.PaneSelectRequest{}) if err != nil { return err } _, err = logs.Select(ctx) if err != nil { return err }
// Walk the objects: down from the server, then up from one pane. snapshot, err := server.Snapshot(ctx) if err != nil { return err } for _, each := range snapshot.Sessions() { sessionName, _ := each.Name() fmt.Println("session", sessionName) windows, _ := each.Windows() for _, window := range windows { name, _ := window.Name() fmt.Printf(" window %d:%s:", window.Index(), name) panes, _ := window.Panes() for _, pane := range panes { fmt.Print(" ", pane.ID()) } fmt.Println() } } pane, _ := snapshot.PaneByID(right.ID()) window, _ := pane.Window() owner, _ := window.Session() windowName, _ := window.Name() sessionName, _ := owner.Name() fmt.Println(pane.ID(), "is in window", windowName, "of session", sessionName) return nil}// Command quickstart lays out a tmux session, then walks it as objects.package main
import ( "context" "fmt" "log" "os"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := run(context.Background()); err != nil { log.Fatal(err) }}
func run(ctx context.Context) error { // A private server: a socket and an empty config of its own, so this // neither touches nor is changed by a tmux you already use. // The process ID in the socket name keeps one run apart from the next. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: fmt.Sprintf("libtmux-quickstart-%d", os.Getpid()), ConfigFile: os.DevNull, }) if err != nil { return fmt.Errorf("configure tmux: %w", err) } session, err := server.NewSession(ctx, tmux.NewSessionRequest{ Name: "demo", }) if err != nil { return fmt.Errorf("create session: %w", err) }
// Lay out the session: name its window, split it, add a second window. editor, err := session.ResolveActiveWindow(ctx) if err != nil { return fmt.Errorf("find window: %w", err) } editor, err = editor.Rename(ctx, "editor") if err != nil { return fmt.Errorf("rename window: %w", err) } left, err := editor.ResolveActivePane(ctx) if err != nil { return fmt.Errorf("find pane: %w", err) } right, err := left.Split(ctx, tmux.SplitPaneRequest{ Direction: tmux.PaneDirectionRight, }) if err != nil { return fmt.Errorf("split pane: %w", err) } name := "logs" logs, err := session.NewWindow(ctx, tmux.NewWindowRequest{ Name: &name, }) if err != nil { return fmt.Errorf("add window: %w", err) }
// Type a command into the new pane and wait for what it prints. command := "printf 'hello from %s\\n' tmux" err = right.SendKeys(ctx, tmux.SendKeysRequest{Command: &command}) if err != nil { return fmt.Errorf("send keys: %w", err) } _, err = right.WaitForText(ctx, tmux.WaitForTextRequest{ Text: "hello from tmux", }) if err != nil { return fmt.Errorf("wait for output: %w", err) }
// Move the focus an attached client sees: the pane, then the window. _, err = right.Select(ctx, tmux.PaneSelectRequest{}) if err != nil { return fmt.Errorf("select pane: %w", err) } _, err = logs.Select(ctx) if err != nil { return fmt.Errorf("select window: %w", err) }
// Walk the objects: down from the server, then up from one pane. snapshot, err := server.Snapshot(ctx) if err != nil { return fmt.Errorf("read tmux: %w", err) } for _, each := range snapshot.Sessions() { sessionName, _ := each.Name() fmt.Println("session", sessionName) windows, _ := each.Windows() for _, window := range windows { name, _ := window.Name() fmt.Printf(" window %d:%s:", window.Index(), name) panes, _ := window.Panes() for _, pane := range panes { fmt.Print(" ", pane.ID()) } fmt.Println() } } pane, _ := snapshot.PaneByID(right.ID()) window, _ := pane.Window() owner, _ := window.Session() windowName, _ := window.Name() sessionName, _ := owner.Name() fmt.Println(pane.ID(), "is in window", windowName, "of session", sessionName) return nil}// Command quickstart lays out a tmux session, then walks it as objects.package main
import ( "context" "errors" "fmt" "log" "os"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := run(context.Background()); err != nil { log.Fatal(err) }}
func run(ctx context.Context) (err error) { // A private server: a socket and an empty config of its own, so this // neither touches nor is changed by a tmux you already use. // The process ID in the socket name keeps one run apart from the next. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: fmt.Sprintf("libtmux-quickstart-%d", os.Getpid()), ConfigFile: os.DevNull, }) if err != nil { return err } session, err := server.NewSession(ctx, tmux.NewSessionRequest{ Name: "demo", }) if err != nil { return err } // Cleanup runs even when ctx is the reason the program is leaving. defer func() { err = errors.Join(err, server.Kill(context.WithoutCancel(ctx))) }()
// Lay out the session: name its window, split it, add a second window. editor, err := session.ResolveActiveWindow(ctx) if err != nil { return err } editor, err = editor.Rename(ctx, "editor") if err != nil { return err } left, err := editor.ResolveActivePane(ctx) if err != nil { return err } right, err := left.Split(ctx, tmux.SplitPaneRequest{ Direction: tmux.PaneDirectionRight, }) if err != nil { return err } name := "logs" logs, err := session.NewWindow(ctx, tmux.NewWindowRequest{ Name: &name, }) if err != nil { return err }
// Type a command into the new pane and wait for what it prints. command := "printf 'hello from %s\\n' tmux" err = right.SendKeys(ctx, tmux.SendKeysRequest{Command: &command}) if err != nil { return err } _, err = right.WaitForText(ctx, tmux.WaitForTextRequest{ Text: "hello from tmux", }) if err != nil { return err }
// Move the focus an attached client sees: the pane, then the window. _, err = right.Select(ctx, tmux.PaneSelectRequest{}) if err != nil { return err } _, err = logs.Select(ctx) if err != nil { return err }
// Walk the objects: down from the server, then up from one pane. snapshot, err := server.Snapshot(ctx) if err != nil { return err } for _, each := range snapshot.Sessions() { sessionName, _ := each.Name() fmt.Println("session", sessionName) windows, _ := each.Windows() for _, window := range windows { name, _ := window.Name() fmt.Printf(" window %d:%s:", window.Index(), name) panes, _ := window.Panes() for _, pane := range panes { fmt.Print(" ", pane.ID()) } fmt.Println() } } pane, _ := snapshot.PaneByID(right.ID()) window, _ := pane.Window() owner, _ := window.Session() windowName, _ := window.Name() sessionName, _ := owner.Name() fmt.Println(pane.ID(), "is in window", windowName, "of session", sessionName) return nil}// Command quickstart lays out a tmux session, then walks it as objects.package main
import ( "context" "errors" "fmt" "log" "os"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := run(context.Background()); err != nil { log.Fatal(err) }}
func run(ctx context.Context) (err error) { // A private server: a socket and an empty config of its own, so this // neither touches nor is changed by a tmux you already use. // The process ID in the socket name keeps one run apart from the next. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: fmt.Sprintf("libtmux-quickstart-%d", os.Getpid()), ConfigFile: os.DevNull, }) if err != nil { return fmt.Errorf("configure tmux: %w", err) } session, err := server.NewSession(ctx, tmux.NewSessionRequest{ Name: "demo", }) if err != nil { return fmt.Errorf("create session: %w", err) } // Cleanup runs even when ctx is the reason the program is leaving. defer func() { err = errors.Join(err, server.Kill(context.WithoutCancel(ctx))) }()
// Lay out the session: name its window, split it, add a second window. editor, err := session.ResolveActiveWindow(ctx) if err != nil { return fmt.Errorf("find window: %w", err) } editor, err = editor.Rename(ctx, "editor") if err != nil { return fmt.Errorf("rename window: %w", err) } left, err := editor.ResolveActivePane(ctx) if err != nil { return fmt.Errorf("find pane: %w", err) } right, err := left.Split(ctx, tmux.SplitPaneRequest{ Direction: tmux.PaneDirectionRight, }) if err != nil { return fmt.Errorf("split pane: %w", err) } name := "logs" logs, err := session.NewWindow(ctx, tmux.NewWindowRequest{ Name: &name, }) if err != nil { return fmt.Errorf("add window: %w", err) }
// Type a command into the new pane and wait for what it prints. command := "printf 'hello from %s\\n' tmux" err = right.SendKeys(ctx, tmux.SendKeysRequest{Command: &command}) if err != nil { return fmt.Errorf("send keys: %w", err) } _, err = right.WaitForText(ctx, tmux.WaitForTextRequest{ Text: "hello from tmux", }) if err != nil { return fmt.Errorf("wait for output: %w", err) }
// Move the focus an attached client sees: the pane, then the window. _, err = right.Select(ctx, tmux.PaneSelectRequest{}) if err != nil { return fmt.Errorf("select pane: %w", err) } _, err = logs.Select(ctx) if err != nil { return fmt.Errorf("select window: %w", err) }
// Walk the objects: down from the server, then up from one pane. snapshot, err := server.Snapshot(ctx) if err != nil { return fmt.Errorf("read tmux: %w", err) } for _, each := range snapshot.Sessions() { sessionName, _ := each.Name() fmt.Println("session", sessionName) windows, _ := each.Windows() for _, window := range windows { name, _ := window.Name() fmt.Printf(" window %d:%s:", window.Index(), name) panes, _ := window.Panes() for _, pane := range panes { fmt.Print(" ", pane.ID()) } fmt.Println() } } pane, _ := snapshot.PaneByID(right.ID()) window, _ := pane.Window() owner, _ := window.Session() windowName, _ := window.Name() sessionName, _ := owner.Name() fmt.Println(pane.ID(), "is in window", windowName, "of session", sessionName) return nil}tmux before the first call: no server is running.
tmux after tmux.NewServer: no server is running; the call sent no command.
tmux after Server.NewSession: added session demo.
tmux after Session.ResolveActiveWindow: unchanged.
tmux after Window.Rename: renamed window 0:sh to 0:editor.
tmux after Window.ResolveActivePane: unchanged.
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.WaitForText: 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 Snapshot.PaneByID: 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 Window.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.
tmux.NewServer returned tmux.Server
{ "configFile": "/dev/null", "executable": "/usr/bin/tmux", "socketPath": "/tmp/tmux-1000/libtmux-quickstart-12345"}The call sent no tmux command.
Server.NewSession returned tmux.Session
{ "id": "$0", "name": "demo"}list-sessions -F '#{session_id} #{session_name}' error connecting to /tmp/tmux-1000/libtmux-quickstart-12345 (No such file or directory) new-session -P -F#{session_id} -sdemo -d $0 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… Before these, the library asked tmux about itself 7 times (its version, its daemon, how a control client reads escapes).
Session.ResolveActiveWindow returned tmux.Window
{ "id": "@0", "index": 0, "name": "sh"}list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output Window.Rename returned tmux.Window
{ "id": "@0", "index": 0, "name": "editor"}rename-window -t @0 -- editor no output list-windows -t @0 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_c… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… Window.ResolveActivePane returned tmux.Pane
{ "id": "%0"}list-panes -t @0 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/14|0|2… Pane.Split returned tmux.Pane
{ "id": "%1"}split-window -t $0:.%0 -h -P -F#{pane_id} -d %1 list-panes -t $0:.%1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|0|2|0|0|0|0|0|0|\$1|0|1|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0… Session.NewWindow returned tmux.Window
{ "id": "@1", "index": 1, "name": "logs"}new-window -t $0 -d -P -F#{window_id} -n logs @1 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output Pane.SendKeys returned error
nullsend-keys -t $0:.%1 -- 'printf '\''hello from %s\n'\'' tmux' no output send-keys -t $0:.%1 -- Enter no output Pane.WaitForText returned error
nullcapture-pane -p -J -t %1 ; run-shell -C -t %1 libtmux-text-wait-fcb5574e00cc8b43-#{q:pane_id}-#{q:pane_dead}| $ printf 'hello from %s\n' tmux
hello from tmux
$ Pane.Select returned error
nullselect-pane -t $0:.%1 no output list-panes -t $0:.%1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|0|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|-|0|1|24|\%0|0|0|0|VT10x|1|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0|… Window.Select returned error
nullselect-window -t @1 no output list-windows -t @1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_c… 1|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|2|0|24,960,67,335,0,0|1295|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|0|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%1|0|1|0|VT10x|0|41|0|0|0||4||0|hidden|2848987|0||7,25|79||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/16|0|24|39|39|41|0|1… Server.Snapshot returned tmux.Snapshot
{ "panes": 3, "sessions": 1, "windows": 2}list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 1|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%2|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2849087|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/17|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 1|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|2|0|24,960,67,335,0,0|1295|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|0|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%1|0|1|0|VT10x|0|41|0|0|0||4||0|hidden|2848987|0||7,25|79||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/16|0|24|39|39|41|0|1… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 1|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|1|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|0|1|1|0|1|default|23|0|sh|/tmp/marked|0||||default|-|0|1|24|\%0|0|0|0|VT10x|1|0|0|0|0||1||0|hidden|2848733|0||7,25|39||||/tmp/marked|0|8,16,24,32|host|0|/dev/pts/14|0|24|40|40|0|0|1|0|… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output Before these, the library asked tmux about itself 2 times (its version, its daemon, how a control client reads escapes).
Snapshot.PaneByID returned tmux.Pane
{ "id": "%1"}The call sent no tmux command.
Pane.Window returned tmux.Window
{ "id": "@0", "index": 0, "name": "editor"}The call sent no tmux command.
Window.Session returned tmux.Session
{ "id": "$0", "name": "demo"}The call sent no tmux command.
Server.Kill returned error
nullkill-server no output Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).
POSIX shell, tmux 3.3a or newer and Go 1.26.5.
Save the program above as quickstart.go 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.
module example.com/libtmux-home
go 1.26.0
require github.com/libtmux/libtmux-go v0.1.2go mod tidygo build -p 2 -o quickstart quickstart.gounset TMUX TMUX_PANEexport ENV=/dev/null BASH_ENV=/dev/null SHELL=/bin/sh./quickstartsession demo window 0:editor: %0 %1 window 1:logs: %2%1 is in window editor of session demo// Command control-mode-subscribe watches a persistent tmux control client// receive changes without polling.package main
import ( "context" "errors" "fmt" "log" "os" "time"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := start(); err != nil { log.Fatal(err) }}
// start owns cleanup because log.Fatal skips deferred calls in main.func start() error { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel()
// Choose an unused socket name: cleanup kills the server selected here. // The empty config keeps personal settings out of a new server. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: "libtmux-control-mode-subscribe", ConfigFile: os.DevNull, }) if err != nil { return fmt.Errorf("configure tmux server: %w", err) } return run(ctx, server)}
// run accepts injected server state so tests can isolate the example.func run(ctx context.Context, server tmux.Server) (err error) { session, err := server.NewSession(ctx, tmux.NewSessionRequest{Name: "libtmux-control"}) if err != nil { return fmt.Errorf("create session: %w", err) } defer func() { cleanupCtx, cleanupCancel := context.WithTimeout(context.WithoutCancel(ctx), time.Second) defer cleanupCancel() err = errors.Join(err, session.Kill(cleanupCtx)) }()
stream, err := session.OpenNotifications(ctx, tmux.NotificationOptions{}) if err != nil { return fmt.Errorf("open notification stream: %w", err) } defer func() { err = errors.Join(err, stream.Close()) }()
// Rename after subscribing; notifications do not include earlier changes. if _, err := session.Rename(ctx, "control-example"); err != nil { return fmt.Errorf("rename session: %w", err) }
for { notification, err := stream.Next(ctx) if err != nil { return fmt.Errorf("read notification: %w", err) } fmt.Printf("notification: %s\n", notification.Kind()) if notification.Kind() == tmux.ControlNotificationSessionRenamed { fmt.Println("heard the rename") break } }
// A subscription is a format tmux evaluates for you: it reports the value // when it first looks, about a second later, and then each time it changes. if err := stream.Subscribe(ctx, tmux.SubscriptionRequest{ Name: "windows", Format: "#{session_windows}", }); err != nil { return fmt.Errorf("subscribe: %w", err) } if _, err := session.NewWindow(ctx, tmux.NewWindowRequest{}); err != nil { return fmt.Errorf("open window: %w", err) } for { notification, err := stream.Next(ctx) if err != nil { return fmt.Errorf("read notification: %w", err) } if change, ok := notification.Subscription(); ok && change.Value == "2" { fmt.Println("session has", change.Value, "windows") return nil } }}tmux before the first call: no server is running.
tmux after tmux.NewServer: no server is running; the call sent no command.
tmux after Server.NewSession: added session libtmux-control.
tmux after Session.OpenNotifications: unchanged.
tmux after Session.Rename: renamed session libtmux-control to control-example.
tmux after NotificationStream.Next: unchanged, the call sent no command.
tmux after NotificationStream.Next: unchanged, the call sent no command.
tmux after NotificationStream.Subscribe: unchanged.
tmux after Session.NewWindow: added window 1:sh.
tmux after NotificationStream.Next: unchanged, the call sent no command.
tmux after NotificationStream.Next: unchanged, the call sent no command.
tmux after Session.Kill: the server has exited.
Before the first call
No tmux server is running yet.
tmux.NewServer returned tmux.Server
{ "configFile": "/dev/null", "executable": "/usr/bin/tmux", "socketPath": "/tmp/tmux-1000/libtmux-control-mode-subscribe"}The call sent no tmux command.
Server.NewSession returned tmux.Session
{ "id": "$0", "name": "libtmux-control"}list-sessions -F '#{session_id} #{session_name}' error connecting to /tmp/tmux-1000/libtmux-control-mode-subscribe (No such file or directory) new-session -P -F#{session_id} -slibtmux-control -d $0 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2472129|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… Before these, the library asked tmux about itself 7 times (its version, its daemon, how a control client reads escapes).
Session.OpenNotifications returned *tmux.NotificationStream
{ "session": "$0"}attach-session -f no-output,no-detach-on-destroy,new-layouts -t $0 no output Before these, the library asked tmux about itself 3 times (its version, its daemon, how a control client reads escapes).
%session-changed $0 libtmux-control Session.Rename returned error
nullrename-session -t $0 -- control-example no output list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2472129|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… %session-renamed $0 control-example NotificationStream.Next returned tmux.ControlNotification
{ "kind": "%session-changed"}The call sent no tmux command.
NotificationStream.Next returned tmux.ControlNotification
{ "kind": "%session-renamed"}The call sent no tmux command.
NotificationStream.Subscribe returned error
nullrefresh-client -B windows::#{session_windows} no output Before these, the library asked tmux about itself 2 times (its version, its daemon, how a control client reads escapes).
Session.NewWindow returned error
nullnew-window -t $0 -d -P -F#{window_id} @1 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2472129|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2472129|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2472129|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|1794697140|||1|1794697140|0|attached,focused,control-mode,no-detach-on-destroy,no-output,new-layouts,UTF-8||root||\#\[fg\=themelightgrey]\#\{t/p:client_activity\}:\ session\ \#\[default]\#\{session_name\}|client-2472529|2472529|0|0|control-example||xterm-256color|||1000|host|1|80|0|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,… %window-add @1%subscription-changed windows $0 - - - : 2 NotificationStream.Next returned tmux.ControlNotification
{ "kind": "%window-add"}The call sent no tmux command.
NotificationStream.Next returned tmux.ControlNotification
{ "kind": "%subscription-changed", "subscription": { "name": "windows", "value": "2" }}The call sent no tmux command.
Session.Kill returned error
nullkill-session -t $0 no output %exit// Command run-to-completion runs a program in a tmux pane and reads its exit// status and screen back, the way os/exec would if the program had a terminal.package main
import ( "context" "errors" "fmt" "log" "os" "time"
"github.com/libtmux/libtmux-go/tmux")
func main() { if err := start(); err != nil { log.Fatal(err) }}
// start owns cleanup because log.Fatal skips deferred calls in main.func start() error { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel()
// Choose an unused socket name: cleanup kills the server selected here. // The empty config keeps personal settings out of a new server. server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: "libtmux-run-to-completion", ConfigFile: os.DevNull, }) if err != nil { return fmt.Errorf("configure tmux server: %w", err) } return run(ctx, server)}
// run accepts injected server state so tests can isolate the example.func run(ctx context.Context, server tmux.Server) (err error) { session, err := server.NewSession(ctx, tmux.NewSessionRequest{Name: "libtmux-run"}) if err != nil { return fmt.Errorf("create session: %w", err) } defer func() { cleanupCtx, cleanupCancel := context.WithTimeout(context.WithoutCancel(ctx), time.Second) defer cleanupCancel() err = errors.Join(err, session.Kill(cleanupCtx)) }()
// The command runs with a terminal, so test -t holds where a pipe fails. command := "test -t 1 && echo stdout is a terminal; exit 3" result, err := session.Run(ctx, command, tmux.RunOptions{}) if err != nil { return fmt.Errorf("run command: %w", err) } for _, line := range result.Lines { fmt.Println("screen:", line) } fmt.Println("exited", result.Status)
// Start returns while the command is still running, so its output can be // followed and it can be stopped from another goroutine. The stream begins // where StreamTo opens it, so this command waits before its first line; // result.Lines holds the screen either way. running, err := session.Start(ctx, "sleep 1; seq 1 3; sleep 30", tmux.RunOptions{}) if err != nil { return fmt.Errorf("start command: %w", err) } stopped := make(chan error, 1) go func() { time.Sleep(2 * time.Second) stopped <- running.Kill(ctx) }() streamed, err := running.StreamTo(ctx, os.Stdout) if err != nil { return fmt.Errorf("stream command: %w", err) } if err := <-stopped; err != nil { return fmt.Errorf("stop command: %w", err) } fmt.Println("stopped:", streamed.Signal) return nil}tmux before the first call: no server is running.
tmux after tmux.NewServer: no server is running; the call sent no command.
tmux after Server.NewSession: added session libtmux-run.
tmux after Session.Run: unchanged. tmux held window @1 while the call ran and removed it before it returned.
tmux after Session.Start: added window 1:sh; ran a command in pane %2.
tmux after Running.StreamTo: closed window 1:sh.
tmux after Session.Kill: the server has exited.
Before the first call
No tmux server is running yet.
tmux.NewServer returned tmux.Server
{ "configFile": "/dev/null", "executable": "/usr/bin/tmux", "socketPath": "/tmp/tmux-1000/libtmux-run-to-completion"}The call sent no tmux command.
Server.NewSession returned tmux.Session
{ "id": "$0", "name": "libtmux-run"}list-sessions -F '#{session_id} #{session_name}' error connecting to /tmp/tmux-1000/libtmux-run-to-completion (No such file or directory) new-session -P -F#{session_id} -slibtmux-run -d $0 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|0|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… Before these, the library asked tmux about itself 7 times (its version, its daemon, how a control client reads escapes).
Session.Run returned tmux.RunResult
{ "Status": 3, "Signal": null, "Lines": [ "stdout is a terminal" ], "Pane": "%1"}new-window -t $0 -d -P -F#{window_id} -- cat @1 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output list-panes -t @1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|0|0|0|24,960,0,0,0,0|960|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%1|0|0|0|VT10x|0|0|0|0|0||0||0|hidden|2503154|0||7,25|79||cat|\'cat\'|/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/… set-option -t $0:.%1 -p -- remain-on-exit on no output set-option -t $0:.%1 -p -- remain-on-exit-format '' no output set-hook -t $0:.%1 -p -- pane-died 'wait-for -S libtmux-go-run-CCSS5A4GOHZPDVRIBNZZWURGV7' no output respawn-pane -t $0:.%1 -k -- 'test -t 1 && echo stdout is a terminal; exit 3' no output list-panes -t %1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|0|default|0|0|1|0|24,960,40,200,0,0|1160|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|test||1||3|1794697402|default|\*|0|1|24|\%1|0|0|0|VT10x|0|0|0|0|0||1||0|hidden||0||7|79||\"test\ -t\ 1\ \&\&\ echo\ stdout\ is\ a\ terminal\;\ exit\ 3\"|\'test\ -t\ 1\ \&\&\ echo\ stdout\ is\ a\ ter… wait-for -- libtmux-go-run-CCSS5A4GOHZPDVRIBNZZWURGV7 no output list-sessions libtmux-run: 2 windows (created Sat Nov 14 17:03:21 2026) list-panes -t %1 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|0|default|0|0|1|0|24,960,40,200,0,0|1160|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|test||1||3|1794697402|default|\*|0|1|24|\%1|0|0|0|VT10x|0|0|0|0|0||1||0|hidden||0||7|79||\"test\ -t\ 1\ \&\&\ echo\ stdout\ is\ a\ terminal\;\ exit\ 3\"|\'test\ -t\ 1\ \&\&\ echo\ stdout\ is\ a\ ter… capture-pane -t $0:.%1 -p -S - -E - -J stdout is a terminal kill-window -t @1 no output Session.Start returned *tmux.Running
{ "pane": "%2"}new-window -t $0 -d -P -F#{window_id} -- cat @2 list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output list-panes -t @2 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|0|0|0|24,960,0,0,0,0|960|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%2|0|0|0|VT10x|0|0|0|0|0||0||0|hidden|2503405|0||7,25|79||cat|\'cat\'|/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/… set-option -t $0:.%2 -p -- remain-on-exit on no output set-option -t $0:.%2 -p -- remain-on-exit-format '' no output set-hook -t $0:.%2 -p -- pane-died 'wait-for -S libtmux-go-run-C24MZQGAL3ZANICITXCQXNVYDS' no output respawn-pane -t $0:.%2 -k -- 'sleep 1; seq 1 3; sleep 30' no output list-panes -t %2 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|0|0|0|24,960,0,0,0,0|960|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%2|0|0|0|VT10x|0|0|0|0|0||0||0|hidden|2503499|0||7,25|79||\"sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\"|\'sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\'|/tmp/li… Running.StreamTo returned tmux.RunResult
{ "Status": -1, "Signal": 9, "Lines": [ "1", "2", "3" ], "Pane": "%2"}list-sessions -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|0|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-windows -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_coll… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|2|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|0|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-panes -a -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_collec… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|2|0|0|24,960,20,100,0,0|1060|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%0|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2502975|0||7,25|79||||/tmp/marked|0|8,16,24,32,40,48,56,64,72|host|0|/dev/pts/11|0|2… list-clients -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{q:client_activity}|#{q:client_cell_height}|#{q:client_cell_width}|#{q:client_control_mode}|#{q:client_created}|#{q:client_discarded}|#{q:client_flags}|#{q:client_height}|#{q:client_key_table}|#{q:client_last_session}|#{q:client_mode_format}|#{q:c… no output attach-session -f no-detach-on-destroy,new-layouts -t $0 no output refresh-client -A %2:on ; list-windows -t $0 -F #{window_id} ; capture-pane -b libtmux-go-observe-QGLYOJ7QRPWRELYX4ILU4ITXII -t %2 ; save-buffer -b libtmux-go-observe-QGLYOJ7QRPWRELYX4ILU4ITXII -- /tmp/libtmux-go-observe-3954340031/pane ; delete-buffer -b libtmux-go-observe-QGLYOJ7QRPWRELYX4ILU4ITXII @0
@2 list-panes -t %2 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|0|0|0|24,960,0,0,0,0|960|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%2|0|0|0|VT10x|0|0|0|0|0||0||0|hidden|2503499|0||7,25|79||\"sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\"|\'sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\'|/tmp/li… list-panes -t %2 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|1|default|0|0|3|0|24,960,60,300,0,0|1260|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sh|/tmp/marked|0||||default|\*|0|1|24|\%2|0|0|0|VT10x|0|0|0|0|0||1||0|hidden|2503499|0||7,25|79||\"sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\"|\'sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\'|/tm… run-shell -b -t %2 -- '[ -n "#{pane_pid}" ] && kill -s KILL -- -#{pane_pid} 2>/dev/null; true' no output wait-for -- libtmux-go-run-C24MZQGAL3ZANICITXCQXNVYDS no output list-sessions libtmux-run: 2 windows (created Sat Nov 14 17:03:21 2026) (attached) list-panes -t %2 -F#{q:active_window_index}|#{q:alternate_on}|#{q:alternate_saved_x}|#{q:alternate_saved_y}|#{q:bracket_paste_flag}|#{q:buffer_mode_format}|#{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_added}|#{q:history_all_bytes}|#{q:history_bytes}|#{q:history_col… 0|0|4294967295|4294967295|0|\#\{t/p:buffer_created\}:\ \#\{buffer_sample\}|/dev/null|0|\ |none|0|default|0|0|3|0|24,960,60,300,0,0|1260|0|0|2000|0|host|host|0|0|0|1|1|0|0|0|0|0|0|\$1|0|1|1|1|1|1|default|23|0|sleep||1|9||1794697405|default|\*|0|1|24|\%2|0|0|0|VT10x|0|0|0|0|0||1||0|hidden||0||7|79||\"sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\"|\'sleep\ 1\;\ seq\ 1\ 3\;\ sleep\ 30\'|/tmp/marke… capture-pane -t $0:.%2 -p -S - -E - -J 1
2
3 list-windows -t $0 -F #{window_id} @0 kill-window -t @2 no output Before these, the library asked tmux about itself 7 times (its version, its daemon, how a control client reads escapes).
%session-changed $0 libtmux-run%paste-buffer-changed libtmux-go-observe-QGLYOJ7QRPWRELYX4ILU4ITXII%paste-buffer-deleted libtmux-go-observe-QGLYOJ7QRPWRELYX4ILU4ITXII%output %2 1\015\0122\015\0123\015\012%window-close @2%exit Session.Kill returned error
nullkill-session -t $0 no output github.com/libtmux/libtmux-go/tmux$ go get github.com/libtmux/libtmux-go/tmux@latest$ go get github.com/libtmux/libtmux-go@v0.1.3Pins 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_panes: 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.
{ "sessionId": "$0", "sessionName": "checks"}AgentList the panes, each with the session it belongs to.
{ "panes": [ { "active": true, "currentCommand": "sh", "geometry": { "height": 24, "left": 0, "top": 0, "width": 80 }, "id": "%0", "index": 0, "isCaller": null, "session": "checks", "window": "sh", "windowId": "@0" } ], "total": 1}AgentSplit the pane the list returned (%0) in two.
{ "paneId": "%1"}AgentList the panes again; each now carries its position and size.
{ "panes": [ { "active": true, "currentCommand": "sh", "geometry": { "height": 24, "left": 0, "top": 0, "width": 40 }, "id": "%0", "index": 0, "isCaller": null, "session": "checks", "window": "sh", "windowId": "@0" }, { "active": false, "currentCommand": "sh", "geometry": { "height": 24, "left": 41, "top": 0, "width": 39 }, "id": "%1", "index": 1, "isCaller": null, "session": "checks", "window": "sh", "windowId": "@0" } ], "total": 2}AgentRun the tests in the pane the list returned (%0).
{ "effective_timeout_seconds": 120, "exit_status": 0, "output": [ ".. [100%]", "2 passed in 0.01s" ], "pane_id": "%0", "resolved_pane_ids": [ "%0" ], "timed_out": false}AgentShow the log in the new pane the split returned (%1).
{ "effective_timeout_seconds": 120, "exit_status": 0, "output": [ "2026-01-01 checks started", "2026-01-01 checks finished" ], "pane_id": "%1", "resolved_pane_ids": [ "%1" ], "timed_out": false}AgentRemove the session by the id the create result returned ($0).
{ "killed": "checks"}pytest printed 2 passed and checks.log ends with checks finished. I removed the checks session.
github.com/libtmux/libtmux-go/mcpChoose your client and configuration scope, then run the command or paste the configuration.
$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ claude mcp add tmux -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ claude mcp add tmux --scope user -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ claude mcp add tmux --scope project -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ codex mcp add tmux -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest[mcp_servers.tmux]
command = "libtmux-mcp"$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ gemini mcp add --scope user tmux libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ gemini mcp add --scope project tmux libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ grok mcp add --scope user tmux -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ grok mcp add --scope project tmux -- libtmux-mcp$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest{
"mcpServers": {
"tmux": {
"command": "libtmux-mcp"
}
}
}$ go install github.com/libtmux/libtmux-go/mcp/cmd/libtmux-mcp@latest$ opencode mcp add tmux -- libtmux-mcpWrites ~/.claude.json (this project).
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ~/.claude.json (all projects).
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes .mcp.json (in repo, version-controlled).
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ~/.codex/config.toml.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ~/.gemini/settings.json.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes .gemini/settings.json (in repo).
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ~/.grok/config.toml.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ./.grok/config.toml (in repo).
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
Writes ~/.config/opencode/opencode.jsonc.
That puts libtmux-mcp in $(go env GOPATH)/bin, which has to be on your PATH for the command below to resolve.
func connect(ctx context.Context, target tmux.Server) (*sdk.ClientSession, func(), error) { clientTransport, serverTransport := sdk.NewInMemoryTransports() instance, err := tmuxmcp.NewServer(target) if err != nil { return nil, nil, fmt.Errorf("construct the server: %w", err) } serverSession, err := instance.Connect( ctx, tmuxmcp.AssumeResponseCommit(serverTransport), nil, ) if err != nil { _ = instance.Close() return nil, nil, fmt.Errorf("start the server: %w", err) } client := sdk.NewClient(&sdk.Implementation{Name: "agent-workflow", Version: "1"}, nil) session, err := client.Connect(ctx, clientTransport, nil) if err != nil { _ = serverSession.Close() _ = instance.Close() return nil, nil, fmt.Errorf("connect a client: %w", err) } return session, func() { _ = session.Close() _ = serverSession.Close() _ = instance.Close() }, nil}
Excerpt of mcp/examples/agent-workflow/main.go.
This program is tested on every change.
Load a workspace file concept Working example; may change without notice. Read more Workspace Manager home →
environment sets variables for a session, a window or a pane.
session_name: nativestart_directory: .environment: {SESSION_VALUE: session}windows:- window_name: development window_index: 3 layout: even-horizontal environment: {WINDOW_VALUE: window} panes: - start_directory: one shell_command: 'printf "%s:%s:%s" "$SESSION_VALUE" "$WINDOW_VALUE" "$PANE_VALUE" > result' - start_directory: two environment: {PANE_VALUE: pane} shell_command: 'printf "%s:%s:%s" "$SESSION_VALUE" "$WINDOW_VALUE" "$PANE_VALUE" > result'- window_name: second focus: true panes: [blank]{ "session_name": "native", "start_directory": ".", "environment": { "SESSION_VALUE": "session" }, "windows": [ { "window_name": "development", "window_index": 3, "layout": "even-horizontal", "environment": { "WINDOW_VALUE": "window" }, "panes": [ { "start_directory": "one", "shell_command": "printf \"%s:%s:%s\" \"$SESSION_VALUE\" \"$WINDOW_VALUE\" \"$PANE_VALUE\" > result" }, { "start_directory": "two", "environment": { "PANE_VALUE": "pane" }, "shell_command": "printf \"%s:%s:%s\" \"$SESSION_VALUE\" \"$WINDOW_VALUE\" \"$PANE_VALUE\" > result" } ] }, { "window_name": "second", "focus": true, "panes": [ "blank" ] } ]}Save the file as workspace.yaml and load it with:
tmux-workspace load workspace.yaml
Workspace file: workspace/internal/integration/cli_test.go.
Tested by TestLoadFreezeReloadAppendAndEnvironment
(workspace/internal/integration/cli_test.go; a test runs the command).
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: workspace/testdata/tmuxp/shorthands.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed by the library in a test; the command is not run).
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" ] } ]}
Workspace file: workspace/testdata/tmuxp/2-pane-vertical.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed by the library in a test; the command is not run).
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: workspace/testdata/tmuxp/3-pane.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/4-pane.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: 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" } ]}
Workspace file: workspace/testdata/tmuxp/main-pane-height.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/start-directory.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/2-pane-synchronized.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/blank-panes.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed by the library in a test; the command is not run).
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" ] } ] } ]}
Workspace file: workspace/testdata/tmuxp/env-variables.yaml.
Tested by TestEveryTmuxpExampleMatchesTheStructureTmuxpBuilds
(workspace/internal/cli/tmuxp_structure_test.go; 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: workspace/testdata/tmuxp/focus-window-and-panes.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/main-pane-height-percentage.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/minimal.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/options.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/pane-shell.yaml.
Tested by TestEveryTmuxpExampleMatchesTheStructureTmuxpBuilds
(workspace/internal/cli/tmuxp_structure_test.go; 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: workspace/testdata/tmuxp/skip-send.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/skip-send-pane-level.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/sleep.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/sleep-pane-level.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/sleep-virtualenv.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/suppress-history.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed 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: workspace/testdata/tmuxp/window-index.yaml.
Tested by TestEveryTmuxpExampleParses
(workspace/workspace_test.go; parsed by the library in a test; the command is not run).
github.com/libtmux/libtmux-go/workspaceThe workspace package is separate from the core library.
$ go install github.com/libtmux/libtmux-go/workspace/cmd/tmux-workspace@latest$ tmux-workspace load ./workspace.yamlNeeds Go 1.26 or newer. Puts tmux-workspace in $(go env GOBIN), or in $(go env GOPATH)/bin when GOBIN is unset; rerunning it upgrades.
// document is a workspace file. A program of your own would read one from// disk with os.ReadFile.const document = `session_name: projectwindows: - window_name: editor layout: main-vertical panes: - echo editing - echo testing - window_name: logs panes: - echo api - echo worker - echo database`
// Parse refuses a field it does not know rather than dropping it, so a// workspace that loads is one that was understood.parsed, err := workspace.Parse([]byte(document))if err != nil { return fmt.Errorf("parse workspace: %w", err)}
// Choose an unused socket name: cleanup kills the server selected here.// The empty config keeps personal settings out of a new server.server, err := tmux.NewServer(tmux.ServerOptions{ SocketName: "libtmux-build-workspace", ConfigFile: os.DevNull,})if err != nil { return fmt.Errorf("configure tmux: %w", err)}// Cleanup runs even when ctx is the reason the program is leaving.defer func() { err = errors.Join(err, server.Kill(context.WithoutCancel(ctx)))}()
session, err := workspace.Build(ctx, server, parsed)
Excerpt of workspace/examples/build-workspace/main.go.
This program is tested on every change.
Subject-by-subject, with Go in every code block.
Task guides for Go.
Complete programs, sourced from the code each port tests.
The domain model every port shares.
Example programs, each run by the port's CI:
examples/control-mode-subscribe/main.go in .github/workflows/tests.ymlexamples/run-to-completion/main.go in .github/workflows/tests.ymlReference preview