Getting Started with Zellij Sessions

Jul 1, 2026

If you are still using tmux or screen, it might be time to take a look at Zellij. Zellij is a modern terminal multiplexer written in Rust that provides a fully out-of-the-box layout system, status bar, and powerful sessions.

Here is a deep-dive guide to mastering Zellij sessions, scripting layouts, and configuring automatic session connections.


What is a Zellij Session?

A session is an isolated workspace running as a background daemon. This means you can launch text editors, servers, or compilers in a session, disconnect from it (detach), close your terminal emulator, and reconnect (attach) later without interrupting any running processes.


1. Starting & Naming Sessions

When you run zellij, it automatically starts a session and assigns it a funny, randomized name (e.g., creative-writer).

To start a session with a custom, recognizable name, use the --session (or -s) flag:

zellij -s web-development

2. Detaching (Leaving a Session Active)

To disconnect from your session and leave it running in the background:

  1. Press Ctrl + o to enter Session Mode.
  2. Press d to detach.

You will be returned to your regular shell prompt, but all processes inside your Zellij session will continue running.


3. Listing and Re-attaching

To view all currently active Zellij sessions:

zellij list-sessions
# or shorthand:
zellij ls

To connect back to a running session:

zellij attach web-development
# or shorthand:
zellij a web-development

Note: If there is only one active session, running zellij attach with no name will automatically reconnect to it.


4. Interactive Session Manager

Zellij includes a powerful built-in UI for managing sessions.


5. Designing Preset Workspaces with Layouts (KDL)

Instead of manually splitting panes and tabs every time you open a session, Zellij uses a declarative configuration format called KDL to define layouts.

Save this file as dev-layout.kdl inside ~/.config/zellij/layouts/:

// ~/.config/zellij/layouts/dev-layout.kdl
layout {
    default_tab_template {
        // Tab header layout
        pane size=1 borderless=true {
            plugin location="zellij:tab-bar"
        }
        children
        // Tab footer layout
        pane size=1 borderless=true {
            plugin location="zellij:status-bar"
        }
    }

    tab name="Code" focus=true {
        pane edit="src/main.rs" // Opens editor directly
    }

    tab name="Servers & Logs" {
        pane split_direction="vertical" {
            pane name="Server" command="cargo" {
                args "run"
            }
            pane name="Build Monitor" command="cargo" {
                args "watch" "-x" "check"
            }
        }
    }
}

Start your session with this pre-defined layout:

zellij --layout dev-layout

6. Auto-Attach Shell Script

If you want your terminal to automatically connect to an existing session (or prompt you to create a new one) whenever you open a new terminal window, append this shell script to your ~/.bashrc or ~/.zshrc:

# Auto-attach or launch Zellij session
if [ -z "$ZELLIJ" ]; then
    # Get active session names
    active_sessions=$(zellij list-sessions 2>/dev/null | awk '{print $1}')
    
    if [ -n "$active_sessions" ]; then
        echo "Active Zellij sessions found:"
        echo "$active_sessions"
        read -p "Enter session name to attach (or Enter to start new): " choice
        if [ -n "$choice" ]; then
            zellij attach "$choice"
        else
            zellij
        fi
    else
        zellij
    fi
fi

This keeps your terminal workspace persistent and unified across multiple windows or reboots.