How to Keep Claude Code Running After You Close Your Terminal
Claude Code exits when you close your terminal because it receives SIGHUP. tmux is the fix — here's how to set it up, detach, and reconnect, with screen and nohup as alternatives.
Claude Code exits when you close your terminal because it runs as a foreground process that receives SIGHUP when the terminal session ends. tmux is the fix — it keeps sessions running independently of any terminal window. If you also want to monitor the running session from your phone without reopening a terminal, Grass handles that part.
TL;DR
- Claude Code dies on terminal close because it receives SIGHUP — it has no built-in daemon mode
- Fix: always start Claude Code inside a tmux session
- Detach with
Ctrl+B D; reattach later withtmux attach -t session-name - Resume Claude Code after reattaching:
claude --continue - Optional: run Grass alongside for phone monitoring without ever reopening a terminal
Why Claude Code stops when you close your terminal
Claude Code runs as a foreground terminal process. When you close a terminal window or an SSH connection times out, the operating system sends SIGHUP (hangup signal) to the entire process group. Claude Code has no built-in daemon mode and no signal handler for SIGHUP — it exits immediately.
The session history is preserved in ~/.claude/projects/<cwd>/<session-id>.jsonl, so no conversation context is lost. But the running process is gone, and any task in progress stops at that point.
This affects remote coding sessions especially hard — network interruptions silently kill long-running tasks.
The fix: tmux
tmux is a terminal multiplexer. Sessions live on the server and persist independently of any terminal connection. You attach to see them and detach to leave them running. Claude Code inside tmux is unaffected by terminal closes, SSH disconnects, or network interruptions.
Install tmux
macOS:
brew install tmux
Ubuntu/Debian:
sudo apt install tmux
Verify: tmux -V returns something like tmux 3.2a.
The basic workflow
# 1. Start a named session before starting Claude Code
tmux new -s claude
# 2. Navigate to project and start
cd ~/project
claude
# 3. Detach without killing (hold Ctrl, press B, release, press D)
# Ctrl+B D
# 4. Close your terminal — Claude Code keeps running
# 5. Reattach later
tmux attach -t claude
# or: tmux a -t claude
# 6. List all running sessions
tmux ls
# 7. Kill a session when done
tmux kill-session -t claude
Naming sessions by project (tmux new -s frontend, tmux new -s api) keeps things organized when you're running multiple AI coding agents in parallel.
Reconnecting to a Claude Code session
After reattaching to tmux, Claude Code may have exited naturally (task complete) or be waiting for input. Resume with:
claude --continue
This restores the full conversation from the transcript at ~/.claude/projects/<cwd>/. To resume a specific past session:
claude --resume <session-id>
Session IDs appear in the .jsonl filenames in the transcripts directory. See the Claude Code CLI reference for the complete list of flags.
Alternative: GNU screen
screen is an older terminal multiplexer with a smaller feature set than tmux. It works for the same purpose:
# Start a named screen session
screen -S claude
# Run Claude Code inside
claude
# Detach: Ctrl+A then D
# Reattach
screen -r claude
# List sessions
screen -ls
For most developers starting fresh, tmux is the better choice — it has better documentation, more active development, and handles multiple windows/panes more cleanly. screen still works fine if it's already part of your workflow.
Fallback: nohup (limited use)
nohup claude > claude.log 2>&1 &
This runs Claude Code in the background, immune to SIGHUP, with output going to claude.log. The process survives terminal close.
The problem: nohup provides no interactive terminal. Claude Code's approval gates write a prompt to the terminal and wait for stdin response. With nohup, there's no stdin — gates stall silently. The session just hangs at the first permission request.
nohup is only appropriate for fully automated runs with --dangerously-skip-permissions. For anything interactive, use tmux.
Useful tmux configuration
Add to ~/.tmux.conf:
set -g mouse on # scroll through output with mouse
set -g history-limit 50000 # keep more scrollback for long Claude Code sessions
set -g status-right "#{session_name} | %H:%M" # session name + time in status bar
Reload without restarting: tmux source-file ~/.tmux.conf
Does Claude Code have a daemon mode?
No. As of early 2026, Claude Code has no built-in background/daemon mode. tmux is the standard approach for persistence. Some developers use systemd service units for fully automated unattended runs, but this only works without approval gates.
Going further: monitoring without reopening a terminal at all
tmux means you never lose the session. But you still need to SSH back in — open a terminal, tmux attach — to see what the agent is doing.
If you want live output, agent approval gates surfaced as mobile notifications, and the ability to send new prompts — all without opening a terminal:
npm install -g @grass-ai/ide
In a second tmux window alongside your Claude Code session:
grass start
Scan the QR code from the Grass iOS or Android app. From that point, the Grass app is the interface — live output, approval modals, file browser, prompt input. The terminal can stay closed.
For remote access outside your local network: grass start --network tailscale (requires Tailscale on both machine and phone).
Frequently asked questions
Why does Claude Code stop when I close my terminal?
Claude Code runs as a foreground process. Closing a terminal sends SIGHUP to the process group, and Claude Code has no built-in handler for it — it exits immediately. Use tmux to insulate Claude Code from terminal lifecycle events.
How do I use tmux with Claude Code?
Start a named session with tmux new -s claude, run claude inside it, and detach with Ctrl+B D. Claude Code keeps running. Reattach with tmux attach -t claude. Resume Claude Code after reattaching with claude --continue.
How do I run Claude Code in the background?
tmux is the right answer for interactive sessions. For fully automated runs without approval gates: nohup claude --dangerously-skip-permissions > output.log 2>&1 & — but note that any approval gate will stall silently without a terminal to respond to it.
What is the difference between tmux and screen for Claude Code?
Both keep sessions alive after terminal close. tmux has better multi-window and pane support, more active development, and more documentation. screen is older but still works. If you don't already use screen, start with tmux.
How do I reconnect to a Claude Code session after my terminal closes?
If you were using tmux: tmux attach -t session-name. If Claude Code exited while you were away: claude --continue to resume from the last transcript.
Does Claude Code have a daemon mode?
No. Claude Code has no built-in daemon or background mode. tmux is the standard persistence layer. For fully automated runs, --dangerously-skip-permissions with nohup works — but only in isolated environments where there are no sensitive credentials or files at risk.
How do I keep Claude Code running overnight?
tmux is the mechanism. Start a session with tmux new -s overnight, run claude inside, detach with Ctrl+B D, and close the terminal. For overnight runs on a remote server (so your local machine can also sleep), run Claude Code on a VPS or Daytona workspace instead of locally.