Blog

Keep Claude Code running after you close the terminal

Run Claude Code inside tmux. A program started in a terminal window ends with the window; one started in tmux belongs to tmux, which keeps running until you end the session.

Close a terminal window and whatever ran in it ends, a Claude Code session in the middle of its work included. The fix is tmux: a program that holds terminal sessions apart from any window. Start Claude Code inside tmux and the window becomes a view onto the session, not its owner.

With plain tmux

brew install tmux
tmux new -s claude
claude

You are now in a tmux session named claude, with Claude Code running in it. Press Ctrl-b, then d, to detach. The window is yours again, and Claude Code keeps working. Close the window, quit the terminal app, it makes no difference.

To see what is running and to go back in:

tmux ls
tmux attach -t claude

To end it for good:

tmux kill-session -t claude

Two things tmux does not fix

A sleeping Mac. tmux keeps the session, but a Mac that sleeps runs nothing. caffeinate -i keeps it from sleeping when idle for as long as that command runs. A laptop with its lid closed still sleeps.

A waiting agent. A session that is alive is not a session that is working. If Claude Code asks for a permission ten minutes after you left, it waits on that prompt until you come back. Keeping it running is half the problem. The other half is knowing it is waiting and answering.

The same, with Grenade

Grenade starts every agent in a tmux session of its own, so this is how it works from the first command:

grenade new api --cwd ~/code/api --agent claude
grenade open api     # attach this terminal; Ctrl-b d detaches
grenade ls           # every session and its status
grenade kill api     # end it

The session is an ordinary tmux session named gr-api, so tmux attach -t gr-api works too. No window opens unless you ask for one, and nothing you close ends it.

It also covers the second half. The Grenade app on your phone lists the same sessions with a color for each (amber when one needs an answer), shows its terminal, and lets you answer a permission with a tap.

Read on: Claude Code in tmux, and for the version without Grenade, SSH, tmux and Tailscale.

Try it on your own agents.

Two commands on the Mac, one QR code on the phone. No account.