Skip to content

Workflow 003: Pair Programming

Fresh

Share tmux sessions for collaborative coding and pair programming.

When to Use

  • Remote pair programming
  • Teaching/mentoring sessions
  • Collaborative debugging
  • Code reviews in real-time

How It Works

Both users connect to the same tmux session - everyone sees the same screen and can interact.

Setup Methods

Method 1: Shared User Account

Simplest approach - both users SSH as the same user.

bash
# User A starts session
ssh shared@server
tmux new -s pair

# User B joins
ssh shared@server
tmux attach -t pair

Security Note

Both users have the same permissions. Use only with trusted collaborators.

Method 2: Shared Socket

More secure - each user has their own account but shares a socket.

Setup

bash
# User A creates session with shared socket
tmux -S /tmp/pair-socket new -s pair

# Set permissions for group
chmod 770 /tmp/pair-socket

Join

bash
# User B (in same group) connects
tmux -S /tmp/pair-socket attach -t pair

tmate is tmux with built-in sharing:

bash
# Install tmate
brew install tmate    # macOS
apt install tmate     # Ubuntu

# Start session (generates share URL)
tmate

# Share the SSH command shown:
# ssh ro-xxxxx@nyc1.tmate.io  # Read-only
# ssh xxxxx@nyc1.tmate.io     # Read-write

Session Modes

Full Collaboration

Both users can type and navigate:

bash
# Default mode - both attached to same view
tmux attach -t pair

Independent Views (Same Session)

Users share session but can view different windows:

bash
# User B creates new grouped session
tmux new-session -t pair -s pair-b

# Now User B can navigate independently
# Changes to files/commands still shared

Read-Only Viewer

For demos or presentations:

bash
# Presenter
tmux new -s demo

# Viewer (read-only)
tmux attach -t demo -r

Practical Pair Programming

Driver/Navigator Pattern

Setup

bash
# Driver creates session
tmux new -s pair

# Create coding layout
Ctrl+b %    # Split for terminal
bash
tmux attach -t pair

Swap roles

bash
# Driver detaches keyboard focus
# Navigator takes over typing
# No technical change needed - just agree who types!

Code Review Session

bash
# Reviewee shares screen
tmux new -s review

# Setup review layout
# Pane 1: Code (vim)
# Pane 2: Terminal for testing
# Pane 3: Git log/diff

Ctrl+b %    # Split
Ctrl+b "    # Split again

# Reviewer joins
tmux attach -t review -r    # Read-only is fine for reviewers

Communication

Since tmux is terminal-only, combine with:

  • Voice call (Zoom, Meet, Discord)
  • Text chat in a tmux pane
  • Shared notes in a file

In-Session Chat

Create a chat window:

bash
# Create chat window
Ctrl+b c
Ctrl+b ,    # Rename to "chat"

# Both users can type messages here
# Use different colors/prefixes:
echo "[Alice] Ready to start?"
echo "[Bob] Yes, let's go!"

Best Practices

1. Establish Conventions

  • Who's driving?
  • How to request control?
  • Break signals?

2. Use Visual Cues

bash
# Add user indicator to status bar
# In ~/.tmux.conf
set -g status-right '#[fg=yellow]PAIR MODE #[fg=white]%H:%M'

3. Sync Environment

bash
# Both users should have similar:
# - Shell (bash/zsh)
# - Editor (vim/nvim)
# - Color schemes

4. Handle Conflicts

bash
# If both type simultaneously, chaos ensues!
# Use clear handoffs:
"Your turn" / "Taking over"

Troubleshooting

Screen size mismatch

Solution

The smaller terminal wins. Ask partner to resize:

bash
# Check attached clients
tmux list-clients

# Force resize to largest
:setw aggressive-resize on

Or use independent views (grouped sessions).

Can't see partner's cursor

Solution

tmux doesn't show multiple cursors. Use communication:

  • Voice: "I'm on line 42"
  • Or use different pane colors

Latency issues

Solution

  • Use server geographically between both users
  • Consider tmate's regional servers
  • Reduce status bar update frequency:
bash
set -g status-interval 15

Permission denied on socket

Solution

Check socket permissions:

bash
ls -la /tmp/pair-socket
chmod 770 /tmp/pair-socket
# Ensure both users in same group

Security Considerations

  1. Shared user = shared access - Be careful what's accessible
  2. Socket files - Clean up after session: rm /tmp/pair-socket
  3. tmate - URLs are public-ish; don't share sensitive sessions
  4. SSH keys - Don't share private keys for pairing

See Also

Generated with AI-powered SOP Generator