Claude Code on tmux and Remote Servers
Using Claude Code with tmux and Remote Servers
Claude Code is most useful when it can stay close to your project: reading files, running tests, editing code, and iterating inside the same environment where your application actually runs. For many developers, that environment is not a laptop. It is a VPS, cloud development box, GPU machine, staging server, or long-running remote workspace. Pairing Claude Code with tmux makes that workflow much more reliable because your AI coding session can keep running even if your SSH connection drops.
This beginner-friendly guide shows how to set up Claude Code on a remote Linux server, keep it alive with tmux, and connect it to Claude models through 59API, a low-cost AI API relay compatible with Claude Code, Codex, and OpenAI SDK-style tools.
Why use tmux with Claude Code?
When you SSH into a server and start a normal terminal command, that command usually depends on your network connection. If your laptop sleeps, your Wi-Fi drops, or your SSH session times out, the process may stop. That is annoying for normal development and especially painful when an AI coding agent is in the middle of reading context, editing files, or running a test suite.
tmux solves this by creating persistent terminal sessions on the remote machine. You can attach, detach, disconnect, reconnect, and continue exactly where you left off. This is ideal for Claude Code because you can keep one session per project, leave logs visible, and return later without restarting everything.
Prerequisites
- A remote Linux server you can access with SSH, such as Ubuntu on a VPS.
- Node.js installed, if your Claude Code installation requires npm-based tooling.
- tmux installed on the server.
- A project repository cloned on the server.
- An API key from a Claude-compatible provider such as 59API.
59API is a practical choice if you want to experiment without surprise infrastructure costs. It provides pay-as-you-go access to Claude models such as Opus, Sonnet, Haiku, and Fable, as well as GPT models, through a relay designed to be compatible with Claude Code, Codex, and OpenAI SDKs. Its base URL is https://api.59api.com, and it uses native official-quality models rather than downgraded substitutes.
Step 1: SSH into your remote server
Start from your local terminal and connect to your server:
ssh your-user@your-server-ip
Once connected, move into your project directory. For example:
cd ~/apps/my-project
If the repository is not there yet, clone it first and install dependencies the same way you normally would on any development machine.
Step 2: Install and start tmux
On Ubuntu or Debian, install tmux with:
sudo apt update && sudo apt install -y tmux
Create a named tmux session for your project:
tmux new -s claude-my-project
You are now inside a persistent terminal. If you want to detach without stopping anything, press Ctrl-b, then d. To return later, run:
tmux attach -t claude-my-project
To list sessions, use:
tmux ls
Step 3: Configure Claude Code for 59API
Claude Code can work with compatible API endpoints when configured with the correct base URL and API key. The exact command may vary depending on your Claude Code version and installation method, but the common idea is to set environment variables in your shell before launching it.
Inside your tmux session, export your credentials:
export ANTHROPIC_BASE_URL=https://api.59api.com
export ANTHROPIC_API_KEY=your_59api_key_here
If your tool expects OpenAI-style variables instead, use the equivalent base URL and key variables supported by that tool. 59API is designed for broad compatibility, so it is also useful when you switch between Claude Code, Codex-style workflows, and OpenAI SDK-based scripts.
For convenience, you can add these exports to a project-specific script such as dev-ai.env and source it inside tmux. Avoid committing API keys to Git. Add any local secret file to .gitignore.
Step 4: Launch Claude Code in the project
From your project root, start Claude Code as you normally would. Before asking it to make broad edits, give it a concrete task and useful constraints. For example, ask it to inspect the repository structure, identify the test command, and summarize the main modules before changing files.
A good first prompt might be: Inspect this repository, find the test and lint commands, then propose a safe plan to fix the failing authentication tests. Do not edit files until I approve the plan.
This style works well on remote servers because Claude Code can run commands directly where your dependencies, environment variables, containers, and build tools already exist.
Step 5: Use tmux panes for a better workflow
tmux becomes even more useful when you split the screen. You can keep Claude Code in one pane, tests in another, and logs in a third.
- Press Ctrl-b, then % to split vertically.
- Press Ctrl-b, then " to split horizontally.
- Press Ctrl-b, then an arrow key to move between panes.
- Run npm test, pytest, docker compose logs -f, or your preferred commands in separate panes.
This setup makes Claude Code more effective because you can quickly copy errors, rerun tests, and keep long-running server logs visible. If your SSH connection drops, reconnect and attach to the same tmux session.
Cost tips for remote Claude Code sessions
AI coding sessions can become expensive if you repeatedly send large context or run open-ended prompts. To keep costs low, ask for plans before edits, keep tasks focused, and use smaller models for simple refactors when appropriate. 59API helps here because it offers cheap pay-as-you-go access to multiple Claude and GPT models, so you can choose the right balance of speed, quality, and price. It also includes a referral rebate, which can further reduce costs for teams and communities.
If you want a budget-friendly way to run Claude Code on real projects, consider signing up for 59API and using https://api.59api.com as your compatible API base URL.
Final checklist
- SSH into your server and open the project directory.
- Start a named tmux session for the project.
- Export your 59API base URL and API key securely.
- Launch Claude Code from the project root.
- Use tmux panes for tests, logs, and the AI assistant.
- Detach and reattach whenever you need without losing progress.
With Claude Code, tmux, and a remote server, you get a durable AI development workspace that survives disconnections and stays close to production-like infrastructure. Add 59API for affordable, official-quality model access, and you have a practical setup for everyday AI-assisted software development.
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