For my “hybrid” approach (terminal w/ tabs + tmux), this is the best solution I’ve found for the on-new-tab shell script:
exec tmux $(tmux ls | grep -vq attached && echo "attach" || echo "new")
Reattaches orphan (which are rare!) tmux session or creates new; tabs close automatically on killed session/window.
Other solutions had various problems (orphans; multiple views into one session; etc.). This works.
For people who care about, support, or build Free, Libre, and Open Source Software (FLOSS).