I'm writing a script to leverage Tmux to run some commands; however, rather than having to constantly run tmux list-windows, get a count number, and assume the last window number, I'm wondering if there's a way to just simply rename the last window that was created so that I can reference that window from its name going forward.

Here's what I'm currently doing:

last_window=$(tmux list-windows | wc -l)
tmux rename-window -t session_name:$(last_window) new_window_name

but this seems a little messy. Any thoughts?

1 Answer 1


I believe tmux new-window allows you to name the window when you create it. The relevant option is -n window-name.

Even if you need to rename it later (e.g. you retrieve the new name from a process in this very window somehow), you can create it with a name like some_temporary_name. Then you don't need to parse tmux list-windows to know the current name of the last window is some_temporary_name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .