tmux, clearly explained (multi-agent terminal)

⏱ ~26 min 🎤 David Ondrej 🏷 tmux 🏷 VPS 🏷 Multi-Agent 🏷 Terminal 🏷 Codex 🏷 Claude Code

tmux is a terminal multiplexer that lets you run multiple terminal sessions inside a single window — and more importantly, it keeps those sessions alive even when you disconnect. In the age of AI coding agents, tmux becomes essential infrastructure: it lets you run multiple AI agents in parallel on a remote VPS, each in its own pane, persistent across SSH disconnects. This walkthrough covers everything from zero to running Codex and Claude Code side by side on a remote server.

01

Why tmux

The core problem: when you close your terminal or your SSH connection drops, everything running in that terminal dies. If you're running a long build, a dev server, or an AI agent — it's gone. tmux solves this by decoupling the terminal session from the connection.

With AI agents that can run for minutes or hours autonomously, persistence isn't a nice-to-have — it's critical. tmux lets you start an agent, disconnect, come back later, and find it still working. It's the foundation for a multi-agent development workflow.

"tmux is to terminal sessions what Docker is to processes — it makes them portable and persistent."

02

Local Setup

Getting tmux installed locally takes one command on most systems:

# macOS brew install tmux # Ubuntu/Debian sudo apt install tmux # Start a new session tmux new -s my-session

Once inside a tmux session, you'll notice a status bar at the bottom of the terminal. That's your indicator that you're inside tmux, not a raw terminal. Everything you do from here is persistent.

03

Core Concepts

tmux has three levels of organization:

  • Sessions — top-level containers. Each session is an independent workspace (e.g., "project-a", "project-b").
  • Windows — tabs within a session. Each window is a full-screen terminal view.
  • Panes — splits within a window. You can divide a window horizontally or vertically to see multiple terminals at once.

The prefix key (default Ctrl+b) activates tmux commands. After pressing the prefix:

# Key bindings (after Ctrl+b) % → split pane vertically " → split pane horizontally d → detach from session (session keeps running) c → create new window n/p → next/previous window arrow → navigate between panes
04

VPS Setup

To really unlock tmux's power, you want it on a remote server — a VPS that's always running. This way your sessions persist indefinitely, not just until your laptop sleeps.

Any cheap VPS works. The video demonstrates with a small cloud instance:

  • Provider: Any cloud (Hetzner, DigitalOcean, AWS Lightsail — whatever's cheap)
  • Size: Even 1 CPU / 1GB RAM works for running AI agents (the heavy compute happens at the API provider)
  • OS: Ubuntu is the safest bet for compatibility with AI coding tools
05

SSH & tmux on VPS

Once your VPS is running, SSH in and install tmux. The workflow becomes: SSH → attach to tmux session → work → detach → disconnect SSH. When you come back, everything is exactly where you left it.

# SSH into your VPS ssh user@your-vps-ip # Install tmux on the VPS sudo apt install tmux # Create a named session tmux new -s agents # Later, reattach after disconnecting tmux attach -t agents

"The magic of tmux on a VPS: you SSH in, start your agents, detach, close your laptop, go to sleep — and they're still coding when you wake up."

06

Panes & Splitting

Panes are where multi-agent workflows come alive. Split your window into multiple panes and run a different agent or process in each one:

# Split vertically (side by side) Ctrl+b then % # Split horizontally (top/bottom) Ctrl+b then " # Navigate between panes Ctrl+b then arrow keys # Resize panes Ctrl+b then hold Ctrl+arrow keys

A typical multi-agent layout: left pane runs Codex, right pane runs Claude Code, bottom pane is your manual terminal for git operations and reviewing output. You can watch both agents work simultaneously.

07

Install Codex CLI

OpenAI's Codex CLI is one of the AI agents you can run in a tmux pane. Installation on the VPS:

# Install Node.js (required for Codex) curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs # Install Codex CLI globally npm install -g @openai/codex # Set your API key export OPENAI_API_KEY="sk-..." # Launch Codex in a tmux pane codex

Once Codex is running in its pane, you can give it tasks and switch to other panes while it works. tmux keeps it alive regardless of what you do.

08

Multi-Agent Demo

The real power move: running multiple AI agents in parallel panes, each working on different parts of a project. The demo shows two agents side by side:

  • Left pane — Codex: Working on the backend API implementation
  • Right pane — Claude Code: Building the frontend components
  • Bottom pane — Manual terminal: Running git, reviewing diffs, managing branches

Both agents work simultaneously and independently. You can monitor progress, intervene when needed, and coordinate their output. It's like having a team of developers — each with their own terminal.

"This is the multi-agent dream: two AI coding agents working in parallel on different parts of your project, all persistent in tmux panes on a cheap VPS."

09

Install Claude Code

Claude Code is Anthropic's AI coding agent. Installing it on the same VPS gives you a second agent to run alongside Codex:

# Install Claude Code npm install -g @anthropic-ai/claude-code # Set your API key export ANTHROPIC_API_KEY="sk-ant-..." # Launch in a tmux pane claude

Now you have both agents installed and ready. Create a tmux layout with panes for each, and you're running a multi-agent development environment.

10

Persistence Proof

The demo proves persistence by disconnecting the SSH session entirely — closing the terminal, waiting, then reconnecting. Upon reattachment with tmux attach -t agents, everything is exactly where it was left: both agents still running, output preserved, work continuing.

# Detach from tmux (session keeps running) Ctrl+b then d # Disconnect SSH entirely exit # ... time passes ... # Reconnect and reattach ssh user@your-vps-ip tmux attach -t agents # Everything is still there! 🎉

This is the killer feature. Your agents don't need you to be connected. They keep working while you sleep, commute, or work on something else.

11

Live App Preview

When your agents build a web app on the VPS, you can preview it by forwarding the port through SSH:

# SSH with port forwarding ssh -L 3000:localhost:3000 user@your-vps-ip # Then open http://localhost:3000 in your browser

This lets you see the app your agents are building in real time, right in your local browser, while the actual server runs on the VPS inside a tmux pane.

12

The Full Vision

The bigger picture: tmux on a VPS is the infrastructure layer for autonomous AI development. The vision is a persistent, always-on development environment where:

  • Multiple agents work in parallel on different features or repos
  • Sessions persist indefinitely — no more lost work from dropped connections
  • You orchestrate by checking in periodically, reviewing output, and redirecting agents
  • Cost is minimal — a $5/month VPS is all you need since compute happens at the API layer

"tmux + VPS + AI agents = a 24/7 development team that costs you $5/month in server costs plus API usage. That's the future we're building toward."

✦ Key Takeaways

1 tmux decouples terminal sessions from connections — sessions survive SSH disconnects and terminal closures.
2 Sessions → Windows → Panes: three levels of organization that let you run multiple agents side by side.
3 A cheap VPS ($5/mo) + tmux gives you a persistent, always-on environment for AI coding agents.
4 Codex and Claude Code can run simultaneously in separate tmux panes, each working on different parts of a project.
5 SSH port forwarding lets you preview apps built by agents on the VPS in your local browser.
6 The full vision: tmux as infrastructure for autonomous, parallel, persistent AI development workflows.