Tmux Session Management Skill
Overview
This system uses tmux with tmuxinator templates and sesh for powerful session management.
Configuration Locations
- •Tmuxinator templates:
~/.config/tmuxinator/*.yml - •Tmux config:
~/.tmux.conf - •Zsh tmux aliases/functions:
~/.zshrc(lines 37-72) - •Active sessions: Check with
tmux lsorsesh list
Tmuxinator Templates
Current Templates
- •
default.yml - Flexible project template
- •Takes directory argument:
tmuxinator start default ~/path - •Layout: nvim (top 70%), terminal + claude (bottom)
- •Dynamic session naming based on directory
- •Takes directory argument:
- •
admin.yml - System monitoring
- •Fixed name: "admin"
- •Layout: btop (left column), 2 terminals (right)
- •Purpose: System monitoring and administration
- •
config.yml - Dotfiles editing
- •Fixed name: "config"
- •Root:
~/.config - •Layout: nvim (top 70%), terminal + claude (bottom)
Template Structure
CRITICAL: Pane Indexing
This tmux configuration uses 1-based indexing (set in ~/.tmux.conf):
set -g base-index 1 # Windows start at 1 set -g pane-base-index 1 # Panes start at 1
- •First pane = 1, second = 2, third = 3
- •Use
prefix + q(Ctrl+Space then q) to see pane numbers visually - •When targeting panes in commands:
select-pane -t 1(not -t 0)
Tmuxinator YAML Structure:
---
name: session-name # Fixed name (or use <%= File.basename(...) %> for dynamic)
root: ~/path # Working directory
on_project_start: tmux resize-pane -t name:0.0 -y 70% # Optional startup commands
windows:
- window-name:
layout: main-horizontal # or main-vertical, tiled, even-horizontal, etc.
panes:
- nvim # Command to run in pane 1
- # empty terminal # Empty pane (interactive shell) - pane 2
- claude --resume # Command for pane 3
Shell Function Structure (for creating windows dynamically):
tnw() {
# Get the session's root directory (uses 1-based indexing internally)
local session_path=$(tmux display-message -p '#{session_path}')
tmux new-window -c "$session_path" \; \
split-window -v -c "$session_path" \; \
split-window -v -c "$session_path" \; \
select-layout main-horizontal \; \
select-pane -t 1 \; \
send-keys 'nvim' C-m \; \
select-pane -t 3 \; \
send-keys 'claude --resume' C-m \; \
select-pane -t 2
}
Key points for both:
- •Use
#{session_path}to get session root directory (not current pane path) - •Pane indexing is 1-based: first pane = 1, not 0
- •
send-keys 'command' C-mexecutes commands in panes (C-m = Enter) - •
select-pane -t Nfocuses pane N (1-based) - •
select-layoutapplies tmux built-in layouts
Common Layouts
- •
main-horizontal- Top pane large, others stacked below - •
main-vertical- Left pane large, others stacked right - •
tiled- All panes equal size - •
even-horizontal- Panes side-by-side equal width - •
even-vertical- Panes top-to-bottom equal height
Session Management with ts (tmux session selector)
The ts function (defined in ~/.zshrc) is the main session switcher:
ts # Opens fzf with: "home" + tmuxinator templates + active sessions
How ts Works
- •Lists all tmuxinator templates (except default.yml)
- •Adds "home" as an option
- •Shows all active tmux sessions from
sesh list - •On selection:
- •If session exists → attach with
sesh connect - •If tmuxinator template exists →
tmuxinator start <template> - •Otherwise →
tmuxinator start default <name>(creates new project session)
- •If session exists → attach with
Key Insight
Template names come from the filename (e.g., admin.yml → "admin" in fzf), but the actual tmux session name comes from the name: field in the YAML file.
Tmux Functions & Aliases
From ~/.zshrc:
Session Management
ts # Tmux session selector (fzf for sessions/templates) tns <name> # Tmux new session - create git project & open with tmuxinator t [name] # Smart attach/create - attach if exists, create if not ta <name> # Attach to session tn <name> # Create new session tls # List sessions tk <name> # Kill session
Window Management
tnw # Tmux new window - create window with 3-pane layout
# Layout: pane 1=nvim, pane 2=terminal (focused), pane 3=claude
# Bound to: prefix + N
Utilities
tcopy # Copy tmux buffer to clipboard tlines [n] # Copy last n lines from tmux pane to clipboard
Common Workflows
Starting Sessions
ts # Use fzf to select session/template tns myproject # Create ~/git/myproject with git + tmuxinator tns myproject config # Use 'config' template instead of default tmuxinator start admin # Start admin monitoring tmuxinator start config # Edit dotfiles tmuxinator start default ~/git/myproject # New project session with default template
Creating Windows
tnw # Create new window with 3-pane layout in current session prefix + N # Keybinding for tnw (Ctrl+Space then Shift+N) prefix + c # Create empty new window (default tmux) prefix + , # Rename current window
Creating New Templates
- •Create
~/.config/tmuxinator/name.yml - •Use existing templates as reference
- •Test with
tmuxinator start name - •Now available in
sfautomatically
Auto-Start Behavior
On terminal startup (from ~/.zshrc:272-275):
- •Creates "home" session if it doesn't exist
- •Runs in background (detached)
- •Provides a default session to attach to
Best Practices
- •Fixed names for utilities: Use
name: adminfor consistent session names - •Dynamic names for projects: Use
<%= File.basename(...) %>for project-based naming - •Exclude default from sf: The default template is a fallback, not a session target
- •Keep layouts simple: 2-3 panes max for usability
- •Use comments for empty panes:
# interactive shellfor clarity
Troubleshooting
- •Wrong session name: Check
name:field in YAML vs filename - •Template not showing in sf: Ensure
.ymlextension and not named "default" - •Layout issues: Try
tmux kill-session -t nameand restart - •Pane sizes: Use
on_project_startwithtmux resize-panecommands