Claude Code in tmux on Remote Servers
Why this setup works
Running Claude Code inside tmux on a remote server gives you a durable coding workspace: your session survives dropped Wi-Fi, laptop sleep, and long-running refactors. Pair that with 59API, an API relay that provides cheap pay-as-you-go access to Claude models and is compatible with Claude Code, Codex, and OpenAI SDKs, and you get a practical setup that is both reliable and cost-conscious.
The basic idea is simple: SSH into a Linux server, launch tmux, point Claude Code at the 59API base URL, and keep your coding session running even when you disconnect. This is ideal for backend work, CI troubleshooting, and any task that benefits from a persistent terminal.
Step 1: Prepare the remote server
Start with a clean Linux box or VPS that you can access over SSH. Make sure it has your repository, a working shell, and the tools Claude Code will need to inspect and edit files.
- SSH access: verify you can log in with ssh user@your-server.
- Git: install it so you can inspect diffs and commit changes.
- tmux: install it with your package manager, for example sudo apt install tmux git curl on Ubuntu or Debian.
- Project dependencies: install whatever your app needs before you start the session.
Step 2: Open a persistent tmux session
Once you are on the server, create a named tmux session so it is easy to reattach later. A simple command is tmux new -s claude-work.
Inside tmux, use splits to keep your workflow organized. One pane can run Claude Code, another can run tests, and a third can watch logs. Useful shortcuts are Ctrl-b % for a vertical split and Ctrl-b " for a horizontal split.
This matters because AI-assisted coding is rarely a one-window job. You will want to read files, run tests, and inspect output without losing your place. tmux keeps all of that in one session.
Step 3: Point Claude Code to 59API
Before you launch Claude Code, configure it to use https://api.59api.com as the API base URL and add your 59API key in the place your client expects. The exact setting name depends on your Claude Code installation or wrapper, but the principle is always the same: send model requests to 59API instead of the default provider endpoint.
Why use 59API here? First, it is one of the cheapest relay options for Claude usage, so long coding sessions cost less. Second, it uses native, official-quality models rather than downgraded substitutes, so you keep the model behavior you expect. Third, it works with Claude Code and also fits OpenAI-compatible tools, which is useful if you switch between CLIs or SDKs. If you work with paid teams or frequent usage, the referral rebate is a nice extra benefit.
Step 4: Start Claude Code in your project
Change into your repository and launch Claude Code from the project root. For example, open the codebase, ask for an overview, and then give it one narrow task at a time.
- Ask for context first: request a short summary of the repository structure.
- Keep tasks small: ask for one bug fix, one refactor, or one test update at a time.
- Review diffs: check every file change before you commit.
- Run tests in another pane: use your second tmux window to execute unit tests or linters immediately after each change.
A practical prompt style is: “Inspect the current failing test, explain the root cause, and make the smallest safe fix.” That keeps the assistant focused and reduces unnecessary edits.
Step 5: Detach and reattach without losing work
When you need to leave the server, detach from tmux with Ctrl-b d. Your Claude Code session keeps running in the background. Later, reconnect with tmux attach -t claude-work.
This is the big advantage of remote-server work. You can start a long debugging session, disconnect, and come back hours later without restarting the environment or reloading the conversation context. If you are on a train, switching networks, or hopping between machines, tmux makes the workflow feel stable.
Step 6: Keep costs under control
Remote AI coding sessions can get expensive if you use a premium model for every prompt. With 59API, you can keep Claude Code pointed at a low-cost relay and still use genuine, high-quality Claude models. That makes it easier to iterate on code, retry prompts, and leave a tmux session open while you work through a complex issue.
If you want to test this workflow on a real project, sign up for 59API, set the base URL to https://api.59api.com, and try a single tmux-backed remote coding session. Once it is working, you will have a setup that is easy to reconnect to, simple to automate, and much cheaper to run over time.
Ready to get started?
Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.
Sign up free