# Run Claude Code in tmux So an SSH Drop Does Not Orphan It

> When SSH dropped, Claude Code kept running in the dev container with no way back to it. Start it inside tmux and you reattach to the live screen.

Published: 2026-11-20. Author: Milan Jovanović.

Canonical: https://milanjovanovic.tech/blog/claude-code-tmux

Start Claude Code inside **tmux**, a program that keeps your terminal running on the server after SSH drops.
Without it, a dropped connection ended the host side of `devcontainer exec` and left `claude` running in the container with no terminal to reattach to.
With tmux, you log back in and run `tmux attach` to get the same screen.

I tested this on November 20, 2026: a 2 vCPU / 8 GB Ubuntu 24.04 VPS with Docker 29.10, tmux 3.4, and Claude Code 2.1.329.
Claude Code ran in a **dev container** (a Docker container defined by a `.devcontainer` folder in the repo), started with the [**Dev Containers CLI**](https://milanjovanovic.tech/blog/claude-code-devcontainer-cli).

## What Happens When SSH Drops Without tmux?

I started Claude Code over SSH with `devcontainer exec`, killed the SSH client to simulate a dropped connection, and listed the processes on the host and in the container:

![Terminal output of three process lists. While connected, the host runs devcontainer exec and docker exec, and the container runs claude. Ten seconds after the SSH client was killed, the host list is empty but claude is still running in the container. Two minutes later, claude is still there.](https://milanjovanovic.tech/blogs/articles/claude-code-tmux/ssh_drop_orphan.png)

The host side was gone within 10 seconds.
`claude` was still running in the container two minutes later, with nothing connected to its terminal.
It's an **orphan**: a process that keeps running with nothing attached to it.

You can't get back to it, because `docker exec` always starts a new process and can't attach to a running one.
Killing a tmux session that holds Claude Code left an orphan too.

## How Do You Keep Claude Code Running With tmux?

tmux runs a small server process on the host.
Your terminal lives inside that server, so it stays when SSH drops.

![Two panels. Without tmux, an SSH session on the host starts devcontainer exec, which starts docker exec, which starts claude inside the container. When SSH drops, the host processes die and claude is left orphaned in the container with no terminal. With tmux, the tmux server on the host holds the terminal for devcontainer exec, so SSH can drop and you reattach to the same claude session.](https://milanjovanovic.tech/blogs/articles/claude-code-tmux/ssh_drop_with_and_without_tmux.png)

Start a named session on the server, then start Claude Code inside it:

```bash
tmux new -s claude
cd ~/projects/orders-api
devcontainer exec --workspace-folder . claude
```

Press `Ctrl+b`, then `d`, to **detach**.
The session keeps running, and you can close SSH.

You can also pass the command to tmux, so one line starts both:

![Terminal output on the host. One tmux new command starts devcontainer exec with claude inside the session. After Ctrl+b and d it prints detached from session claude, and tmux ls still lists the claude session.](https://milanjovanovic.tech/blogs/articles/claude-code-tmux/one_command.png)

If that command fails, the tmux session closes and takes the error with it.
Run the part in quotes on its own to see what went wrong.

When you log back in, attach to it:

```bash
tmux attach -t claude
```

I ended the SSH session and logged back in 50 seconds later.
The session was still listed, and its screen showed Claude Code where I left it:

![Terminal output after logging back in. tmux ls lists the claude-test session created at 10:41:36, and tmux capture-pane prints the live Claude Code screen, still on its theme picker with a code diff preview.](https://milanjovanovic.tech/blogs/articles/claude-code-tmux/tmux_reattach.png)

`capture-pane -p` prints a session's screen without attaching to it.

## Which tmux Commands Do You Need?

These six cover everything in this guide:

| Command | What it does |
| --- | --- |
| tmux new -s claude | Starts a session named claude and attaches to it |
| Ctrl+b, then d | Detaches. The session keeps running |
| tmux attach -t claude | Reattaches with the screen as you left it |
| tmux ls | Lists sessions |
| tmux capture-pane -p -t claude | Prints the screen without attaching |
| tmux kill-session -t claude | Ends the session. Quit Claude Code first |

tmux 3.4 came with the test server's Ubuntu 24.04 image.
If yours doesn't have it, run `sudo apt install tmux`.

## How Do You Find and Stop an Orphaned Claude Process?

Find the container the Dev Containers CLI started for your repo.
Run this from the repo folder on the host, because the label holds that folder's full path:

```bash
docker ps -q --filter label=devcontainer.local_folder=$PWD
```

Then list the processes in that container with their start times:

```bash
docker exec <container> ps -eo pid,lstart,tty,args
```

Every Claude Code session shows up as `claude`, so check the start time before you kill anything.
In my test, an orphan from the first SSH test sat next to a live tmux session:

![Terminal output of ps inside the dev container, trimmed to two claude processes. PID 10875, started at 10:41:04, is the orphan from the SSH test. PID 10956, started at 10:41:36, is the live session in tmux.](https://milanjovanovic.tech/blogs/articles/claude-code-tmux/find_orphan.png)

Stop only the process you own:

```bash
docker exec <container> kill <pid>
```

`pkill -x claude` also works, but it stops every `claude` in the container, live sessions included.

## Should tmux Run on the Host or in the Container?

Run tmux on the host and start `devcontainer exec` inside it.
That is the setup I tested.
The dev container image doesn't include tmux, so I left that option out.

The [**Remote Control docs**](https://code.claude.com/docs/en/remote-control) give the same advice for a remote machine: start Claude Code inside tmux or screen so the session survives an SSH disconnect.
[**Remote Control**](https://milanjovanovic.tech/blog/claude-code-remote-control-vps) and long runs [**without permission prompts**](https://milanjovanovic.tech/blog/claude-code-dangerously-skip-permissions) both depend on it.

tmux does not survive a reboot.
I didn't test reboots, systemd services, mosh, or a network that stops delivering packets without closing the connection.

## Summary

Start Claude Code inside tmux on the host, detach with `Ctrl+b` and `d`, and close SSH.
`tmux attach -t claude` brings back the same screen.
Without tmux, a dropped connection leaves `claude` orphaned in the container, so find it by start time and kill only that PID.

Thanks for reading.

And stay awesome!

---

## Frequently asked questions

### How do I keep Claude Code running after SSH disconnects?

Start it inside a tmux session on the server. When SSH drops, tmux keeps the terminal and Claude Code running. After you log back in, run tmux attach to get the live screen back.

### What happens to Claude Code when SSH disconnects without tmux?

In testing with a dev container, the host side of devcontainer exec was gone within 10 seconds, but claude kept running inside the container with no terminal. It was still there two minutes later, and there was no way to reattach to it.

### How do I stop an orphaned Claude Code process in a dev container?

List the processes in the container with docker exec and ps, check the start time to find the one you started, and kill that process ID with docker exec. Avoid killing every claude process, because another session on the server can have the same name.

### Should I run tmux on the host or inside the dev container?

Run it on the host and start devcontainer exec inside it. That is the setup I tested, and it kept Claude Code alive and reachable. Running tmux inside the container was not tested.

### Does tmux keep Claude Code running after a reboot?

No. A reboot ends tmux sessions and everything running in them. Reboots were not part of this test, so plan to start the dev container and Claude Code again after one.
