How to attach to tmux session 0?

Quick Answer

To attach to tmux session 0, use the command tmux attach -t 0 or the shorter form tmux a -t 0.

$ tmux attach -t 0

Detailed Explanation

tmux automatically numbers sessions sequentially starting from 0. Session 0 is typically the first session created unless it was explicitly given a name. Attaching to session 0 is a common operation when you've just started using tmux or have a simple setup with one primary session.

Checking if session 0 exists:

Before attaching, you can verify that session 0 exists by listing all current sessions:

$ tmux list-sessions

Or using the shorter form:

$ tmux ls

You should see output like this if session 0 exists:

0: 3 windows (created Sat Jun 1 10:42:33 2025) [80x24]
dev: 2 windows (created Sat Jun 1 09:15:22 2025) [80x24]

Attaching to session 0:

To attach to session 0, use:

$ tmux attach -t 0

What if session 0 doesn't exist?

If session 0 doesn't exist, you'll get an error like:

can't find session 0

In this case, you have two options:

  1. Create a new session numbered 0: tmux new-session -s 0
  2. Use the "attach-or-create" approach: tmux new-session -A -s 0

Pro Tip

Consider using named sessions instead of numbered ones for clarity. A descriptive name like "dev" or "project" is easier to remember than a number.

For Remote Servers

When connecting to a remote server, you can combine SSH and tmux attach in one command: ssh user@host -t 'tmux attach -t 0 || tmux new -s 0'