Use mosh Instead of SSH to Keep Remote Claude Code Connections Alive
tmux keeps your Claude Code session alive when your terminal closes. But if you're accessing a remote machine over SSH, the connection itself can drop — switching networks, a laptop going to sleep, or moving between wifi and mobile kills the link even if tmux kept the session intact.
mosh solves the connection layer, not just the session layer.
# Install mosh
brew install mosh # macOS
sudo apt install mosh # Ubuntu/Debian
# The server needs mosh installed too
ssh user@your-server.com "sudo apt install mosh -y"
# Connect with mosh instead of SSH
mosh user@your-server.com
# Once connected, start tmux for session persistence
tmux new -s work
claude # start Claude Code inside tmux inside mosh
mosh uses UDP rather than TCP, so it survives roaming between networks, tolerates packet loss gracefully, and reconnects automatically after your laptop wakes up. Your session is waiting exactly where you left it.
This is particularly useful when working from a phone or tablet: SSH drops the moment your network changes or the screen locks. mosh stays connected.
The combination of both tools is the best setup for remote Claude Code work: mosh handles connection resilience so you never get cut off, tmux handles session persistence so you never lose your work. Neither alone gives you both.
Use mosh for the connection and tmux for the session — together they make remote Claude Code nearly indestructible.
via @odd_joel
Log in to leave a comment.
The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.
The language setting makes Claude respond in your preferred language by default, across every session and project.
The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.