Guide · Overnight agent runs

Run AI coding agents overnight on a Mac without sleep

You kick off a long Claude Code refactor or a Codex batch, glance at the clock, and step away — maybe to bed, maybe to a meeting. The plan is simple: let the agent grind through the work while you are gone and read the results in the morning. Then you come back to a sleeping Mac and a run that stalled hours ago. This guide covers why macOS sleep kills overnight agent runs, the power and session settings that keep a run alive, and how Perked automates the whole thing — staying awake only while your agents work, then letting the Mac sleep again the moment they finish.

Why macOS sleep kills an overnight run

macOS has two different kinds of sleep, and only one of them is harmless. Display sleep just turns the screen off — your agent keeps running behind a black display, which is exactly what you want overnight. System (idle) sleep is the problem: after a stretch with no keyboard, trackpad, or mouse activity, macOS suspends the whole machine. The CPU parks, background processes freeze, and network connections drop. A coding agent counts as none of that activity, so from the system's point of view an unattended Mac looks idle even while an agent is hammering the CPU — and it gets put to sleep mid-run.

The common assumption is that a plugged-in Mac stays awake on its own. It does not. Idle sleep has a timer that fires on AC power too — the default is just longer than on battery. So the laptop you left charging on your desk still drops off an hour or two into the job, and the agent's session dies with it. Getting an overnight run to finish means defeating idle sleep specifically, without also leaving the Mac awake forever after the work is done.

The power settings that matter

macOS exposes its sleep behavior through the built-in `pmset` tool. It is worth knowing what the relevant keys do — and where driving them by hand falls short:

The catch with all of this is that it is a manual, global, all-or-nothing switch you have to remember to flip before the run and unflip afterwards — and if you forget, the Mac never sleeps again on its own.

Keep the session alive: tmux and detached runs

Staying awake is only half the problem. If you start an agent inside a terminal over SSH, or in a window you later close, the run can die when that connection or session goes away — even on a Mac that never slept. The fix is a persistent session. Start the agent inside tmux (or screen), detach from it, and the process keeps running under the session; you can reattach later from anywhere and pick up exactly where it left off. Running the command with `nohup` or as a background job serves a similar purpose for one-off scripts.

But session persistence and sleep are two separate concerns, and it is easy to conflate them. tmux keeps your process attached to a living session; it does nothing to stop macOS from idle-sleeping the machine underneath it. A detached tmux session on a sleeping Mac is still frozen — the process is preserved, but it is not making progress. You need both: a persistent session so the run survives disconnects, and a stay-awake so the Mac keeps running the session through the night.

Know when it's done: completion notifications

An overnight run is more useful if it can tell you it finished — or that it stopped and needs you. A few lightweight ways to get a signal without babysitting the terminal:

Lock & Leave: walk away without sleeping

Leaving a Mac awake and unlocked on your desk overnight is not ideal. macOS lets you lock the screen with ⌃⌘Q, but the security-conscious move is to lock and keep the run going in one step. Perked's "Lock & Leave" does exactly that: press ⌥⌘A to lock the screen while the session stays awake and the agents keep working. The display goes dark and the machine is secured, but the run underneath never pauses — you can walk away safely and come back to finished work.

Where Perked fits

Perked is a macOS menu-bar app that automates all of this so you do not have to remember any of it. It auto-detects 22 coding agents out of the box — Claude Code, Codex, Cursor, Gemini CLI, Aider and more — plus any custom app you add, and it keeps the Mac awake only while one of them is actually running. Kick off the run and step away; Perked handles staying awake for you, no `pmset` and no flag to unset.

Because it is tied to what the agents are doing, it also solves the other half of the problem: when the last agent finishes, Perked lets the Mac sleep again on its own, so an overnight run does not turn into a Mac that stays awake all day. It is power-aware — require AC power or a battery threshold you set — it works with the lid closed, and it pairs with "Lock & Leave" so you can secure the screen without stopping the run.

It is a one-time purchase from €1 — currently €1, and whatever you pay is locked in for good.

Overnight agent runs FAQ

Will a plugged-in Mac stay awake for an overnight agent run on its own?

No. macOS idle-sleep has a timer that fires on AC power too, just after a longer delay than on battery — so a charging Mac still sleeps mid-run and stalls the agent. You have to defeat idle sleep specifically, either with pmset or with an app like Perked that does it automatically only while an agent is running.

Does running my agent in tmux stop the Mac from sleeping?

No. tmux keeps the session alive so the run survives disconnects and closed windows, but it does nothing to stop macOS from idle-sleeping the machine. On a sleeping Mac the detached session is frozen. You need a stay-awake as well — tmux for persistence, and something like Perked to keep the Mac running through the night.

How do I get notified when an overnight run finishes?

Chain a notifier onto the end of your command. osascript -e 'display notification …' pops a native macOS banner, say speaks an alert, and a one-line curl to ntfy or Pushover pushes to your phone. Many agents also have hooks that can run a command when a task completes.

Can I lock my Mac and still let the agents keep working?

Yes. Perked's "Lock & Leave" locks the screen with ⌥⌘A while the session stays awake, so the display is secured and dark but the agents keep running underneath. When the run is done, Perked lets the Mac sleep again on its own.

Let your agents run overnight

One-time purchase, yours forever — €1 today, and your price is locked in for good.

See the full price ladder →

Related guides

Want the fundamentals first? Keep your Mac awake for Claude Code & Cursor →

Leaving the laptop shut on your desk? Keep your MacBook awake with the lid closed →

← Back to Perked