SSH Remote Session Drops Fix (2026)
The Error
client_loop: send disconnect: Broken pipe
Connection to remote-server closed.
Claude Code session lost — SSH connection dropped after 60s inactivity
Unsaved work in remote Claude Code session may be lost
This appears when the SSH connection drops during a Claude Code session on a remote machine, typically due to network timeouts or NAT table expiry.
The Fix
# Add to ~/.ssh/config:
Host *
ServerAliveInterval 30
ServerAliveCountMax 5
TCPKeepAlive yes
- Configure SSH keepalive to send heartbeat packets every 30 seconds.
- Reconnect to the remote server and check if Claude Code is still running.
- Use tmux or screen for all remote Claude Code sessions going forward.
Why This Happens
SSH connections are stateful TCP connections. When Claude Code waits for a long API response or you pause typing, the connection goes idle. Firewalls, NAT gateways, and load balancers drop idle TCP connections after their timeout (often 60 seconds). Without keepalive packets, the SSH server does not know the client disconnected, and the client does not know the server is unreachable until the next write attempt.
If That Doesn’t Work
Always run Claude Code inside tmux on the remote server:
ssh remote-server
tmux new -s claude-session
claude
# If disconnected, reconnect with:
ssh remote-server
tmux attach -t claude-session
Use mosh instead of SSH for unreliable connections:
brew install mosh # on client
# On remote: apt install mosh
mosh remote-server
claude
Configure the server-side keepalive as well:
# On remote server, add to /etc/ssh/sshd_config:
# ClientAliveInterval 30
# ClientAliveCountMax 5
sudo systemctl restart sshd
Prevention
# CLAUDE.md rule
Always run Claude Code inside tmux on remote servers. Configure SSH keepalive in ~/.ssh/config. Use 'tmux new -s claude' before starting Claude Code remotely. Never run long sessions over bare SSH.
See Also
Related Error Messages
This fix also applies if you see variations of this error:
- Connection or process errors with similar root causes in the same subsystem
- Timeout variants where the operation starts but does not complete
- Permission variants where access is denied to the same resource
- Configuration variants where the same setting is missing or malformed
If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.
Frequently Asked Questions
Does this error affect all operating systems?
This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.
Will this error come back after updating Claude Code?
Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.
Can this error cause data loss?
No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.
How do I report this error to Anthropic if the fix does not work?
Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.