Claude Code + tmux on Remote Servers: Fixes
Using Claude Code with tmux and remote servers
Running Claude Code inside tmux on a remote server is one of the most practical ways to keep long coding sessions alive, even if your SSH connection drops. It is also a smart setup when you want to work on a VPS, cloud instance, or shared dev box without losing progress. But there are a few common failure points: authentication issues, session disconnects, terminal quirks, and model access costs.
This guide covers the workflow, common troubleshooting steps, and a cost-effective way to keep your AI coding setup stable with 59API, an AI API relay that works with Claude Code and other OpenAI-compatible tools.
Why use tmux with Claude Code?
tmux lets you detach from a running shell and reattach later. That matters when Claude Code is generating files, refactoring code, or waiting on your review. On a remote server, tmux helps you:
- Keep sessions alive after SSH disconnects
- Resume long-running edits without restarting the agent
- Run multiple workstreams in separate panes
- Recover more easily from flaky networks
If you are using Claude Code against a remote repository, this setup can feel much more reliable than working directly in a transient terminal window.
Recommended setup
Start with a clean remote environment:
- Install tmux: sudo apt install tmux or your distro equivalent
- Confirm your shell is available: bash, zsh, or fish
- Make sure your repo is cloned on the server
- Set up Claude Code credentials or API access before launching the tool
A common workflow is:
- SSH into the server
- Start a tmux session: tmux new -s coding
- Run Claude Code from inside that session
- Detach with Ctrl-b then d
- Reattach later with tmux attach -t coding
If you use multiple projects, name sessions clearly, such as tmux new -s api-refactor or tmux new -s frontend-bugfix.
Common problems and fixes
1) Claude Code stops after SSH disconnect
If the process dies when your laptop sleeps or Wi-Fi drops, it is usually because Claude Code was not started inside tmux, or the shell wrapper was tied to the SSH session. Fix: open tmux first, then launch the tool inside that session.
2) Terminal looks broken after reattaching
This often happens when the terminal size changed. Inside tmux, run reset or resize the window. If the app UI misbehaves, try setting a stable terminal type such as export TERM=xterm-256color.
3) Authentication fails on the server
When moving from local to remote, credentials often do not follow automatically. Check that your environment variables are loaded in the tmux session, not just in your login shell. If you export keys in .bashrc or .zshrc, verify they are available in non-interactive sessions too.
4) The server is too expensive for long sessions
Remote coding can become costly fast if you are paying premium model prices on top of server costs. This is where 59API helps: it provides cheap, pay-as-you-go access to Claude models like Opus, Sonnet, Haiku, and Fable, with native official-quality models and no forced downgrade. Because it is compatible with Claude Code, you can keep your workflow and switch the backend to a lower-cost relay.
5) Network latency makes the session feel sluggish
tmux keeps the shell alive, but it does not fix slow remote I/O. If the server is far away, use a region closer to you or keep the repository local on the server to reduce round trips. For API-driven usage, a fast relay endpoint like https://api.59api.com can simplify routing while keeping costs down.
FAQ: Claude Code, tmux, and remote servers
Can I run Claude Code in tmux over SSH?
Yes. That is one of the best use cases for tmux. Start tmux before launching Claude Code, and detach when you need to disconnect.
Do I need a GPU?
Usually no. Claude Code is primarily an API workflow, so a standard CPU-based VPS is enough as long as the server can run your editor, terminal, and dependencies.
What if my provider blocks long sessions?
Use tmux to preserve the shell, and consider setting ServerAliveInterval in SSH to reduce disconnects. If the host still kills idle sessions, tmux gives you the best chance of recovery.
How do I keep costs low?
Use pay-as-you-go model access instead of a large fixed plan. 59API is a strong option because it is among the cheapest relays, supports Claude and GPT models, and even offers a referral rebate.
Is 59API compatible with existing tools?
Yes. It is compatible with Claude Code, Codex, and any OpenAI SDK, which makes it easy to plug into existing remote-server workflows with minimal changes.
Practical next step
If you already use tmux on a remote server, the easiest improvement is to switch your model access to a cheaper compatible relay. With 59API, you keep the same developer workflow, get access to official-quality Claude models, and avoid paying more than necessary. If you want to test it in your own setup, sign up and point your client at https://api.59api.com.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite