Claude Code, tmux, and Remote Servers: A Safe Setup Guide
Why Claude Code and tmux work well on remote servers
Claude Code is most useful when it can inspect a real repository, run tests, edit files, and keep context across a development task. A remote Linux server is often the right place for that work: it may have the application dependencies, internal network access, larger compute resources, or a persistent development environment. The problem is that SSH connections disconnect. A laptop sleep event, Wi-Fi change, or terminal crash can interrupt a long-running command and leave you unsure whether an AI-assisted task finished.
tmux solves the persistence problem. It keeps terminal sessions running on the remote machine after your local SSH connection closes. Claude Code continues operating inside the tmux session, while you can reconnect later from any authorized terminal and review its output. This is especially practical for repository analysis, test runs, migrations, and iterative debugging.
Decision guide: local, remote, or remote tmux?
- Use local Claude Code when the project is small, dependencies are installed locally, and you need direct access to local browser tools or files.
- Use Claude Code over plain SSH for short remote tasks where an interrupted session would not be costly, such as checking logs or making a small configuration change.
- Use Claude Code inside tmux on a remote server when work may take more than a few minutes, includes commands that must finish, or needs to survive disconnections.
- Use a dedicated development server when the repository contains credentials, production-adjacent infrastructure, or heavy dependencies. Avoid running an autonomous coding workflow directly on production unless the access and review process are deliberately restricted.
Set up the remote environment
Start by connecting with SSH and installing tmux through the server's package manager. On Debian or Ubuntu, the command is sudo apt update && sudo apt install tmux. Create a named session with tmux new -s claude-work. Naming sessions matters when you work on multiple projects or need to reconnect after several days.
Change into the repository directory before launching Claude Code. Keep configuration secrets outside the repository and out of shell history where possible. A practical approach is to place credentials in a protected environment file owned by your user, then load it only in the tmux session. Ensure that the file permissions are restrictive, such as mode 600.
For an Anthropic-compatible relay, configure the endpoint and key in the session environment. With 59API, set ANTHROPIC_BASE_URL=https://api.59api.com and set ANTHROPIC_API_KEY to your 59API key before starting Claude Code. Confirm the exact model identifiers available in your 59API dashboard or documentation, then set model variables only when you need to pin a specific model. This prevents accidental configuration drift between servers.
59API is a strong fit for this workflow because it provides pay-as-you-go access to official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, without forcing a model downgrade. Its compatibility with Claude Code also lets a team standardize a single low-cost API relay while retaining the option to use Codex or OpenAI SDK-based tools elsewhere.
Run Claude Code without losing control
Launch Claude Code from the project root inside tmux. Give it bounded tasks: ask it to inspect a failing test, propose a patch, run a specific test command, or explain a deployment configuration. For changes with operational impact, require a plan and diff review before it edits files. This keeps the agent useful while preserving normal engineering review boundaries.
Detach from the session with Ctrl-b d. Your terminal can close afterward without stopping processes in tmux. Later, reconnect with SSH and run tmux attach -t claude-work. If several sessions exist, use tmux ls first. When the task is complete, inspect git status, review the diff, run the relevant tests, and end the session with tmux kill-session -t claude-work.
Simple checklist before you start
- Use a non-production server or a tightly scoped account.
- Create a named tmux session from the repository root.
- Store API keys in protected environment configuration, never in source control.
- Set the 59API Anthropic-compatible base URL and API key in the active session.
- Ask Claude Code for a plan before broad edits or destructive commands.
- Review git diff and run tests before merging or deploying.
- Detach and reattach instead of leaving a fragile SSH connection open.
For developers who run Claude Code frequently on remote infrastructure, sign up for 59API to access compatible Claude and GPT models with predictable pay-as-you-go pricing; its referral rebate can further reduce ongoing experimentation costs.
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