Back to Guides

Run Claude Code or Codex overnight on a MacBook: a checklist

Run Claude Code or Codex overnight on a MacBook: a checklist

Work that should run overnight without you is better placed on a server, a desktop computer or a cloud environment, for example a Claude Code cloud session or Codex Cloud. If it has to be your MacBook, you need the power adapter, protection against sleep, a run that does not wait for approvals, and a look at the result in the morning.

What are the options?

  • Cloud: The run happens at Anthropic or OpenAI, and your MacBook may sleep. Your project must be available there, for example via GitHub.
  • Server or desktop computer: A machine that runs anyway does the work.
  • Your MacBook: It stays plugged in and awake. You leave the lid open, use an external display, or lower the lid onto a spacer such as WakeClip for MacBook Air, MacBook Neo and MacBook Pro.

What do Anthropic and OpenAI offer in the cloud?

A Claude Code cloud session runs on Anthropic's infrastructure and keeps working after you close your laptop. Cloud scheduled tasks, formerly routines, run at fixed times, for example hourly, nightly or once. They are a research preview. In OpenAI's Codex Cloud, each task has its own workspace and can keep working while your computer is asleep.

Scheduled tasks in both desktop apps can also work locally. Then, according to Anthropic and OpenAI, they need a running computer and the open app.

Checklist for a run on your MacBook

1. Plug in the power adapter

An empty battery ends every run. The macOS setting against sleep with the display off also works only on the power adapter.

2. Prevent idle sleep

After a while without input, the Mac goes to sleep. Many tools keep it awake themselves while they work. Claude's desktop app calls the option "Keep computer awake", OpenAI's desktop app "Prevent sleep while running".

In the Terminal, start the agent with caffeinate -i claude or caffeinate -i codex. According to man caffeinate, this prevents idle sleep while the program runs. Or, as Apple describes, turn on "Prevent automatic sleeping on power adapter when the display is off" under System Settings, Battery, Options. More in the guide caffeinate, pmset and the lid.

3. Think about the lid

Closing the lid always puts a MacBook without an external display to sleep, even with caffeinate. Three ways need no extra software:

  • Leave the lid open. It costs nothing. The display turns off after the time set in your settings.
  • External display. With the lid closed, the Mac needs power plus an external keyboard and mouse, according to Apple.
  • Lid spacer. WakeClip keeps the lid 12 mm open. Your MacBook does not go to sleep from closing the lid, and whatever is running keeps running. This helps if you close the lid out of habit or do not want the MacBook standing open. Unlike a fully closed lid, there is air above the keyboard, and heat can escape.

Idle sleep is still handled by your Mac's settings or the running program, clip or not. WakeClip is made for carrying in your hand, not for the bag. With the lid fully closed, Amphetamine and some similar apps can help, or sudo pmset -a disablesleep 1, which you undo afterwards with sudo pmset -a disablesleep 0. The comparison lists all ways.

4. Settle approvals before you leave

An agent waiting for your approval at night stands still until morning, even on an awake Mac. Decide beforehand what the run may do, and give it only the rights it needs.

Claude Code uses permission modes. In Manual mode it usually asks before file edits, shell commands and network access. In Auto mode a second model reviews actions in your place. If that model blocks actions repeatedly, Claude Code goes back to asking you. The dontAsk mode runs only what needs no approval or was allowed beforehand, and denies the rest instead of waiting. You allow single commands, such as your test command, with rules under /permissions.

Codex separates two layers. The sandbox, a fenced-off area, sets where Codex may write and whether it may reach the network. The approval policy sets when it asks you. For version-controlled folders, Codex recommends the Auto preset. It then works on its own in the working folder and asks before it edits files outside it or runs commands that need network access. For runs without prompts, OpenAI names codex exec --sandbox workspace-write. Without that flag, codex exec runs read-only.

Broad rights let the agent change more without your review, so both providers advise using modes without any checks only in isolated environments such as containers.

5. Make sure the Wi-Fi is stable

A local run still needs the internet all night, because the agent queries the model at the provider. If the connection drops, the run can stop even on an awake Mac. Claude Code then shows an error such as "Unable to connect to API". Leave the MacBook where the Wi-Fi is stable.

6. Keep updates out of this night

When macOS notifies you about an update, you can install it immediately or later that night, according to Apple. During installation the Mac might restart several times, and a restart ends the run. So install pending updates before you start, and do not choose "Update Tonight". Automatic installation is set under System Settings, General, Software Update, "Automatic Updates".

7. Check the result in the morning

Claude Code saves sessions continuously as transcripts under ~/.claude/projects/. In the project folder, claude --continue reopens the last session, and /export saves it as a text file. Codex saves sessions too: codex resume --last opens the last one in the current folder, and with codex exec, -o result.md writes the final answer to a file.

Then check which files changed, whether tests ran and whether the agent is waiting for you. pmset -g log shows whether the Mac slept during the night.

8. Give it air

Put the MacBook on a firm surface. Apple's notes on operating temperatures advise using it on a stable work surface with good ventilation, not in bed, on a pillow or under bedding. Keep the ventilation openings clear and put nothing on the keyboard or the lid.

Where to go from here

Test the setup beforehand with a short task. For each agent, see the guides on Claude Code and Codex.

If a lid with a 12 mm gap suits your setup, see the WakeClip version for your MacBook model. WakeClip is an independent accessory and is not affiliated with Apple, Anthropic or OpenAI.