Developer Automation

Automating tmux Workspaces:
Shell Scripts & Multi-Window Environments

Stop manually creating panes, switching directories, and launching servers every morning. Learn how to write reusable, dependency-free Bash automation scripts that construct your full-stack development environment in a single second.

The 6 Essential tmux Scripting Primitives

Every tmux automation script relies on a set of core command-line primitives that can be executed directly from Bash without human interaction. For a full list of flags, check our Commands Reference.

Command Primitive Purpose Example Snippet
new-session -d -s Creates a session in the background (detached). tmux new-session -d -s dev -n editor
new-window -t -n Creates an additional numbered tab/window. tmux new-window -t dev:2 -n servers
split-window -h / -v Splits a specific pane horizontally or vertically. tmux split-window -h -t dev:2.1
send-keys -t ... C-m Injects text commands into a pane and executes them. tmux send-keys -t dev:2.1 'npm run dev' C-m
select-layout -t Applies layout geometry (e.g. tiled, even-horizontal). tmux select-layout -t dev:2 even-horizontal
attach-session -t Connects the user to the prepared session at the end. tmux attach-session -t dev

Production Template: Full-Stack App Starter Script

Save the following script as start-project.sh in your repository root and make it executable with chmod +x start-project.sh:

start-project.sh (Bash)

#!/usr/bin/env bash

# Project Workspace Starter Script


SESSION_NAME="webapp"

PROJECT_DIR="$HOME/projects/my-webapp"


# If session already exists, just attach to it

if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then

  echo "Session $SESSION_NAME already running. Attaching..."

  tmux attach-session -t "$SESSION_NAME"

  exit 0

fi


# 1. Create session with Window 1: Editor

tmux new-session -d -s "$SESSION_NAME" -n "code" -c "$PROJECT_DIR"

tmux send-keys -t "$SESSION_NAME:1" "nvim" C-m


# 2. Create Window 2: Dev Servers (Split into 2 panes)

tmux new-window -t "$SESSION_NAME:2" -n "services" -c "$PROJECT_DIR"

tmux send-keys -t "$SESSION_NAME:2.1" "cd frontend && npm run dev" C-m


# Split vertically for Backend API

tmux split-window -v -t "$SESSION_NAME:2.1" -c "$PROJECT_DIR/backend"

tmux send-keys -t "$SESSION_NAME:2.2" "source venv/bin/activate && uvicorn main:app --reload" C-m


# 3. Create Window 3: Database & Git terminal

tmux new-window -t "$SESSION_NAME:3" -n "git-db" -c "$PROJECT_DIR"

tmux send-keys -t "$SESSION_NAME:3.1" "docker compose up -d postgres" C-m


# Focus back on code window and attach

tmux select-window -t "$SESSION_NAME:1"

tmux attach-session -t "$SESSION_NAME"

Log Monitoring Dashboard (4-Way Tiled Grid)

Automating a quad-pane log monitor for distributed microservices or AI coding agents (such as Claude Code) using select-layout tiled:

monitor-logs.sh

#!/usr/bin/env bash

SESSION="monitoring"


tmux new-session -d -s "$SESSION" -n "logs"

tmux send-keys -t "$SESSION:1.1" "tail -f /var/log/nginx/access.log" C-m


tmux split-window -h -t "$SESSION:1"

tmux send-keys -t "$SESSION:1.2" "tail -f /var/log/nginx/error.log" C-m


tmux split-window -v -t "$SESSION:1.1"

tmux send-keys -t "$SESSION:1.3" "journalctl -u postgresql -f" C-m


tmux split-window -v -t "$SESSION:1.2"

tmux send-keys -t "$SESSION:1.4" "htop" C-m


# Balance all 4 panes into a 2x2 symmetrical grid

tmux select-layout -t "$SESSION:1" tiled

tmux attach-session -t "$SESSION"

Pure Shell Scripts vs Tmuxinator vs Teamocil

Approach Pros Cons Best For
Pure Bash Scripts ✅ 0 dependencies, instant startup, full conditional logic. ⚠️ Slightly more verbose than YAML. Any server, CI/CD, portable dotfiles.
Tmuxinator ✅ Clean YAML format, project templates. ❌ Requires Ruby runtime installation. Ruby/Rails shops, YAML enthusiasts.
Teamocil ✅ YAML layouts, easy pane weights. ❌ Infrequent maintenance, requires Ruby. Legacy workflows.

Related Tutorials & References