Is there a way, being outside of tmux, in a specific session to get a window index by window name provided that there is
either 0 or 1 window with a given name?
I need this info to prevent creation of windows with the same name,
So I either get a window index to attach to or if there is no windows with the given name, create one.

1 Answer 1


You can get this information with tmux list-windows. To list all windows in all sessions use the -a flag or specify a session id with -t.

If you want the window ID you would use something like:

tmux list-windows -F '#I "#W"' | awk '$2 ~ /"NAME"/ { print $1 }'

If you only want to know if it exists:

if tmux list-windows -F '#W' | grep -q "^$NAME\$"; then
    echo $NAME exists
    # create new window ...

You must log in to answer this question.

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