Keep Codex running overnight on a Mac

LidRun Team
6 min readJun 2026
Keep Codex running overnight on a Mac

An overnight Codex run is the kind of thing you start before bed and hope to find finished by morning. Then the Mac sleeps, or the lid closes, and the agent is suspended mid-task. Here is how to keep Codex running overnight on a Mac without pushing the hardware past where it should go.

Why an overnight Codex run dies

macOS is built to sleep an idle laptop. After the idle timer, or the moment you shut the lid, the system suspends, and every running process suspends with it, Codex included.

Nothing is lost when this happens. The agent stops where it was and waits. But a multi-hour run you wanted finished by morning is now barely started, and the night is gone.

Two different things are in play. The idle sleep timer fires when you step away with the lid open. A lid close is a separate clamshell sleep that kicks in within seconds. Keeping Codex alive overnight means handling both.

Keeping the agent alive without straining the Mac

LidRun holds a PreventUserIdleSystemSleep power assertion through IOKit, which is what stops the idle timer from suspending the run. caffeinate does the same job for idle sleep, so the assertion is the well-trodden part.

A closed lid needs more. LidRun handles that with the documented pmset disablesleep toggle, asked for through a native macOS admin prompt and paired so it is always undone again on stop or quit.

The part that matters for an unattended night is the guardrails. LidRun reads battery charge and thermal state for the whole run and steps back, letting the Mac sleep, if charge drops past your floor or thermal pressure climbs. It is meant to reduce risk on a long run, not to override the protections macOS already has, and it does not promise a Mac cannot get warm.

Related guideA lid-closed developer workflow for the MacBook

When it is worth it, and when it is not

If your Codex task finishes in a few minutes, you do not need any of this. Leave the lid open and let it run.

Overnight keep-running is for the long jobs: a large refactor, a batch of agent tasks, a run that leans on a slow model or a big repo. The kind you want done by morning without sitting over it.

It is most worth turning on when you would otherwise prop the lid open just so the run survives, especially if the Mac will be on battery or somewhere warm while you sleep.

A safe overnight setup

Keep the Mac plugged in. Overnight runs on battery are possible, but mains power removes the drain question, and you can keep the low-battery auto-stop on anyway so a power cut ends the session cleanly.

Run it on a hard, flat, ventilated surface. A closed lid already traps some heat; a bed, a couch cushion, or a sealed bag makes that worse, and no software fixes airflow that is not there.

Set a session timer and leave the thermal and battery guards on. The point of an overnight setup is that it ends itself safely whether the run finishes early, the battery runs low, or the heat climbs, so you are not relying on remembering to stop it.

A feature of LidRun for closed-lid Mac.

Try it instead of fighting clamshell sleep

LidRun keeps your work running with the lid closed, with battery and thermal safety built in.

Download for macOS

Frequently asked

Does LidRun detect Codex automatically?

LidRun's Auto Mode can watch for known long-running processes and keep the Mac awake only while they run. You can also start a manual session before you launch Codex and let the session timer cap it.

Is it safe to run with the lid closed overnight?

It is safer with the guardrails on and the Mac plugged in on a ventilated surface, but a closed lid traps heat by design. Keep it out of a sealed bag, leave the thermal and battery guards on, and treat them as risk reduction rather than a guarantee.

Will it drain my battery if I am not plugged in?

LidRun auto-stops below a charge threshold you set, so a long run does not drain to zero. For an overnight run, plugging in is still the calmer choice.

What happens when the run finishes?

With Auto Mode, LidRun releases the wake lock once the watched process exits and lets the Mac sleep again. A session timer gives the same outcome if you started the session manually.