How can I reset tmux's automatic session name numbering?

After accidentally holding down ctrl+alt+t, my tmux sessions are now automatically named with annoyingly high numbers:

[email protected]:~$ tmux ls
124: 1 windows (created Mon Jan  5 16:45:55 2015) [80x24] (attached)

How can I reset this number to 1? I’ve tried tmux rename-session‘ing my session to a lower number, but after closing it and opening a new session, the numbering resumes from the original number.

Is there any way to fix this without restarting tmux?

Unix & Linux Asked on November 11, 2021

2 Answers

2 Answers


tmux kill-server && tmux

Answered by user423787 on November 11, 2021

No, this is not currently possible.

The only thing you can do about this without restarting the server is to override the name manually when creating a new session by issuing tmux new -s 5, for example:

$ tmux new -d -P
$ tmux ls
10: 1 windows (created Wed Jan  7 15:50:29 2015) [107x89]
$ tmux new -s 5 -d -P
$ tmux ls
10: 1 windows (created Wed Jan  7 15:50:29 2015) [107x89]
5: 1 windows (created Wed Jan  7 15:50:40 2015) [107x89]
$ tmux new -s 5 -d -P
duplicate session: 5

The automatic session number is governed by the global variable u_int next_session_id in session.c which cannot be accessed from the command line, as grepping the source code reveals.

tmux new-session calls session_create() in session.c (line 88) and next_session_id is incremented whenever you create a new session. The argument of -s flag to new-session (short new) sets name, otherwise next_session_id is used.

     if (name != NULL) {
              s->name = xstrdup(name);
              s->id = next_session_id++;
     } else {
             s->name = NULL;
             do {
                     s->id = next_session_id++;
                     xasprintf(&s->name, "%u", s->id);
             } while (RB_FIND(sessions, &sessions, s) != NULL);

Answered by ariane on November 11, 2021

Add your own answers!

Related Questions

How to default `ps aux` to `ww`?

0  Asked on January 7, 2021 by nicholas-dipiazza


Earphone’s mic does’t work on fedora linux

0  Asked on January 6, 2021 by vedant-nandwana


Parallelize a Bash FOR Loop

10  Asked on January 6, 2021 by ravnoor-s-gill


List only bind mounts

5  Asked on January 6, 2021 by l0b0


Addition with ‘sed’

12  Asked on January 5, 2021 by luigi-tiburzi


Muon is stuck on lubuntu cosmic. How do I get off this dead end?

1  Asked on January 5, 2021 by cw-holeman-ii


Where are defined the man pages grouping descriptions?

1  Asked on January 5, 2021 by lus-gustavo-monezi


xrandr three monitors

2  Asked on January 5, 2021 by ben-flowers


Adding iptables rules after implementing fail2ban

1  Asked on January 5, 2021 by mike-dank


Get active sink in PulseAudio

1  Asked on January 4, 2021 by inspectormustache


How do I run 32-bit programs on a 64-bit Debian/Ubuntu?

3  Asked on January 3, 2021 by gilles-so-stop-being-evil


Grub’s default kernel priority

0  Asked on January 3, 2021 by abhishek-deshpande


Ask a Question

Get help from others!

© 2021 All rights reserved.