Keep Claude Code or Codex running after you close your laptop
Checked 16 November 2026
A coding agent runs where its process runs. If that process is on your laptop and the laptop sleeps, the agent stops. Remote access doesn't change that: a phone app can show you the session, but it can't make a sleeping machine run code. To keep working, you either keep the laptop awake or run the agent somewhere else.
This page is published by Bivy, which is one of the options. Each claim below comes from the product's own docs, site or manual page, linked under Sources. Products change often, so check the linked page before you rely on a detail. For apps that steer an agent from a phone, see Run Claude Code or Codex from your phone.
| Option | Where the agent runs | Laptop can sleep? | Local services and uncommitted work | Phone access | Cost |
|---|---|---|---|---|---|
| Keep the laptop awake | Your laptop | No | Yes, everything on the laptop | Through a remote tool, such as Remote Control or SSH | Free; battery and heat |
| Always-on machine + tmux, SSH or mosh | Your desktop, home server or VPS | Yes | Only what is on that machine; push or copy work there first | Phone SSH or mosh app | Your hardware or VPS bill; tmux, mosh and Tailscale Personal are free |
| Claude Code cloud sessions | Anthropic-managed VM | Yes | No local services. Clones your pushed GitHub branch, or uploads tracked files including uncommitted changes | Claude app Code tab, claude.ai/code | Pro, Max, Ultra, Team, some Enterprise seats; shares your plan's usage limits |
| Claude Code Remote Control | Your computer | No; it reconnects after waking | Yes | Claude app, claude.ai/code | Pro, Max, Ultra, Team, Enterprise; API keys not supported |
| Codex cloud | OpenAI's cloud, one workspace per task | Yes | Works from repositories Codex can clone, such as GitHub or GitLab.com | ChatGPT app | Plus $20/month, Pro from $100/month, Business, Edu, Enterprise; not with an API key |
| Codex remote connections | Your Mac or Windows PC running the ChatGPT desktop app | No | Yes | ChatGPT app | Needs Codex access in your ChatGPT workspace |
| Bivy on your own machine | Your Mac or Linux machine | Yes, if the agent runs on a machine other than the laptop | Yes, on that machine | Installable web app (PWA) | Your own machines never count against a plan; self-host $0 |
| Bivy cloud computer | A persistent machine in Bivy's Fly.io account | Yes; it sleeps when the work stops | Not your laptop's services. Moving a session carries committed state and a bounded uncommitted patch | Installable web app (PWA) | Free: 5 hours once. Cloud: $15/month with 120 hours, then $0.10/hour |
Keep the laptop awake
The simplest option, if you can leave the laptop plugged in where it is. The agent keeps your files, local services and logins. The cost is a laptop that can't go in a bag.
- macOS, one command:
caffeinate -i -s claudeholds the assertions for as long asclauderuns.-iprevents idle sleep.-sprevents system sleep, but its manual says it is valid only on AC power. To cover a process that is already running, usecaffeinate -i -s -w <pid>. - macOS, settings: on a laptop, System Settings › Battery › Options has “Prevent automatic sleeping on power adapter when the display is off”. Apple notes this uses more power.
- macOS, lid closed: the
caffeinatemanual covers idle and system sleep, not the lid. Apple documents lid-closed use with an external display connected. OpenAI's Codex docs say a Mac laptop with the lid closed needs power and an external display to stay reachable, and that choosing Sleep stops remote access. - Linux, one command:
systemd-inhibit --what=idle:sleep:handle-lid-switch claudeholds the locks whileclauderuns. Includehandle-lid-switch: logind's defaultLidSwitchIgnoreInhibited=yesmeans a plain sleep lock does not stop suspend on lid close. - Linux, settings: in a drop-in such as
/etc/systemd/logind.conf.d/lid.conf, setHandleLidSwitch=ignore, orHandleLidSwitchExternalPower=ignoreto stay awake only when plugged in.HandleLidSwitchDocked, used in a dock or with more than one display connected, already defaults toignore. Desktop environments can apply their own power settings on top. - Limits: the laptop has to stay put, powered and on the network. A closed laptop in a bag gets hot. When you leave the Wi-Fi, the agent may lose network access, and any remote view of it drops.
Run it on an always-on machine you own
The do-it-yourself option: a desktop, home server or VPS runs the agent, and you connect to it. It works with any terminal agent and adds no service in between.
- tmux or screen: start
tmux new -s agent, runclaudeorcodexinside it, and detach withCtrl-b d. The tmux wiki says detaching leaves the session and its programs running. Reattach later withtmux attach -t agent. Anthropic's Remote Control docs give the same advice: on a remote machine, startclaudeinside tmux or screen so it survives an SSH disconnect. - SSH or mosh: mosh roams between networks and resumes when service comes back, so your client laptop can sleep and reconnect. Mosh's own session lasts only as long as the connection, so pair it with tmux, for example
mosh host -- tmux attach -t agent. - Tailscale: puts your devices on one private network, so you don't open ports. Tailscale SSH can handle SSH authentication with your Tailscale identity. The Personal plan is free for up to 6 users and unlimited devices, for non-commercial use.
- Trade-off: the work has to live on that machine. Push your branch or copy the checkout there before you start, and run the services the task needs there too. From a phone you get a terminal: no push notifications, approval buttons or diff view unless you add them. Phone apps for this are compared in the phone guide.
Claude Code cloud sessions and Remote Control (Anthropic)
Cloud sessions keep Claude Code going after you close the laptop. Remote Control does not. They are easy to confuse, because both show up in the Claude app.
- Cloud sessions: run in an isolated, Anthropic-managed VM. Anthropic's docs say the session keeps running after you close your laptop. Start one from claude.ai/code, the Code tab in the Claude app, the Desktop app, or
claude --cloud "task"in your repo. - Eligibility: Pro, Max, Ultra and Team plans, and Enterprise users with premium or Chat + Claude Code seats. Usage shares rate limits with the rest of your Claude and Claude Code usage. It needs a claude.ai sign-in; it is not available through Amazon Bedrock, Google Cloud's Agent Platform or other third-party providers.
- GitHub: repository cloning and pull requests need GitHub.
--cloudclones your GitHub remote at your current branch, not your local checkout, so push first. Without the Claude GitHub App, or withCCR_FORCE_BUNDLE=1, it uploads a bundle that includes uncommitted changes to tracked files but not untracked files, and leaves out files named like credentials on macOS, Linux and WSL. A session from a bundle can push back to GitHub only if your GitHub connection has push access to that repository. - What it can't reach: your local services, databases and anything only on your laptop. Network access is limited by default and set per cloud environment.
- Idle sessions: they stop after a period of inactivity and the VM is reclaimed. Reopening restores the conversation, but not shell commands or subagents that were still running.
- Moving work: from the CLI, handoff is one-way.
claude --teleportpulls a cloud session into your terminal, but you can't push a running terminal session to the cloud. The Desktop app can send a local session to the cloud from its Open in menu. - Remote Control:
claude remote-controllets you steer a session that runs on your own machine from the Claude app. If the laptop sleeps, the session reconnects when it is back online, but theclaudeprocess has to keep running, so nothing happens while it sleeps. Pro, Max, Ultra, Team and Enterprise; API keys are not supported.
Codex cloud and Codex in ChatGPT (OpenAI)
Codex cloud runs tasks on OpenAI's side; remote connections steer a computer you own. Only the first keeps going while your laptop sleeps.
- Cloud tasks: OpenAI's docs say each task has its own workspace and can keep working while your computer is asleep. Start tasks from the web, the desktop app, your terminal, or Codex in the ChatGPT app on your phone.
- Setup: a default environment, where available, starts without a repository. For a reusable environment you choose GitHub or GitLab.com repositories, and Codex inspects them, installs dependencies and tests the workflow. Network access, from package-manager domains to the full public internet, is set per environment.
- Plans: OpenAI's pricing page lists Codex on the web, CLI, IDE extension and iOS for Plus ($20/month) and Pro (from $100/month). Business mentions larger virtual machines for cloud work, and Edu and Enterprise include Business features. Free and Go are listed for the desktop app. An API key gives no cloud features.
- Remote connections: the ChatGPT app can control a Mac or Windows PC running the ChatGPT desktop app. The host must be awake, online and signed in. OpenAI suggests keeping it plugged in and turning on the keep-awake option in the desktop app's Connections settings; choosing Sleep stops remote access.
- Trade-off: cloud tasks work on repositories Codex can clone, not your laptop's local services. OpenAI's docs don't say whether uncommitted local changes reach a cloud task.
Bivy
Runs Claude Code, Codex and other agents on a machine you pick, and lets you follow and steer them from a phone, browser or terminal. The machine can be your own computer or server, or a Bivy cloud computer. Bivy runs the real agent CLIs, each with its own login and configuration.
- Your own always-on machine: connect a Mac or Linux desktop or server. The agent uses the repo, local services, databases and tools on that machine. Machines dial out, so there are no ports to open. Sessions on your own machines never count against a plan.
- A Bivy cloud computer: one persistent machine with its own disk, so tools and sign-ins you set up are still there next time. It sleeps when the work stops, meaning no turn running, no device attached and no queued work, and wakes when you send a message, open a preview, or an automation fires. Hours count only while it is awake.
- Moving off the laptop: start at your desk, then open the session's menu and choose Fork / move… to send it to another machine, such as the cloud computer. Bivy carries committed repository state, a bounded patch of uncommitted changes and portable conversation history. Bivy treats cross-machine moves as a 0.x capability: a move can pause for missing repository access or agent credentials, and you should check the destination's first turn before deleting the original.
- From the phone: watch the session live, answer questions, approve tool calls, open its terminal, send files, stop it, and get push notifications. There is no native iOS or Android app yet. Bivy is an installable web app (PWA).
- Security: session traffic is end-to-end encrypted between the machine and your paired devices. The relay forwards encrypted frames, and the control plane stores account and session-index metadata. On a Bivy cloud computer, the control plane and relay still can't read its sessions, but the machine runs in Bivy's Fly.io account, so Bivy and Fly.io can technically reach it. If that matters, use your own machine or self-host. App previews and push notification text are not end-to-end encrypted.
- No-account option:
bivy tailscaleserves the app from your machine over your tailnet, with no Bivy account, control plane or relay. Push notifications and previews need the hosted service or your own server. - Cost and license: MIT-licensed, including the relay, control plane and cloud-computer fleet. The free plan has 10 new sessions a week and 5 hours on a Bivy computer, once. The Cloud plan is $15/month with 120 cloud-computer hours, then $0.10/hour. Sleeping is free. Self-hosting is $0. Agent subscriptions are separate.
- Trade-off: a cloud computer doesn't have your laptop's local services, and a web app replaces a native one. Unless you use Tailscale mode or self-host, there is one more service between you and the agent.
Which should you pick?
- One long task, and the laptop can stay on your desk, plugged in: keep it awake with
caffeinateorsystemd-inhibit, and use Remote Control or Codex remote connections to check on it. - You already have a desktop, home server or VPS: run the agent there in tmux, and reach it with SSH or mosh over Tailscale. See Run Claude Code or Codex on a home server.
- Claude Code, a GitHub repo, and no local services needed: Claude Code cloud sessions. Push your branch first.
- Codex on a Plus, Pro or business plan, with a GitHub repo: Codex cloud.
- The task needs your local database, VPN or GPU: run it on a machine that has them and stays on, in tmux or through Bivy on that machine.
- Several agents, a session you started on the laptop, and no server of your own: Bivy with a cloud computer, if a machine in Bivy's Fly.io account is acceptable for your code.
FAQ
Does Claude Code keep running when I close my laptop?
Not if it runs on the laptop. Closing the lid normally puts the laptop to sleep, and a sleeping machine runs no processes. Claude Code's Remote Control reconnects when the laptop wakes, but no work happens while it sleeps. To keep going, keep the laptop awake, run Claude Code on a machine that stays on, or start a cloud session.
Can I keep a MacBook running with the lid closed?
Apple documents lid-closed use with an external display connected. OpenAI's Codex docs add that a Mac laptop with the lid closed needs both power and an external display to stay reachable. Without those, closing the lid puts the Mac to sleep.
How do I stop a Linux laptop from suspending when the lid closes?
Set HandleLidSwitch=ignore, or HandleLidSwitchExternalPower=ignore for plugged-in only, in a logind.conf drop-in. For one command, run it under systemd-inhibit with handle-lid-switch in --what. A plain sleep inhibitor is ignored on lid close by default.
Can I move a running local session to the cloud?
With Claude Code's CLI, no: handoff is one-way, from cloud to terminal with --teleport. The Claude Desktop app can send a local session to the cloud from its Open in menu. Bivy can fork or move a session from your laptop to another machine, including a Bivy cloud computer.
Do cloud sessions see my local database and uncommitted changes?
No local services. Claude Code cloud sessions clone your GitHub branch, so push first, or upload a bundle that includes uncommitted changes to tracked files but not untracked files. Codex cloud tasks work from repositories Codex can clone, such as GitHub or GitLab.com.
Sources
All checked on 16 November 2026.
- Apple: Set sleep and wake settings for your Mac, Connect an external display to MacBook Pro,
caffeinate(8)manual page - systemd:
systemd-inhibit,logind.conf - tmux: Getting Started. Mosh: site. Tailscale: Tailscale SSH, pricing
- Anthropic: Claude Code cloud sessions, Remote Control
- OpenAI: Codex cloud, Codex pricing, Remote connections
- Bivy: README, cloud computers and runners, fork or move a session, remote access, security model, Tailscale, pricing
Want to try Bivy? Start on a cloud computer with nothing installed, or connect your own Mac or Linux machine.