If you're running Claude Code on a VPS, you need one tool: tmux. Without it, a dropped SSH connection kills your session — and your AI coding run dies with it.
✅ What tmux solves
- Keep Claude Code running after disconnects
- Reattach later without losing work
- Run long tasks overnight safely
Step 1: Install tmux
Step 2: Start a Named Session
Use a memorable name like claude so you can reattach easily.
Step 3: Run Claude Code Inside tmux
Start Claude Code the same way you normally do:
Step 4: Detach Without Killing It
To leave the session running in the background:
Step 5: Reattach Later
List sessions and reattach:
✅ Pro Tip
If you only have one session, you can simply run tmux attach without the name.
Essential tmux Commands (Cheat Sheet)
- Create session:
tmux new -s claude - Detach:
Ctrl+bthend - List sessions:
tmux ls - Reattach:
tmux attach -t claude - Kill session:
tmux kill-session -t claude
⚠️ Common Mistake
Typing exit inside tmux ends the session completely. If you just want to disconnect, always use Ctrl+b then d.
Optional: Increase Scrollback
If you want to scroll through longer logs, add this to ~/.tmux.conf:
Reload tmux config:
Want More VPS + AI Coding Guides?
Join Vibe Coding Academy for step-by-step tutorials, real-world fixes, and a community of builders shipping with AI.
Join the AcademyKey Takeaways
- tmux keeps Claude Code running even if SSH drops
- Always use named sessions for easy reattach
- Detach, don’t exit (Ctrl+b then d)
- Use the cheat sheet to manage sessions fast