Skip to content
86% off$349 $48.86code BF2026

Guides

Keep Claude Code Running After You Close the Terminal

Keep Claude Code running in the background on a Mac or your own server: tmux, --continue and --resume, and agents that outlive the app and resume after reboots.

GuideUpdated 9 min read

On this page

To keep Claude Code running in the background after you close the Terminal window, start it inside tmux. Run tmux new -s claude, start claude, then detach with Control-b followed by d. Reattach later with tmux attach -t claude. If the agent has already stopped, go back to the same project folder and run claude --continue to pick up the last conversation.

The built-in and free options come first. After them, this guide covers how Sledbot keeps agents running after you quit the app, how it resumes them after a crash or reboot, and how to run Claude Code on a server you own.

Why Claude Code stops when the terminal closes

Claude Code is an interactive program that runs inside your shell. When you close the window, the shell ends, and so does every program it started, including the agent.

The conversation itself survives. Claude Code saves its sessions on disk, so the resume flags can load them again. The work does not survive. Between closing the window and resuming, nothing gets done.

That leaves two separate problems:

  • Keeping the process alive while no window is attached. tmux or a background engine handles this.
  • Getting the conversation back after the process has died. Resume flags or automatic resume handle this.

Run Claude Code in the background with tmux (or screen)

tmux runs your programs inside its own background server, and a Terminal window only shows a view of them. Closing the window leaves both the tmux session and Claude Code running.

macOS doesn't include tmux. If you have Homebrew, install it like this:

bash
brew install tmux

That installs tmux. To remove it later, run brew uninstall tmux.

Then:

  1. Open Terminal and cd into your project folder.
  2. Start a named session: tmux new -s claude
  3. Run claude inside it and give it a task.
  4. Press Control-b, then d, to detach. You can now close the window.
  5. To return later, run tmux attach -t claude.

To list your running sessions:

bash
tmux ls

This ends the session and everything running in it, Claude Code included:

bash
tmux kill-session -t claude

If you already use GNU screen, it works the same way. Detach with Control-a then d, and reattach with screen -r.

Some things tmux can't do:

What about nohup?

nohup makes a command ignore the hang-up signal sent when its terminal closes, and it writes the command's output to a file. That's fine for programs that never need a keyboard. Claude Code normally runs as an interactive screen where you type and answer prompts, so tmux is the better fit.

Resume a session with --continue and --resume

If the process has already ended, Claude Code can load a past conversation:

  • claude --continue picks up the most recent conversation. Run it from the project folder you were working in.
  • claude --resume <id> reopens a specific session by its ID.

You get the conversation back, not the running process. Any command the agent was running when it was killed didn't finish, and it did no work while it was stopped. Run git status before you tell it to carry on.

Keep agents alive in Sledbot after you quit

Sledbot is our Mac app for running coding agents in real terminals. It has two parts: the window you look at, and a background engine called Sled Core that owns every terminal.

Quitting the app never stops the core or the agents. When you open Sledbot again, it reattaches to their live screens. Each terminal is also held by a small holder process, so terminals survive a core crash or a core update as well.

To start a Claude Code agent that keeps running after you quit the app:

  1. Open Sledbot and add your project as a space. In the onboarding sheet, click Choose folder…. Later on, you can use Add Project Folder… (⌘O, Command-O) instead.
  2. Press ⌘T (Command-T) to open New task.
  3. Choose Claude Code in the agent chip. It's the default unless you last used a different agent.
  4. Describe the task and press ⌘↩ (Command-Return) to start it.
  5. Quit Sledbot. The agent keeps working.
  6. Open Sledbot again whenever you like. The agent's terminal is still there, mid-task.

In a git repo, Work in a new worktree is on by default. The agent works in its own checkout on its own branch, so your files stay as they are while it runs.

Sledbot Settings General pane with the Sled Core section showing Running and the note that agents keep running
Sled Core keeps running when you quit the app.

Sled Core is set up to start when you log in, and macOS may ask you to approve that the first time. If Sledbot's Settings ▸ General asks you to allow Sledbot in Login Items, open System Settings, search for "Login Items" and allow Sledbot. Without that approval, the core runs as a background process instead. It still survives quitting, but it won't start on its own when you log in.

Other things to know:

  • Sledbot adds its hooks to each Claude Code launch only. It doesn't change your global Claude config.
  • When Claude Code is waiting for permission or asks a question, it shows up in Needs you, on the menu bar bell and as a banner. Banners need the app to be running, but the window can stay closed.
  • Quitting Sledbot doesn't stop anything, and there is no "stop all on quit". To end an agent, click Stop in its header.
  • Sledbot needs macOS 14 Sonoma or later. It's part of MacSuite, and each app runs free for 7 days.

Resume after a crash or reboot

A reboot ends every process on the Mac, including tmux sessions and Sledbot's holder processes. Sledbot keeps agent terminals by default and brings them back:

  • The next time the core starts, it runs each lost agent's own resume command. For Claude Code, that's claude --resume <id>.
  • The agent restarts with the same folder, environment and labels, and Sledbot reports "Resumed Claude Code session".
  • If Sledbot has no session ID, it resumes the latest session in that folder. It only does this when no other kept Claude Code terminal uses the same folder.
  • If it can't tell which session is the right one, or the resume fails, it opens a plain shell in the folder.

When this happens depends on Login Items. If Sledbot is allowed there, the core starts at login. If not, it starts when you open Sledbot.

In the app, Restart on a stopped agent restarts it with its conversation where possible. If an agent looks stuck or keeps crashing, the Health banner offers Restart with resume.

To stop Sledbot from resuming one terminal, give it the label sled.keep=off, for example sled label t7 sled.keep=off.

Run Claude Code on a remote server you own

To keep agents working while your laptop is closed, run them on a machine that stays on.

With SSH and tmux

This works on any server where you can install tmux.

  1. Install Claude Code on the server, then run claude there to log in.
  2. Connect to the server from your Mac with ssh.
  3. Run tmux new -s claude, cd into the project and start claude.
  4. Detach with Control-b then d, then disconnect.
  5. Later, ssh back in and run tmux attach -t claude.

This costs nothing beyond the server and your Claude plan. You get one terminal per session, with no notifications and no review view.

With Sledbot's remote machines

Sledbot can add any machine you reach with SSH and run agents there through its own engine. Those agents keep running while your Mac sleeps or the connection drops.

Check these first:

  • Another Mac works today. Sledbot copies its own sled engine to that Mac and starts it there.
  • Linux needs the sled binary already on the server. The Sledbot app we ship today doesn't include the Linux build of its engine. Unless ~/.sledbot/bin/sled is already on the server, setup fails with "This build has no sled-linux-<arch>…". On a Linux server, use the SSH and tmux method above for now.
  • Supported remote systems are Linux (x86_64 or aarch64) and macOS. The remote home folder needs about 128 MB free.

To add a machine:

  1. In the sidebar, click + next to Machines and choose Add machine….
  2. Fill in Host, User, Port and Name, then click Continue.
  3. Choose how to sign in: SSH agent / keys (the default), Key file or Password. On the same step, Agents may run defaults to Ask every time. With that setting, an agent working while you're away waits in Needs you until you answer. Click Connect.
  4. Compare the host key fingerprint with the one your provider shows, then click Trust and connect.
  5. In the agent setup checklist, use Install… and then Log in… for Claude Code. Both run in a terminal on that machine, so device-code and browser login flows work.
  6. Press ⌘T to start a task, and choose the remote machine in the machine chip.

API keys you save in Sledbot are never copied to remote machines. If something on the server needs a key while your Mac is off, set it on the server, for example ANTHROPIC_API_KEY in its shell profile.

The remote machines doc covers host keys, port forwarding and removing a machine.

What happens when your Mac sleeps

When your Mac sleeps, nothing on it runs. That includes tmux, Sledbot's local core and every agent on the Mac. Work stops until the Mac wakes. Closing a MacBook's lid normally puts it to sleep too.

You have two options:

  • Keep the Mac awake while the agent runs. The built-in caffeinate command prevents idle sleep for as long as the command it starts is running:

    bash
    caffeinate -i claude

    When you quit Claude Code, caffeinate exits and your normal sleep settings apply again. It doesn't stop the Mac from sleeping when you close the lid. See the caffeinate command on Mac and keeping your Mac awake while Claude Code or Codex runs.

  • Run the agent on another machine. Agents on a remote machine keep going while your Mac sleeps. When the Mac wakes, Sledbot reconnects on its own and shows Reconnecting… on the machine until the connection is back.

Which method to use

MethodSurvives closing the window or appSurvives restarting your MacWorks while your Mac sleeps
tmux on your MacYesNo (resume afterwards)No
--continue / --resumeBrings back the conversation afterwardsBrings back the conversation afterwardsNo
tmux on a serverYesYesYes
Sledbot on this MacYes, even after quitting the appResumes the conversation automaticallyNo
Sledbot remote machineYesYesYes (another Mac today; Linux only with sled preinstalled)
  • Use tmux if you run one agent at a time and don't mind reattaching by hand.
  • Use the resume flags to recover after something has already died.
  • Use Sledbot if you run several agents and want them to survive quitting and reboots without extra setup, with a notice when one needs you. See running multiple Claude Code agents in parallel.

If it doesn't work

tmux attach finds no session. The tmux server has ended, usually because of a restart or a logout. Start a new session and run claude --continue in the project folder.

claude --continue opens the wrong conversation. It uses the folder you run it from. cd into the project first, or run claude --resume <id> with the session you want.

Sledbot shows "Sled Core isn't running". Click Retry, or click Open logs to see what went wrong. Settings ▸ General ▸ Sled Core also has Restart core.

Agents only come back after you open Sledbot. The core isn't allowed to start at login. Open System Settings, search for "Login Items" and allow Sledbot.

A resumed agent opened a plain shell instead of Claude Code. Sledbot couldn't tell which session to resume, for example because two kept Claude Code terminals share the folder, or the resume command failed. Run claude --resume <id> in that shell.

You can't restart an agent after the trial. Agents that are already running keep going after the trial ends, but starting or restarting one needs a licence.

For more fixes, see Troubleshooting Sledbot.

FAQ

Does quitting Sledbot stop my agents? No. Agents run in Sled Core, which keeps going after you quit. To end one, click Stop in its header.

Can I use my Claude subscription on a server? Yes. Log in by running claude on the server itself. Sledbot doesn't store Claude subscription login tokens and never copies keys from your Mac to remote machines.

Does a resumed session remember what it was doing? It gets the conversation back. Commands that were running when the process died didn't finish, so check the working tree before you continue.

Every app.
One purchase.