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
screenis 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 claudeSession 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 outsideInside a Screen Session
| Shortcut | Action |
|---|---|
Ctrl+A, D | Detach (leaves Claude Code running) |
Ctrl+A, C | Create a new window |
Ctrl+A, N / P | Next / previous window |
Ctrl+A, " | List all windows |
Ctrl+A, A | Switch 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
bashSwitch between windows: Ctrl+A, " or Ctrl+A, 0/1/2.
Key Options / Variants
| Tool | Detach | Reattach | Notes |
|---|---|---|---|
| screen | Ctrl+A, D | screen -r <name> | Universal, ships with most Linux distros |
| Zellij | Ctrl+O → D | zellij attach <name> | Modern UX — see claude-code-zellij-sessions |
| tmux | Ctrl+B, D | tmux 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 withdefscrollback 10000in~/.screenrc. - Sessions accumulate — remember to kill old ones:
screen -X -S <name> quit. - On macOS,
screenis available but Zellij or tmux tend to have better integration with modern terminal emulators.
Recommended ~/.screenrc
# ~/.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