Phuriwaj

Linux screen — Persistent Terminal Sessions with Claude Code

screen is a terminal multiplexer that keeps sessions alive after disconnecting. Useful for running Claude Code over SSH or in the background without losing state.

Why / When to Use

  • Running Claude Code on a remote server over SSH and need to disconnect
  • Keeping an autonomous Claude Code run alive overnight
  • Monitoring logs in one window while Claude Code runs in another
  • When Zellij is not installed but screen is available (it ships with most Linux distros)

Core Concept / Commands

Basic Workflow

# Start a named session
screen -S claude
 
# Inside the session: launch Claude Code normally
claude
 
# Detach (keep session running in background)
# Press: Ctrl+A, then D
 
# Reattach later
screen -r claude

Session Management

screen -S claude        # Create named session
screen -ls              # List all sessions
screen -r claude        # Reattach to named session
screen -r               # Reattach if only one session exists
screen -d -r claude     # Force detach from elsewhere then reattach
screen -X -S claude quit  # Kill a session from outside

Inside a Screen Session

ShortcutAction
Ctrl+A, DDetach (leaves Claude Code running)
Ctrl+A, CCreate a new window
Ctrl+A, N / PNext / previous window
Ctrl+A, "List all windows
Ctrl+A, ASwitch to last window
Ctrl+A, [Enter scroll mode (arrow keys to navigate, Q to exit)

Multi-Window Setup

Run Claude Code in one window, watch logs in another:

screen -S claude   # start session
 
# Window 0: Claude Code
claude
 
# Ctrl+A, C → new window
# Window 1: watch LiteLLM proxy logs
tail -f /path/to/litellm.log
 
# Ctrl+A, C → new window
# Window 2: spare shell
bash

Switch between windows: Ctrl+A, " or Ctrl+A, 0/1/2.

Key Options / Variants

ToolDetachReattachNotes
screenCtrl+A, Dscreen -r <name>Universal, ships with most Linux distros
ZellijCtrl+O → Dzellij attach <name>Modern UX — see claude-code-zellij-sessions
tmuxCtrl+B, Dtmux attach -t <name>More portable, better split-pane support

Gotchas

  • Scrolling: Claude Code produces heavy output. Use Ctrl+A, [ to enter scroll mode. Increase the buffer with defscrollback 10000 in ~/.screenrc.
  • Sessions accumulate — remember to kill old ones: screen -X -S <name> quit.
  • On macOS, screen is available but Zellij or tmux tend to have better integration with modern terminal emulators.
# ~/.screenrc
defscrollback 10000       # large scroll buffer for Claude Code output
startup_message off       # skip the intro message
hardstatus alwayslastline # show window list at bottom
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

Source

Conversation: “Linux screen command with Claude code” — 2026-05-24