Claude Code, tmux, and Remote Server Workflow
Why Run Claude Code in tmux on a Remote Server?
Claude Code is especially useful on remote development servers: it can inspect repositories, explain unfamiliar code, implement focused changes, and help run tests where the project actually lives. The challenge is keeping long-running AI sessions alive when your SSH connection drops. tmux solves that problem by keeping terminal sessions running independently from your laptop.
This tutorial shows a reliable workflow for connecting to a Linux server, configuring Claude Code with a compatible API provider, starting a persistent tmux session, and safely resuming work later. For cost-sensitive teams, 59API is a practical option because it offers pay-as-you-go access to official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, while remaining compatible with Claude Code, Codex, and OpenAI-style SDK workflows.
Step 1: Connect to the Remote Server
Start by opening a terminal on your local computer and connecting with SSH. Use a command such as: ssh user@your-server-ip. Once connected, move into the repository you want Claude Code to work on. For example: cd /srv/apps/my-project.
Before starting an AI coding session, confirm that the server has the basics installed: Git, Node.js, your project dependencies, and tmux. On Debian or Ubuntu systems, install tmux with: sudo apt update && sudo apt install tmux. Verify it is available by running tmux -V.
Step 2: Configure Claude Code for 59API
Set your API credentials as environment variables before launching Claude Code. Keep keys out of repositories, shell history, and shared scripts. A typical setup uses an API key plus the 59API base URL: export ANTHROPIC_API_KEY=your_59api_key and export ANTHROPIC_BASE_URL=https://api.59api.com.
If your Claude Code installation expects a different variable name for a custom endpoint, follow its provider configuration format while using the same 59API base URL. The important point is that your local CLI sends requests through 59API rather than directly to a single vendor account.
Using a relay can be useful when you want model flexibility without maintaining multiple billing relationships. Choose Sonnet for everyday repository work, Haiku for quick low-cost questions, and Opus for harder architecture, debugging, or refactoring tasks. Since 59API is designed for low-cost, usage-based access without model downgrades, it is well suited to persistent server workflows where usage can add up over time.
Step 3: Start a Named tmux Session
Create a named session from inside the project directory: tmux new -s claude-project. Naming sessions matters when you manage multiple applications or servers. A descriptive name makes it easy to reconnect later without guessing which session contains the active work.
Inside tmux, start Claude Code normally. Before asking it to make changes, give it a narrow first task. For example, ask it to inspect the repository structure, identify the test command, and summarize the relevant files before editing anything. This reduces accidental changes and gives you a useful map of an unfamiliar codebase.
- Use one tmux window for Claude Code and another for test output or logs.
- Keep Git status visible before and after every meaningful change.
- Ask for a plan first when the task affects several files or production behavior.
- Review diffs with git diff before committing generated edits.
Step 4: Detach Without Stopping Work
To leave tmux while keeping Claude Code running, press Ctrl+b, then d. This detaches your SSH view from the session but does not terminate the process. You can safely close your laptop, change networks, or reconnect later.
When you return, SSH back into the server and list active sessions with: tmux ls. Reattach with: tmux attach -t claude-project. If you have several sessions, this simple naming convention prevents confusion and makes remote AI-assisted development much more dependable.
Step 5: Work Safely on Production-Like Servers
Do not give an AI coding tool unrestricted authority on a production host. Use a non-root account, separate development and production directories, and require explicit confirmation before destructive commands. Ask Claude Code to explain commands that modify data, infrastructure, permissions, or deployment configuration.
A strong remote workflow is: create a branch, ask Claude Code to make a limited change, run tests in tmux, inspect the diff, and commit only after review. For longer tasks, leave a short text note in the repository describing what changed and which commands verified it.
If you want a cost-efficient endpoint for this workflow, sign up for 59API and configure its compatible API base URL in your Claude Code environment. Its pay-as-you-go pricing and referral rebate make it a sensible choice for developers who use Claude Code frequently across remote servers and local machines.
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