Newhivemux swarm: Claude Code’s builds and tests run on your other Macs →

How to keep Claude Code running after closing the terminal

Short answer

Closing a terminal window sends a hang-up signal to the shell, and the claude process in it dies with the task half done. Run Claude Code inside tmux instead. The tmux server keeps the process alive after the window closes; reattach with tmux attach and the session is where you left it. With hivemux, every Ghostty window is already a tmux session, so closing a window only detaches.

By · · 3 min read

Claude Code runs as an ordinary process in your terminal. When the window that holds it closes, macOS sends the shell a hang-up signal, the shell exits, and claude goes with it. If it was in the middle of a task, the task stops; the conversation is saved on disk, but nothing continues. The same happens when you quit the terminal app.

The fix is to give Claude a terminal that does not belong to the window: tmux.

Step 1. Start Claude Code inside tmux

Terminal window
brew install tmux # once
tmux new -s api # a tmux session named after the project
cd ~/code/api
claude

Everything you see is now drawn by tmux inside the window, and the claude process belongs to the tmux server, not to the window.

Step 2. Close the window, or detach

Press prefix d (Ctrl+B then d in a plain tmux setup) to detach, or simply close the terminal window. Either way the tmux server keeps running in the background with Claude inside it. A task that was working keeps working; a session that was waiting for your answer keeps waiting.

Step 3. Come back

Terminal window
tmux attach -t api # that project
tmux attach # the most recent session
tmux ls # what is running

The screen is exactly where you left it. If Claude asked a question while you were away, the question is there; press the number and it continues.

What the window closing does and does not stop

You do this Claude Code without tmux Claude Code inside tmux
Close the terminal window killed, task stops keeps running
Quit the terminal app killed keeps running
Mac goes to sleep pauses, continues on wake pauses, continues on wake
Reboot gone gone; restored by tmux-resurrect, resumed by hivemux
/exit or Ctrl+D ends ends

A long task that must not pause: keep the Mac awake with caffeinate -i -w <pid> or the Energy settings, or run Claude on a desktop that stays on and look in from the laptop (see How to continue Claude Code from your phone or another computer).

With hivemux, this is the default

hivemux is a tmux sidebar that shows every Claude Code session — running, waiting for you, or done — and lets you jump to the one that needs you. Its setup makes Ghostty open tmux in every window, so you never start tmux by hand:

  • Every new window attaches to a tmux session; closing it detaches.
  • hm ~/code/api opens one session per project with a Claude window and a shell window.
  • The sidebar shows which sessions are running, which wait for you and which are done, with how long. Option+0 jumps to the one that has waited longest.
  • After a reboot, each pane’s Claude comes back in the same conversation.

hivemux sidebar: five Claude Code sessions kept alive by tmux, one waiting for an approval

Terminal window
curl -fsSL https://hivemux.dev/install.sh | bash

Keys and the full tmux setup are in How to use Claude Code with tmux; what comes back after a reboot is in How to resume Claude Code sessions after a reboot.

FAQ

Can I run Claude Code with nohup or & in the background instead?

Not for an interactive session. Claude Code is a full-screen terminal program that needs a terminal to draw in and read keys from; nohup and & are for commands that run without one. tmux (or screen) gives it a terminal that survives the window.

Does Claude Code keep working while the Mac sleeps?

No. Sleep pauses every process, including Claude's API call in flight. It continues when the Mac wakes; a request that timed out is retried. For a long task, keep the Mac awake with caffeinate -i or in System Settings, or run it on a desktop and attach from the laptop.

Does tmux survive a reboot?

No, a reboot ends the tmux server and everything in it. tmux-resurrect restores the window layout on the next start, and hivemux runs claude --resume <id> in each pane so the conversations come back too. See the guide on resuming sessions after a reboot.

I closed the window on purpose; how do I end the session for real?

Type /exit (or press Ctrl+D) in the session. That ends the Claude process and, with hivemux, marks the session as finished so it is not resumed after a reboot.