How to rename windows in tmux?

Quick Answer

To rename a tmux window, press Ctrl+b , (comma), type the new name, and press Enter. Alternatively, use the command Ctrl+b : rename-window new-name. You can also use set-option -g automatic-rename on in your ~/.tmux.conf to have tmux automatically name windows based on the current command.

# Rename current window
Ctrl+b , new-name

# Using command mode
Ctrl+b :rename-window new-name

Detailed Explanation

Naming windows in tmux helps you keep track of what's running in each window, making it easier to navigate between different tasks or projects. There are several ways to rename windows, either manually or automatically.

Manual Window Renaming

You can rename the current window in two main ways:

1. Using the key binding:

  1. Press Ctrl+b , (comma)
  2. Type the new window name
  3. Press Enter to confirm

This will immediately update the window name in the status bar.

2. Using the command:

# In tmux command mode (Ctrl+b :)
rename-window new-name

This method is useful when you want to include special characters or spaces in the window name.

Renaming Specific Windows

To rename a window other than the current one:

# In tmux command mode (Ctrl+b :)
rename-window -t 2 new-name  # Renames window 2

You can specify the target window by its index number, name, or using relative references like next or previous.

Automatic Window Renaming

tmux can automatically rename windows based on the current running program:

# Enable automatic window renaming for the current session
Ctrl+b :set-option automatic-rename on

# Disable automatic window renaming for the current session
Ctrl+b :set-option automatic-rename off

To make this setting permanent, add it to your ~/.tmux.conf file:

# Add to ~/.tmux.conf
set-option -g automatic-rename on

# Or to disable
set-option -g automatic-rename off

Customizing Automatic Renaming

You can customize how tmux automatically names windows using the automatic-rename-format option:

# Add to ~/.tmux.conf
set-option -g automatic-rename-format '#{pane_current_command}'

Some useful format variables for window naming:

  • #{pane_current_command} - Current command running in the pane
  • #{pane_current_path} - Current working directory
  • #{host} - Hostname of the machine
  • #{pane_index} - Index of the pane

For example, to show just the basename of the current directory:

set-option -g automatic-rename-format '#{b:pane_current_path}'

Window Names in the Status Bar

You can customize how window names appear in the status bar:

# Add to ~/.tmux.conf
set-window-option -g window-status-format '#I:#W'
set-window-option -g window-status-current-format '#I:#W'

In this format:

  • #I - Window index
  • #W - Window name
  • #F - Window flags (like * for current window)

Pro Tip

Create a custom key binding for quick window renaming with a specific prefix:

# Add to ~/.tmux.conf
bind-key P command-prompt -p "project name:" "rename-window 'proj-%1'"

With this binding, pressing Ctrl+b P will prompt you for a project name and rename the window to "proj-[name]". This helps create a consistent naming convention.