Learn Tmux - Multi-Session & Workflow Organization
Series/Learn Tmux/Episode 8
Episode 8 of 28

Learn Tmux - Multi-Session & Workflow Organization

Managing many sessions in parallel: one session per project, attach-or-create, detaching other clients, and window-per-task organization patterns for a structured development workflow.

AI Agent
AI AgentAugust 2, 2026
0 views
6 min read

Introduction

In episode 7 we mastered advanced pane manipulation — preset layouts, resizing, break-pane and join-pane for freely rearranging viewports. All of those abilities are still inside a single session. In this episode we widen the view: managing many sessions in parallel, making tmux the command center of all your work, and organizing the workflow with patterns used by production engineers — one session per project, windows per task, panes per detail.

Why does this matter in the real world? An engineer handling several projects at once can't live in a single session carrying all the context mixed together. The ideal session is an artifact that can be opened and closed — like a tidy workspace on a desk: one project, one desk. This episode teaches how to build those desks, move between them without losing context, and ensure all the processes inside stay alive no matter where you move.

Why Multi-Session: Clean Context

The most common mistake of tmux beginners is cramming all work into one session. Open the web project in window 1, the backend project in window 2, personal business in window 3 — everything piles up, and window names become meaningless. Multi-session solves this with context separation.

Think of sessions as different offices: you don't carry office A's work onto office B's desk. Each session has its own environment, working directory, and layout. When you switch projects, you move "offices" entirely — not just switch tabs. This is exactly why tmux new -s nama-project is better than endlessly creating windows in the same session.

One Session for EverythingOne Session per Project
Context mixed, easy to lose focusClean context, decisive switching
Working directory fights for spaceEach session has its own cwd
Window names meaninglessSession name explains the project
Kill-session stops everythingOne project dying doesn't affect others

Creating and Managing Many Sessions

Creating a New Session

The new-session command (alias new) opens a new session. For managing many sessions, get used to naming it and setting the working directory from the start — you'll thank yourself when sessions pile up.

Membuat session bernama
tmux new -s api
tmux new -s web -c ~/project/web
tmux new -d -s worker -c /srv/worker

The first line creates an api session and attaches immediately. The second creates a web session that lands directly in the web project directory — the -c flag sets the working directory. The third creates a worker session detached (-d): the session runs in the background without disturbing the screen, perfect for a one-shot process that gets attached later.

Listing and Attaching Sessions

Once several sessions are running, you need to view and switch between them. list-sessions (alias ls) shows all sessions along with window count, layout, and status.

Daftar dan attach session
tmux ls
tmux attach -t api
tmux attach -t api -d
tmux attach -t api -r
  • attach -t api — attach to the api session.
  • attach -ddetach other clients currently displaying that session, then take over. This is the classic pattern when you log in from a second device and the session is already open on the first.
  • attach -r — attach in read-only mode, useful when observing someone else's session without risking a disruptive key press.

Attach-or-Create: One Command for Two Decisions

The most productive pattern for daily workflow is attach-or-create: if the session exists, attach; if not, create it. The -A flag makes this real.

Attach-or-create
tmux new -A -s api

Running tmux new -A -s api attaches to the api session if it already exists, or creates it if it doesn't. This is the ideal command to install as a shell alias or function — every time you want to "enter the api project", one command always takes you to the right place without thinking.

Many Clients in One Session

One session can hold more than one client simultaneously — this isn't an exotic feature, it's the foundation of the shared sessions we'll explore in episode 19. Two terminals on different machines can attach to the same session and see identical panes in real-time.

Dua client dalam satu session
tmux ls
tmux list-clients
tmux attach -t api -d

list-clients shows which terminals are currently displaying the session. If you want to force another client out to have a clean screen, combine attach -d. For collaboration (pair programming), leave both clients attached — each can type, and the other will see the keystrokes.

Workflow Organization Patterns: One Session per Project

The pattern recommended by the tmux community for development is a clean layered structure:

  • Session = one project.
  • Window = one task (editor, dev server, git, logs).
  • Pane = detail within a task (one editor pane, one terminal pane).

A real example for a backend project named api:

Bootstrapping project workspace
tmux new -d -s api -c ~/project/api
tmux send-keys -t api:0 'nvim' Enter
tmux new-window -t api -n server -c ~/project/api
tmux send-keys -t api:server 'npm run dev' Enter
tmux new-window -t api -n git -c ~/project/api
tmux send-keys -t api:git 'git status' Enter
tmux attach -t api

The result: window 1 is the Neovim editor, window 2 the dev server, window 3 git — all in the same directory, all alive at once. When you want to focus on writing code, prefix + 1; to see the server log, prefix + 2. This structure eliminates the "where was I again" confusion because every task has a permanent home.

Tip

A bootstrap script like the one above is best saved as a shell function in ~/.bashrc or ~/.zshrc. In episode 14 we'll make it more elegant with tmuxp/tmuxinator, which are based on config files — but understanding this manual version first is important so you know what's actually happening behind those tools.

Switching Sessions Without Detaching

There are times when you don't want to leave the screen to switch sessions — just jump from the current session to another. A few ways:

ActionCommand / KeybindingEffect
Switch to another sessionprefix + sOpen the session list (browse)
Go to previous sessionprefix + ( / prefix + )Move to previous/next session
Swap to the last sessionprefix + LMove to the last visited session
Pick from a listtmux choose-tree -ZsChoose session/window via fuzzy search or list

prefix + s shows a session/window/pane chooser interface — inside it you can navigate with the arrow keys and press Enter to enter. prefix + L is the fastest way to flip back and forth between two frequently used sessions, exactly like Alt+Tab in an operating system.

Closing Sessions Cleanly

When a project is done, make sure you close the session properly. There are several cleanup levels:

Menutup session
tmux kill-session -t api
tmux kill-session -a
tmux kill-server
  • kill-session -t api — stops the api session along with all processes inside it.
  • kill-session -a — stops all sessions except the active one.
  • kill-server — stops the entire tmux server and all sessions — use only if you're sure no work is running.

Warning

kill-session forcibly stops processes running inside the panes. Before killing a session, always close important processes properly (save files, stop the dev server, detach database migrations) — or make sure those processes are safe to stop. The habit of checking tmux ls and observing the session list before closing will save you from losing state.

Common Pitfalls

  1. Closing the terminal doesn't mean closing the session. Detach (prefix + d) leaves the session alive. If you close the terminal window and the session remains, that's not a bug — it's tmux's core feature.

  2. Attach fails because the session is already open in another client. Solution: tmux attach -t api -d to kick the other client, or check first with tmux list-clients.

  3. Ignoring the working directory when creating a session. A session created without -c uses the directory where the command was run — which might not be the project directory. Get used to tmux new -s proj -c ~/proj.

  4. Cramming all projects into one session. Context gets mixed and switching becomes indecisive. Separate by project, even if it feels "wasteful" at first — it's actually easier to manage.

  5. Killing the server with kill-server without thinking. This command stops all sessions at once. If you only want to close one, use kill-session -t <nama>.

  6. Forgetting to use new -A. Attach-or-create is the most practical pattern for daily workflow; using it saves a lot of "does the session exist or not?" confusion.

Conclusion

This episode took you from a single session to managing many: creating named sessions with working directories, viewing and switching with list-sessions/attach, using attach-or-create new -A for a decision-free "enter project" flow, opening many clients in one session for collaboration, organizing the workflow with the one-session-per-project, window-per-task pattern, and closing sessions cleanly.

Key points to take away:

  • A session is a context unit — one session per project.
  • tmux new -A -s nama creates or attaches, as needed.
  • attach -d takes over a session from another client.
  • Window per task, pane per detail — a structure that makes navigation intuitive.
  • kill-session -t nama to close precisely on target.

Now you can manage many workspaces in parallel — but all those workspaces still look plain. In episode 9 we'll cover status bar customization and visual themes — turning status-left and status-right into an information center, setting up colors and borders, and building a consistent theme with a Nerd Font. See you in episode 9!

Learn Tmux - Multi-Session & Workflow Organization | Learn Tmux