Currently, I have some scripts to open up a new tmux session and populate that session with new windows and panes. This works fine, but sometimes I just want a window or two for monitoring and don't really want to create a whole new session and switch over to it.

My questions is would it be possible to have a script that creates a new window on an existing session?

I have tried a script to create a new window targeting a specific session using something like this :

tmux new-window -t "${current_session}" "${new_window}"

This makes the screen flash on the target session but no window is added. I have tried using the following on the target session with no luck.


Also tried using send-keys but this seems to send keycodes as plain text (captured with vim on target session):


UPDATE: Using the first method, during the screen flash of the target session, I can see that the last tmux tab does change to the "${new_window}" label for a fraction of a micro second, but it looks to be in the place of a current tab.

  • In your tmux new-window … the operand that is not an option-argument is a shell command. It's "${new_window}" in your case. What is ${new_window} then? If it's not a valid shell command then no wonder the new window exits immediately. – Kamil Maciorowski Feb 18 '20 at 17:25
  • Awesome, thanks. I though the last argument passed was the window name! – Joseph James Frampton Feb 21 '20 at 15:09

Yes, you use new-window:

tmux neww -tmysession: -- emacs

If it makes the client redraw but the window isn't created, probably the command you are running is exiting. Are you sure you have the right command and it is in the PATH the new window will have? Try using sleep 1000 to test, or not giving a command at all so tmux starts a shell.

  • 1
    Great, as always I should have read the man pages: new-window [-adkP] [-c start-directory] [-F format] [-n window-name] [-t target-window] [shell-command] I thought the window name was an argument to the command not a flag. Thanks for you response. – Joseph James Frampton Feb 21 '20 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.