How to run Claude Code on a server and keep it working

To run Claude Code on a remote server, create a normal user on a VPS, install Claude Code with the official script, sign in once, and start it inside tmux. The agent keeps working when you close the laptop, and you attach again from any device with tmux attach. Give it its own Git key and keep production credentials out of its reach.

Why run Claude Code on a remote server?

On a laptop, Claude Code stops when the lid closes. On a server it keeps going: a long refactor finishes while you sleep, and you can check it from your phone on the way to work.

  • It keeps working after you disconnect, inside tmux.
  • Your laptop stays yours: builds, tests and installs happen on a machine you can wipe.
  • You reach it from anywhere: Mac, iPad or iPhone, over SSH.
  • Several agents in parallel, one tmux session per project.

The whole setup takes about twenty minutes. Here it is, step by step.

Step 1: prepare the server

Any Linux VPS works. The model runs at Anthropic, so the server only runs your tools; 2 CPUs and 4 GB of memory handle most web projects.

  1. Create a normal user for the agent, not root:
    sudo adduser dev
    sudo usermod -aG sudo dev     # only if it really needs sudo
    Our guide on creating an SSH user with sudo has the details.
  2. Sign in with a key, and turn off password login once it works. See disable SSH password login.
  3. Install the basics:
    sudo apt update
    sudo apt install -y git tmux build-essential

Our Linux server security checklist covers the rest of a fresh VPS: firewall, updates and fail2ban.

Step 2: install and sign in to Claude Code on the server

Connect as the new user and install Claude Code with the official script:

curl -fsSL https://claude.ai/install.sh | bash
claude --version

Start claude in a project folder. On a server with no browser, the sign-in shows a link: open it on your own device, sign in, and paste the code back. If you use an API key instead, set it in the environment of that user:

install -m 600 /dev/null ~/.anthropic.env
echo 'export ANTHROPIC_API_KEY=sk-ant-...' > ~/.anthropic.env
echo '. ~/.anthropic.env' >> ~/.bashrc

The key file is readable only by that user, and every new shell loads it.

Step 3: give it Git access the safe way

The agent needs to pull and push. There are three ways, from safest to riskiest:

  1. A deploy key per repository. Make a key on the server and add the public part to the repository's deploy keys, with write access if it must push. It reaches that repository and nothing else.
    ssh-keygen -t ed25519 -C "claude@dev-server" -f ~/.ssh/id_deploy
    cat ~/.ssh/id_deploy.pub
  2. A key for the server on a separate account with access to the few repositories it needs.
  3. Agent forwarding (ssh -A). Convenient, but while you are connected, anything on the server can use your keys. Read the risks of agent forwarding before you rely on it.

If you do forward your agent, Wardterm can ask you before each signature, so a push you did not expect never goes through silently. See agent forwarding with confirmation.

Step 4: run Claude Code on a remote server inside tmux

This is the step that makes the server worth it:

tmux new -s api
cd ~/projects/api
claude

Give it the task, then detach with Ctrl+b, then d. Close the laptop; Claude Code keeps working. Later, from any device:

ssh dev@your-server
tmux ls                 # list running sessions
tmux attach -t api      # back where you left it

One session per project keeps things tidy. If tmux is new to you, tmux for beginners covers the keys that matter.

In Wardterm you can skip the typing: save tmux new -A -s api as the server's startup command, and every connection lands in the same session. If the connection drops, Wardterm reconnects when the network is back. Keep sessions alive.

Step 5: choose how much freedom it gets

Claude Code asks before it edits files or runs commands. On a server you can loosen that, carefully:

  • Allow specific commands in .claude/settings.json of the project, such as your test and lint commands, so it does not ask each time.
  • Accept edits automatically with the accept-edits mode, and keep the question for shell commands.
  • Skip every question only in a throwaway container or VM with nothing valuable in reach. The flag has "dangerously" in its name for a reason.

Whatever you choose, keep production keys, database passwords and cloud credentials off this machine. If the agent can reach production, a mistake reaches it too. Our guide to avoiding mistakes on production servers has more habits.

How do you know when the agent needs you?

An agent on a server has one weakness: it waits silently. You come back an hour later to find it stopped at its first question.

The fix is a notification. Claude Code can send one through the terminal when it waits for you: turn on terminal notifications in /config. The SSH client then has to pass it on.

In Wardterm, keep the agent in tmux and look in on it from whichever device you have at hand: the same server, user and key are there. See our guide to Claude Code on iPhone.

Can you run Codex CLI on a remote server the same way?

Yes. Codex CLI installs with npm and runs in a terminal like Claude Code:

npm install -g @openai/codex
tmux new -s codex
codex

The same rules apply: a normal user, a limited Git key, tmux to keep it running. Gemini CLI and other terminal agents follow the same pattern. Our list of the best AI coding agents for the terminal compares them.

Questions

Can Claude Code run on a server without a screen?

Yes. Claude Code is a terminal program, so it runs over SSH like any other. To sign in on a headless server, it shows a link you open in a browser on your own device, or you set an API key in the environment.

How do I keep Claude Code running after I disconnect?

Start it inside tmux: tmux new -s claude, then claude. Detach with Ctrl+b then d. The session and the agent keep running on the server until you attach again.

What size of VPS do I need for Claude Code?

The model runs at Anthropic, so the server only runs your tools: builds, tests and Git. A small VPS with 2 CPUs and 4 GB of memory is enough for most web projects; size up for heavy builds.

Is it safe to let Claude Code run on a server?

Safer than on your laptop, if you set it up well. Use a dedicated user, a Git key that can only reach the repositories it needs, and no production credentials on that machine.

Should I use SSH agent forwarding for Git with Claude Code?

Better not for long sessions. With ssh -A, anything on the server can use your keys while you are connected. A deploy key or a separate key for the server is easier to limit and revoke.

Does the same setup work for Codex and Gemini CLI?

Yes. Any agent that runs in a terminal works the same way inside tmux: install it, start it in a tmux session and detach.

How do I know when Claude Code on the server needs me?

Turn on Claude Code's terminal notifications in /config. With session alerts in Wardterm, they arrive as a notification on your phone or Mac, and a tap opens the session. Without them, you check the tmux session yourself.

Sources

Each page was read on the date shown. Prices and features change, so check the maker's page before you decide.

  1. Claude Code docs, setup, read on
  2. Claude Code docs, permission modes, read on
  3. Codex CLI, source repository, read on
  4. tmux manual, read on
  5. GitHub docs, managing deploy keys, read on
  6. Wardterm docs, session alerts, read on

All posts