How to script tmux with send-keys
Type a command into a session from outside:
Targets
-t session:window.pane addresses any pane precisely: tmux send-keys -t work:1.2 "ls" Enter types into pane 2 of window 1. Enter at the end is the keypress — without it the text just sits at the prompt.
Scripted workspaces
Combine with detached sessions to build a full dev environment in a script — the lightweight alternative to tmuxinator:
~/.tmux.conf
tmux new -d -s dev -n editor
tmux send-keys -t dev:editor "nvim ." Enter
tmux split-window -t dev:editor -h -l 30%
tmux send-keys -t dev:editor.1 "npm run dev" Enter
tmux attach -t devDriving interactive programs
send-keys can drive anything that reads a terminal — REPLs, TUIs, and lately AI coding agents running in parallel panes. Pair with capture-pane -p to read the output back in a script.
Related
Verified against tmux 3.6 · updated July 2026 · back to the full cheat sheet