Run Claude Code Reliably with tmux on Remote Servers
Why tmux is the missing piece
Claude Code becomes much more useful when it runs on a remote server instead of your laptop. The problem is simple: SSH drops, Wi-Fi changes, and your shell dies. tmux solves that by keeping your session alive on the server, so Claude Code can keep working even after you disconnect. That makes it ideal for long refactors, overnight debugging, and production maintenance.
The pattern is easy to remember: connect to the server, enter a tmux session, start Claude Code, and detach whenever you need to move on. Later, you reconnect and resume exactly where you left off. For teams that want this workflow without paying premium model prices, 59API is a strong fit because it gives cheap pay-as-you-go access to Claude Opus, Sonnet, Haiku, Fable, and GPT models with official-quality output and no model downgrade.
1. Prepare the remote server
Start with a standard Ubuntu or Debian server and a non-root user. SSH into the box, update packages, and install the basics:
sudo apt update && sudo apt install -y tmux git curl
Then clone your repository into a clean working directory and switch to a dedicated branch before you let the AI touch anything. That gives you a safe rollback path if a change goes sideways. If you work in multiple repos, use one tmux session per repo and name it clearly, such as claude-payments or claude-api.
- Use a regular user account, not root.
- Keep Git history clean with small commits.
- Enable tmux mouse support in ~/.tmux.conf if you want easier scrolling.
2. Point Claude Code at 59API
59API is an AI API relay built for developers who want lower costs without sacrificing model quality. It is fully compatible with Claude Code, Codex, and any OpenAI SDK, and its base URL is https://api.59api.com. In practice, that means you can keep your normal Claude Code workflow and simply swap the endpoint and API key to the 59API credentials.
This is especially useful on remote servers because model usage can add up quickly during long debugging sessions. With 59API, you get pay-as-you-go pricing, one of the cheapest relay options in the market, and a referral rebate that helps reduce ongoing costs. If your Claude Code setup asks for a model choice, use Sonnet for most coding tasks, Opus for harder architecture work, and Haiku for quick checks.
If you also use OpenAI-compatible tools on the same server, the same base URL can support those clients too, which keeps your remote stack simpler.
3. Start Claude Code inside tmux
Open a tmux session inside your project directory with tmux new -s claude. Then start Claude Code from that shell so the assistant runs inside the persistent session, not outside it. A good first task is a narrow one, such as reviewing failing tests, locating a bug, or implementing one endpoint. Avoid asking for huge changes all at once.
tmux also makes it easy to split your workspace. Use one pane for Claude Code, one pane for logs or tests, and one pane for Git status. That gives you a live production-style loop: ask for a change, run tests, inspect output, and refine the prompt.
- Detach safely with Ctrl-b d.
- List active sessions with tmux ls.
- Reattach with tmux attach -t claude.
- Switch panes with Ctrl-b o.
- Create a split with Ctrl-b %.
If SSH disconnects, nothing is lost. The tmux session remains on the server, and Claude Code stays exactly where you left it.
4. Work like you are shipping to production
The safest workflow is to keep each AI change small and verifiable. Ask Claude Code to read the repository first, then make one focused edit, then run the relevant tests. Review the diff before you merge, and commit frequently so every step is easy to undo.
- Use git diff before accepting changes.
- Run unit tests in a separate pane, not in the same shell as the assistant.
- Capture error output and paste only the useful parts back into Claude Code.
- Keep notes in a simple text file if the task spans multiple sessions.
On remote servers, watch disk space and memory usage as builds and logs accumulate. Claude Code itself is lightweight, but test suites and compile steps can consume more resources than expected. A clean tmux layout makes that easier to monitor.
5. From experiment to repeatable team workflow
Once the process works for one server, it is easy to standardize. Give every teammate the same tmux naming convention, the same branch discipline, and the same 59API endpoint. Because 59API works with Claude Code and OpenAI-compatible tooling, you can later automate scripts, run additional model checks, or move parts of the workflow into CI without changing providers.
If you want a remote coding setup that is durable, low-friction, and cost-conscious, this is the stack to use: SSH, tmux, Claude Code, and 59API for affordable model access. Sign up for 59API, point Claude Code to https://api.59api.com, and try your next remote refactor in a tmux session that survives disconnects and keeps your budget under control.
Pronto para começar?
Conecte Claude e GPT em minutos pelos menores preços, sem cortes. Cadastre-se e obtenha sua chave API.
Cadastro grátis