← Best Practices

Claude Code Remote Connection Keeps Disconnecting? Troubleshooting Causes + Complete Solution

The most frustrating thing about running Claude Code remotely isn't failing to connect—it's connecting and then constantly disconnecting.

You set it to run a long task on your dev machine, then use your phone or another computer to check progress—only to have it disconnect when you enter an elevator, switch from WiFi to 4G, close your laptop lid and find the session gone, or finally reconnect only to have messages vanish into thin air. Whether it's the official Remote Control or your own SSH + tmux setup, disconnections are almost a universal pain point for remote Claude Code.

This article first explains clearly why disconnections happen (this part is useful for troubleshooting any solution), then shows how to use PandaNpc to switch devices, switch networks, or even close the viewer without dropping the connection.

1. First, understand: Why does remote Claude Code actually disconnect?

A remote connection consists of two segments: the dev machine running Claude Code ←→ the viewing device (phone/another computer) in your hand. Problems on either side can cause a "disconnect." Common causes:

1. The machine running the session sleeps / locks screen / closes lid

This is the most insidious type. Many people think "my dev machine is always on," but system sleep, lid-close sleep, or timed lock screen can suspend or kill the Claude Code process. On the viewing end, it just looks like "suddenly stopped / disconnected."

2. Network switching kills the long-lived connection

Remote real-time sync relies on a long-lived connection (WebSocket / SSH). When you go from WiFi to elevator and switch to 4G, your home broadband re-dials at midnight, or your IP changes—the long-lived connection is immediately broken.

3. Official Remote Control's hard constraint: the local machine must be running in the foreground

Anthropic's official Remote Control "projects your local running session to a phone/browser." Its prerequisite is that the local Claude Code is always running in the foreground and the local machine is always online. Once the local machine sleeps, the terminal is closed, or the network drops, the remote end immediately follows—it's essentially "screen mirroring," not a "persistent service."

4. Half-open connections: the hardest to detect

When the network silently drops, both ends of a TCP connection may think they are still connected, but data can no longer pass through. Without a keepalive mechanism, you get stuck in a weird state of "showing online but messages get no response"—even worse than a clean disconnect.

5. No automatic reconnection / messages lost after reconnection

Even if you can manually reconnect, many solutions fail to resume the original session after reconnection, or all messages sent during the disconnection period are lost—essentially a wasted connection.

In summary: the root cause of remote Claude Code disconnections is that the "running session process" and "your viewing connection" are too tightly coupled—when the process goes down or the connection breaks, everything is lost.

2. The key to the solution: completely decouple the "session process" from the "viewing connection"

To achieve no disconnections, the approach must be:

  • Make the end running Claude Code a persistent daemon service, independent of your viewing device—your phone can disconnect, close, or switch devices without affecting it; it continues running on the dev machine.
  • Make the viewing connection capable of automatic reconnection, resuming the original session after reconnecting, and backfilling messages from the disconnection period.
  • Add heartbeat detection to proactively discover and kill "half-open connections," then reconnect immediately.

PandaNpc + pandapaw is designed with this approach. Below, see how it addresses each disconnection cause.

✅ Corresponding to "machine sleep / local machine must be on" → persistent daemon

The pandapaw installed on the dev machine is a persistent daemon registered to start on boot, not a terminal window you must manually keep open. If it crashes, it gets automatically pulled back up; it's on standby in the background after boot.

So even if you close the viewer, put away your phone, or switch to another computer, as long as the dev machine itself is on, the Claude Code session stays alive under pandapaw's guard—this is fundamentally different from the official Remote Control's "local machine must be running in the foreground."

✅ Corresponding to "network switch / long-lived connection dropped" → auto-reconnect with backoff

If the viewer's connection breaks (network switch, IP change, poor signal), it automatically reconnects with a backoff strategy (1s→2s→5s…) to avoid hammering. When you come out of the elevator or up from the subway, it reconnects on its own—no manual action needed.

✅ Corresponding to "half-open connection" → heartbeat detection

The connection runs keepalive pings. If no response is received from the other end within the agreed time, it's judged a "half-open connection" and actively disconnected to reconnect—rather than stupidly waiting in a "showing online, no response to messages" state.

✅ Corresponding to "session lost on reconnect / messages lost" → resume original session + history replay

After reconnection, it automatically subscribes back to the original session and replays the message history from the disconnection period—no lost context. Further, even if the session process on the dev machine was recycled due to long idle time or pandapaw restarted, sending a single message automatically restores the session from disk (cold recovery self-heal) and continues the conversation—seamless to you.

3. Getting started: two steps to set up a disconnection-proof remote solution

Step 1: Install pandapaw on the dev machine (one command, automatically persistent)

The dev machine is the computer where you normally run Claude Code.

macOS / Linux:

bash
curl -fsSL https://cos.pandanpc.com/pandapaw/install.sh | sh

Windows (PowerShell):

powershell
iwr -useb https://cos.pandanpc.com/pandapaw/install.ps1 | iex

After installation, it automatically: copies the binary → starts the daemon → registers auto-start on boot. This step is the key to "no disconnections"—from now on, there's a persistent service on the dev machine that guards the session, independent of any foreground window.

Tip: Set your dev machine's power plan to "never sleep / do not sleep when lid is closed" to completely eliminate the first category of disconnection causes.

Step 2: Connect from the viewing end (phone / another computer / browser)

  • Phone: Install the PandaNpc iOS App, scan the QR code generated by pandapaw on the dev machine to add the connection.
  • Another computer: Install PandaNpc Desktop (Windows / macOS / Linux), or open https://pandanpc.com/agent directly in a browser.

Once connected, sending messages, viewing sessions, approving tool calls, and viewing code changes are all remotely controlling Claude Code on the dev machine. Network drops, device switches, or screen off—it handles automatic reconnection and session resumption for you.

4. Bonus: Remote running doesn't cost you extra

Many remote solutions use claude -p (headless mode). However, starting June 15, 2026, Anthropic changed its billing—headless mode no longer consumes subscription quota but instead takes a small monthly SDK credit, and charges API rates once exhausted, easily leading to overspending for heavy use.

PandaNpc's interactive mode (cc-tty) runs the claude REPL, which still uses the subscription quota you're already paying for—no extra API charges for remote use. No disconnections and saves money. (See another article on the site for details about the June 15 billing change.)

5. Security note

  • Remote connections are fully secured with HMAC-SHA256 signed authentication, using your own key pair—not open ports.
  • Claude Code's tool calls (Bash / Edit / file writing, etc.) all execute on your own dev machine and require your confirmation before proceeding.

6. Disconnection troubleshooting checklist (works for any solution)

If you're troubled by remote Claude Code disconnections, check in this order:

  1. Is the machine running the session sleeping or locked? → Disable auto-sleep, do not sleep on lid close.
  2. Did you switch networks (WiFi↔4G, IP change)? → Use a solution with auto-reconnect, don't rely on bare SSH.
  3. Are you using a "screen-mirroring" solution that requires the local machine to be in the foreground? → Switch to a solution with a persistent daemon on the dev machine.
  4. Stuck in "showing online but messages get no response"? → This is a half-open connection; you need a solution with heartbeat detection to recover automatically.
  5. Session/messages lost after reconnection? → Choose a solution that can resume the original session + replay history.

7. Try it now

  • Phone: Search for PandaNpc on the App Store, or visit the official site https://pandanpc.com for download.
  • Computer: Download the desktop client from the official site, or use the web client directly at https://pandanpc.com/agent.
  • Install pandapaw, add the connection, and experience "remote Claude Code that doesn't disconnect when switching devices or networks" in 5 minutes.

If you're tired of remote Claude Code disconnecting every few days, this solution is worth a try. Feel free to leave comments for discussion.

First published on pandanpc.com