| name | Fixing tmux Socket Issues |
| description | This skill repairs tmux socket connection errors when the socket directory is deleted while tmux is running. Use this when you see "error connecting to /private/tmp/tmux-UID/default (No such file or directory)" while tmux sessions are still active. |
| allowed-tools | ["Bash","Read"] |
Fixing tmux Socket Issues
Repair tmux socket connection errors without killing your running sessions.
What This Skill Does
- Diagnoses tmux socket connection failures
- Recreates missing socket directories
- Signals tmux server to recreate socket files
- Verifies manual save/restore functionality
- Preserves all running sessions and processes
When to Use This Skill
Symptoms:
- Error:
error connecting to /private/tmp/tmux-UID/default (No such file or directory)
tmux list-sessions fails but you're inside a working tmux session
$TMUX environment variable is set but socket file doesn't exist
- tmux-resurrect manual save fails but automatic saves may appear to work
Common causes:
- System
/tmp directory cleanup
- System updates or reboots
- Manual deletion of temp directories
How tmux Sockets Work
tmux uses a UNIX domain socket for client-server communication. The socket path format is:
/private/tmp/tmux-UID/default
Where UID is your user ID (e.g., 504).
Why sessions survive socket deletion:
- The tmux server process keeps the socket open as a file descriptor
- Existing connections continue to work
- New connections fail because the filesystem path is gone
- The server is alive but unreachable by new clients
Prerequisites
- Active tmux session - You must be inside a running tmux session
- Shell access - Ability to run commands (inside or outside tmux)
- Permissions - Ability to create directories in
/private/tmp or /tmp
Diagnosis Steps
Step 1: Verify the Problem
Check if you're in tmux but the socket is missing:
echo $TMUX
tmux list-sessions
ls -la /private/tmp/tmux-*/
If all three conditions are true (TMUX set, list-sessions fails, directory missing), proceed with the fix.
Step 2: Check Last Successful Save
Verify when tmux-resurrect last successfully saved:
ls -lh ~/.tmux/resurrect/last
stat ~/.tmux/resurrect/last
Note the timestamp. If it's old (before the socket disappeared), automatic saves are likely also failing.
Repair Steps
Step 1: Recreate Socket Directory
Extract the socket directory path from $TMUX:
echo $TMUX
Create the directory with correct permissions:
mkdir -p /private/tmp/tmux-504
chmod 700 /private/tmp/tmux-504
Permission requirements:
- Directory must be owned by your user
- Permissions must be
700 (drwx------) for security
Step 2: Find tmux Server PID
The tmux server is the oldest tmux process:
ps aux | grep tmux | grep -v grep
Look for the process with:
- Oldest start time
- Command
tmux (not tmux attach)
- Usually the lowest PID
Example output:
jonathan 1632 1.1 0.0 435326336 5184 ?? Ss 1Nov25 102:36.11 tmux
jonathan 22779 0.0 0.0 435309312 624 s077 S+ 1Nov25 0:00.05 tmux attach -t 3
In this example, PID 1632 is the server (started Nov 25, command is just tmux).
Step 3: Signal tmux to Recreate Socket
Send SIGUSR1 to the tmux server process:
kill -SIGUSR1 1632
What this does:
- Signals the tmux server to recreate its socket file
- Does NOT kill or restart tmux
- Reconnects the running server to the filesystem
- Preserves all sessions, windows, and processes
Alternative (if you only run one tmux server):
pkill -USR1 -x tmux
This sends SIGUSR1 to all processes named exactly "tmux".
Step 4: Verify the Fix
Check that the socket file was recreated:
ls -la /private/tmp/tmux-504/
tmux list-sessions
~/.tmux/plugins/tmux-resurrect/scripts/save.sh
ls -lh ~/.tmux/resurrect/last
Verification Checklist
After applying the fix:
Troubleshooting
Issue: "Permission denied" when creating directory
Cause: /private/tmp or /tmp may require elevated permissions
Solution:
sudo mkdir -p /private/tmp/tmux-504
sudo chown $(whoami) /private/tmp/tmux-504
chmod 700 /private/tmp/tmux-504
Issue: Socket not recreated after SIGUSR1
Symptoms: Directory exists but socket file still missing after signal
Causes:
- Wrong PID (sent signal to client, not server)
- Parent directory permissions incorrect
- Tmux server in unusual state
Solutions:
-
Verify you got the right PID:
ps aux | grep '[t]mux' | grep -v attach
-
Check directory permissions:
ls -ld /private/tmp/tmux-504
-
If still failing, check tmux server is responsive:
tmux refresh-client
-
Last resort - restart tmux server (will lose session state):
tmux kill-server
tmux
Issue: Multiple tmux servers running
Symptoms: ps aux | grep tmux shows multiple "tmux" processes (not "tmux attach")
Cause: Multiple independent tmux servers on different sockets
Solution:
-
Identify which server you're attached to:
echo $TMUX
-
Send SIGUSR1 only to that specific PID:
kill -SIGUSR1 <specific_pid>
Issue: macOS-specific pgrep syntax error
Symptoms: pgrep: illegal option -- -
Cause: macOS uses BSD pgrep which has different options than GNU pgrep
Solution:
pgrep -o tmux
ps aux | grep tmux | grep -v grep
tmux-resurrect Keybindings
For reference, the correct keybindings with a custom prefix:
Default prefix: Ctrl+b
- Save:
Ctrl+b then Ctrl+s
- Restore:
Ctrl+b then Ctrl+r
Custom prefix: Ctrl+a (as in your config)
- Save:
Ctrl+a then Ctrl+s
- Restore:
Ctrl+a then Ctrl+r
Verify your bindings:
tmux list-keys | grep resurrect
Expected output:
bind-key -T prefix C-r run-shell /path/to/restore.sh
bind-key -T prefix C-s run-shell /path/to/save.sh
Prevention
To reduce the likelihood of this issue:
-
Use XDG_RUNTIME_DIR (Linux):
export TMUX_TMPDIR=$XDG_RUNTIME_DIR
This directory persists across reboots on systemd systems.
-
Custom socket location:
tmux -S ~/.tmux/socket new-session
-
System configuration (requires root):
- Exclude
/tmp/tmux-* from automated cleanup scripts
- Configure
tmpwatch or similar tools to skip tmux directories
Best Practices
- Respond quickly: Fix the socket as soon as you notice the error to avoid confusion
- Verify timestamps: Always check that saves are actually happening after the fix
- Document your UID: Note your user ID for faster diagnosis next time
- Keep sessions active: The fix works because sessions are still running; if you kill tmux first, you'll need to restore from last save
- Regular saves: Use
Ctrl+a Ctrl+s periodically for important session states
Related Skills
- configuring-neovim - For fixing Neovim session restoration with tmux-resurrect
- working-with-terminals - For understanding terminal multiplexer fundamentals
Understanding tmux-continuum Behavior
Why automatic saves appear to work:
tmux-continuum runs inside the tmux server process using run-shell. In some cases:
- Old save timestamps may persist, making it look like saves are working
- The actual save attempts are failing silently
- Check timestamps carefully to confirm saves are current
After fixing:
- Monitor
~/.tmux/resurrect/last timestamp
- Verify it updates every 15 minutes (or your configured interval)
- First new save confirms the fix worked
Quick Reference
mkdir -p /private/tmp/tmux-$(id -u)
chmod 700 /private/tmp/tmux-$(id -u)
ps aux | grep '[t]mux' | grep -v attach
kill -SIGUSR1 <server_pid>
tmux list-sessions
ls -la /private/tmp/tmux-$(id -u)/
Additional Resources