Skip to main content
Browse referenceAll guides
Back to Commands
Session Management

new-session

Short form: new

Create a new session and attach the current terminal to it, unless -d is given. With -t, the new session joins a session group and shares its windows, while keeping its own current window.

How new-session works

new-session starts a new tmux session: a named workspace with its own windows that keeps running after you disconnect. Run it from a normal shell and tmux creates the session and puts your terminal inside it straight away.

Most people only need two flags. -s gives the session a name you can attach to later, and -d creates it in the background without attaching, which is what you want in setup scripts. -A makes the command safe to run again and again: it attaches if the session already exists and creates it if not, so tmux new -A -s main works well as a shell alias.

With -t, the new session joins a session group. Sessions in a group share the same windows, but each one keeps its own current window. That lets two terminals look at different windows of the same project at the same time, which a single shared session cannot do.

Synopsis

bash
tmux new-session [-AdDEPX] [-c start-directory] [-e environment] [-F format] [-f flags] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [shell-command [argument ...]]

Options

FlagDescription
-AAttach to existing session if it exists, otherwise create new
-dDon't attach to the new session
-DDetach any other clients attached to the session
-s session-nameSpecify the session name
-n window-nameName the initial window
-c start-directorySpecify starting directory
-t group-nameGroup with an existing session
-x widthSet window width
-y heightSet window height

Examples

Create a new session with default name

bash
tmux new-session

Create a session named 'dev'

bash
tmux new -s dev

Create session 'work' with window named 'editor'

bash
tmux new -s work -n editor

Create session starting in specific directory

bash
tmux new -s project -c ~/code/myproject

Attach to 'main' if it exists, otherwise create it

bash
tmux new -A -s main

Create a detached session (runs in background)

bash
tmux new -d -s background

Start a background session called api in your project folder. Its first window is named server and runs the dev server.

bash
tmux new -d -s api -c ~/code/api -n server 'npm run dev'

Create a second session that shares the windows of api (a session group), so another terminal can watch a different window of the same project.

bash
tmux new -s mirror -t api

Default Keybinding

new-session has no default key. Run it from a shell as tmux new-session, type it at the command prompt (Ctrl+b then :), or give it a key with bind-key.

Common Mistakes

  • Typing tmux new in a shell that is already inside tmux fails with 'sessions should be nested with care, unset $TMUX to force'. Use tmux new -d -s name and then switch-client, or run new-session from the command prompt (Prefix + :), which creates the session and moves you to it.
  • Skipping -s leaves you with sessions called 0, 1, 2 and so on, which are hard to tell apart later. Name sessions after the project or task.
  • tmux 3.7a and later accept colons and periods in names, but those characters also separate session, window, and pane in targets. A name like api.v2 is awkward to target, so stick to letters, numbers, dashes, and underscores.

Pro Tips

  • •Use -A flag to create or attach in one command - perfect for scripts
  • •The -d flag is useful for creating sessions in startup scripts
  • •Session names should be descriptive and short for easy switching