How to run Claude Code on a remote server and keep it running

To keep Claude Code running on a remote server after you disconnect, start it inside something on the server that outlives your SSH connection. By hand that's tmux. LlamaTree does the same job with a session host on the server, and shows the server's sessions beside your local ones. Both work for Codex and other command-line agents too.

Why run an agent on a server?

The agent has to be installed and signed in on the server, since that's where it runs.

By hand: SSH and tmux

Connect, start a tmux session, and start the agent inside it:

ssh user@server
tmux new -s api
cd ~/src/shop && claude

Press Ctrl+B then D to detach. The agent carries on, and you can close the connection. To come back:

ssh user@server
tmux attach -t api

That's all it takes for one agent. What it leaves you to do yourself:

With LlamaTree: server sessions beside your local ones

LlamaTree is a free, open-source desktop app for Windows and Linux that runs your agents side by side in one window. A session can run on this computer or on a server, and the two kinds sit together in your projects.

Session tiles: one runs on a server named build-box, another's server can't be reached, and the rest run locally

What you need:

Then:

  1. Press Ctrl+Shift+N for New Session.
  2. Set Computer to the server: user@server, ssh://user@server:port, or a Host from your SSH config.
  3. Pick a folder on the server (Browse… shows the server's folders) and start the session.

The session appears among your local ones, with the server's name on its tile. From there it works like a local session:

It keeps running

The sessions belong to a LlamaTree session host on the server, not to your window. Close LlamaTree, put your laptop to sleep or lose Wi-Fi, and they carry on. Meanwhile the tile says it can't reach the server and keeps trying, and when the connection comes back the session is as the agent left it.

One thing to check: if the server ends your processes when you log out (systemd's KillUserProcesses), run loginctl enable-linger there once.

Nothing has to be opened in a firewall beyond SSH itself: LlamaTree uses your own ssh, with your SSH config, keys and jump hosts.

Updated 21 November 2026, for LlamaTree v1.4.0. Something wrong or missing? Tell us on GitHub.