Workflow 003: Pair Programming
FreshShare 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.
# User A starts session
ssh shared@server
tmux new -s pair
# User B joins
ssh shared@server
tmux attach -t pairSecurity 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
# User A creates session with shared socket
tmux -S /tmp/pair-socket new -s pair
# Set permissions for group
chmod 770 /tmp/pair-socketJoin
# User B (in same group) connects
tmux -S /tmp/pair-socket attach -t pairMethod 3: tmate (Recommended for Remote)
tmate is tmux with built-in sharing:
# 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-writeSession Modes
Full Collaboration
Both users can type and navigate:
# Default mode - both attached to same view
tmux attach -t pairIndependent Views (Same Session)
Users share session but can view different windows:
# 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 sharedRead-Only Viewer
For demos or presentations:
# Presenter
tmux new -s demo
# Viewer (read-only)
tmux attach -t demo -rPractical Pair Programming
Driver/Navigator Pattern
Setup
# Driver creates session
tmux new -s pair
# Create coding layout
Ctrl+b % # Split for terminalNavigator joins
tmux attach -t pairSwap roles
# Driver detaches keyboard focus
# Navigator takes over typing
# No technical change needed - just agree who types!Code Review Session
# 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 reviewersCommunication
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:
# 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
# Add user indicator to status bar
# In ~/.tmux.conf
set -g status-right '#[fg=yellow]PAIR MODE #[fg=white]%H:%M'3. Sync Environment
# Both users should have similar:
# - Shell (bash/zsh)
# - Editor (vim/nvim)
# - Color schemes4. Handle Conflicts
# 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:
# Check attached clients
tmux list-clients
# Force resize to largest
:setw aggressive-resize onOr 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:
set -g status-interval 15Permission denied on socket
Solution
Check socket permissions:
ls -la /tmp/pair-socket
chmod 770 /tmp/pair-socket
# Ensure both users in same groupSecurity Considerations
- Shared user = shared access - Be careful what's accessible
- Socket files - Clean up after session:
rm /tmp/pair-socket - tmate - URLs are public-ish; don't share sensitive sessions
- SSH keys - Don't share private keys for pairing