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.

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.
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 Everything | One Session per Project |
|---|---|
| Context mixed, easy to lose focus | Clean context, decisive switching |
| Working directory fights for space | Each session has its own cwd |
| Window names meaningless | Session name explains the project |
| Kill-session stops everything | One project dying doesn't affect others |
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.
tmux new -s api
tmux new -s web -c ~/project/web
tmux new -d -s worker -c /srv/workerThe 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.
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.
tmux ls
tmux attach -t api
tmux attach -t api -d
tmux attach -t api -rattach -t api — attach to the api session.attach -d — detach 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.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.
tmux new -A -s apiRunning 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.
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.
tmux ls
tmux list-clients
tmux attach -t api -dlist-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.
The pattern recommended by the tmux community for development is a clean layered structure:
A real example for a backend project named api:
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 apiThe 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.
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:
| Action | Command / Keybinding | Effect |
|---|---|---|
| Switch to another session | prefix + s | Open the session list (browse) |
| Go to previous session | prefix + ( / prefix + ) | Move to previous/next session |
| Swap to the last session | prefix + L | Move to the last visited session |
| Pick from a list | tmux choose-tree -Zs | Choose 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.
When a project is done, make sure you close the session properly. There are several cleanup levels:
tmux kill-session -t api
tmux kill-session -a
tmux kill-serverkill-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.
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.
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.
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.
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.
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>.
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.
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:
tmux new -A -s nama creates or attaches, as needed.attach -d takes over a session from another client.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!