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.
When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.
Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.
Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.