All guides

Does Codex keep running when you close your laptop?

Updated 27 November 2026 · 5 min read

No, not by default. The Codex CLI runs on your computer, so when you close the lid and the laptop goes to sleep, Codex stops with it and carries on only when the computer wakes. To keep a local session working, keep the laptop on power and stop it from sleeping: Codex has an experimental setting for that, and Mac, Windows and Linux each have their own. If you want work to continue with the computer completely off, use a Codex cloud task, which runs in a cloud environment instead of on your machine.

01Why closing the lid stops Codex

The codex CLI is a program on your machine. It reads your files, runs your commands in its sandbox and calls the model from there. A sleeping computer runs no programs, so a turn in progress simply stops where it was. When the computer wakes, the terminal session is still there.

The same applies to OpenAI's Codex on mobile, which drives the ChatGPT desktop app on your computer. OpenAI's remote connections docs say that if the computer "sleeps, loses network access, or closes the app, remote access stops until it's available again."

02Codex's own setting: Prevent sleep while running

The Codex CLI has an experimental feature called Prevent sleep while running. Turn it on in /experimental, or add it to ~/.codex/config.toml:

[features]
prevent_idle_sleep = true

OpenAI's config reference describes it as preventing "the machine from sleeping while a turn is actively running (experimental; off by default)". It's available on macOS, Windows and Linux.

Two limits are worth knowing. It only holds while a turn is running, so once Codex finishes and waits for you, the computer can sleep as normal. And in the Codex source it prevents idle sleep (on macOS it uses a PreventUserIdleSystemSleep assertion), which is the sleep that happens when you leave the computer alone. Closing a laptop lid is a separate trigger, so you still need the system settings below if you want to shut the lid.

03Keep a laptop awake on Mac

caffeinate keeps the Mac awake for as long as a command runs:

caffeinate -i codex

-i stops idle sleep while Codex runs. To keep working with the lid closed, a MacBook also needs to be on power with an external display connected (clamshell mode). With no display attached, closing the lid still sleeps it. If you'd rather walk away with the lid open, leave it plugged in and let the display turn off.

04Keep a laptop awake on Windows

In Control Panel > Power Options > Choose what closing the lid does, set "When I close the lid" to Do nothing for "Plugged in". Then set sleep to Never while plugged in, under Settings > System > Power. Microsoft PowerToys also has an Awake tool that keeps the computer awake on demand.

05Keep a laptop awake on Linux

On distributions with systemd, run Codex under an inhibitor so the system doesn't sleep while it runs:

systemd-inhibit --what=idle:sleep:handle-lid-switch codex

Your desktop environment's power settings may also have a "when the lid is closed" option.

06If you use the ChatGPT desktop app

When you control a computer from your phone through the ChatGPT desktop app, that app has its own setting, Keep this Mac awake, described as "Prevent sleep when computer is plugged in and remote access is enabled". OpenAI's docs say a Mac laptop can stay available with the lid open and power connected, and with the lid closed only if an external display is connected as well. They also say that choosing Sleep still stops remote access. This setting belongs to the desktop app; it doesn't affect a codex session in your terminal.

07When you want it to run with the computer off

Use a Codex cloud task. OpenAI's cloud docs say each task "has its own workspace and can keep working while your computer is asleep." You can start one in ChatGPT on the web or the desktop app (Work in > Cloud), from the Codex section of the mobile app, or from your terminal.

The trade-off: a cloud task works in the cloud environment you set up, with the repositories and tools you give it, not with your local files, credentials and services. For work that needs your machine, keep it awake.

08Leaving a long task on a laptop that stays on

Keeping the computer awake is half of it. Codex still stops at approvals, questions and the end of each turn, and nobody is there to see it. Leave Codex running and walk away has the full routine: sandbox settings that cut down approvals, a clear definition of done, and a way to hear from Codex.

Notifier for Codex covers that last part. It's an independent tool, not made by OpenAI, with a free command line tool, codex-notifier, for Mac, Windows and Linux, and apps for iPhone and Android. It sends a push when Codex finishes, needs an approval or asks a question, and you can approve, reject, answer or send the next instruction from your phone. It doesn't keep a computer awake, so use it with the settings above.

09FAQ

If I close my laptop, does Codex lose my session?

No. The session pauses while the computer sleeps and continues when it wakes. Quitting the terminal or stopping the codex process is what ends it.

Does prevent_idle_sleep let me close the lid?

Not on its own. It prevents idle sleep while a turn runs. Closing the lid is handled by your system's lid settings, or on a Mac by clamshell mode with power and an external display.

Can I close the lid on a MacBook and keep Codex running?

Only in clamshell mode, with power and an external display connected. Otherwise keep the lid open on power and run caffeinate -i codex.

Does Codex run in the cloud?

It can. Codex cloud tasks run in a cloud environment and keep working while your computer is asleep. A codex session in your terminal runs on your computer.

Notifier for Codex Get a push on your phone when Codex finishes or needs you, then approve, reject or answer from there. The codex-notifier command line tool is free on Mac, Windows and Linux.