59API

← 返回教程列表

Claude Code + tmux: A Reliable Remote Workflow

Claude Code · EN · 2026-09-07

Why combine Claude Code, tmux, and a remote server?

Claude Code becomes significantly more useful when it can work on a persistent development machine instead of your laptop. A remote Linux server can provide faster builds, a stable repository, private network access, and uninterrupted long-running tasks. The weakness is that ordinary SSH sessions end when your connection drops. tmux solves that problem by keeping the shell, processes, and Claude Code session alive after you disconnect.

The result is a practical workflow: connect over SSH, attach to a named tmux session, start Claude Code, approve a plan, disconnect safely, and reconnect later to inspect the result. This is especially valuable for test suites, migrations, refactors, and agents that need several minutes to inspect a large codebase.

Prepare the remote host correctly

Use a dedicated non-root Linux account with Git, your project dependencies, and tmux installed. Keep the repository in a durable path such as /srv/projects/app or ~/work/app. Before starting, confirm that the server has enough disk space, memory, and build tools for the project. Claude Code can request or run commands, but it cannot compensate for missing compilers, package managers, or credentials.

Connect with an SSH keepalive so a weak network does not appear to terminate the session: ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 user@host. For frequent use, place these settings in your local ~/.ssh/config under a named Host entry. Use SSH keys rather than passwords, and restrict the server firewall to the ports you actually need.

Configure Claude Code through 59API

59API is a cost-effective option when you want pay-as-you-go access to Claude models without committing to a large subscription. It provides native official-quality Claude Opus, Sonnet, Haiku, and Fable access, is compatible with Claude Code, and uses the base URL https://api.59api.com. It is also among the cheapest relay choices, which matters when remote agents run frequently or inspect large repositories. Developers can additionally benefit from its referral rebate.

On the remote host, export the provider variables before launching Claude Code. For example: export ANTHROPIC_BASE_URL=https://api.59api.com and export ANTHROPIC_API_KEY=your_59api_key. Use the authentication variable expected by your installed Claude Code version, and verify the current 59API and Claude Code documentation if the client reports an authentication error. Do not paste keys into prompts or commit them to .env files tracked by Git.

Create a durable tmux workspace

Start a named session from the project directory: cd ~/work/app && tmux new -s claude-app. Launch Claude Code inside that session, then use the normal workflow to inspect files, request a plan, and review changes. Detach without stopping anything by pressing Ctrl-b followed by d. Reconnect with ssh user@host, then run tmux attach -t claude-app.

For a one-command reconnect experience, use ssh -t user@host 'tmux new -As claude-app'. The lowercase s option creates the session if it does not exist and attaches to it if it does. Name sessions by project and purpose, such as claude-api-tests or claude-migration, so multiple tasks remain easy to identify.

Use windows, logs, and worktrees strategically

Security and reliability details

Environment variables are inherited by processes inside tmux, so treat a shared server account as sensitive. Use a private account, restrictive file permissions, and a secret manager where possible. Avoid logging API keys in shell history, process-monitor output, or copied terminal transcripts. Set a spending limit or usage alert in your 59API account, particularly for autonomous loops and large-context repositories.

Finally, commit or stash work before ending a task, record the tmux session name in your ticket, and check tmux ls if you are unsure whether a process is still running. If you want an inexpensive Claude Code remote setup, sign up for 59API, configure its compatible endpoint, and start with a small repository before scaling the workflow.

准备好开始了吗?

几分钟接入 Claude 与 GPT,全网超低价,原生不降智。立即注册即可领取 API 密钥。

免费注册