Mac went to sleep mid Claude Code run? Here's the fix.

Claude Code stops the moment macOS sleeps — there's no way around that once it happens. The fix is to stop your Mac from sleeping while Claude Code is actually working, then let it sleep again once it's been quiet for your grace window — 90 seconds by default.

To keep your Mac awake while Claude Code runs: the free way is macOS's built-in caffeinate -i — run it in Terminal before you start, and stop it yourself when the run ends. The automatic way is AgentBarista, which detects Claude Code working and lets your Mac sleep when the run finishes.

The short answer

Your Mac slept because it looked idle to macOS — even though Claude Code was working.

Claude Code spends a lot of its time waiting on the model, not burning CPU. macOS only tracks keyboard/mouse activity and overall CPU load — to the OS, a long Claude Code run can look exactly like an idle terminal. So it goes to sleep on schedule, and the run just stops. There's no "resume" — whatever Claude Code was doing when the lid closed or the screen locked is interrupted, and you have to re-run it.

The fix isn't to disable sleep entirely (then your Mac never sleeps, ever, even when you've actually stepped away for the night). The fix is something that watches for Claude Code specifically and holds sleep off only while it's working.

Honestly — the free option first

caffeinate and Amphetamine will do the basic job for free.

If you only run Claude Code occasionally, macOS already ships a command-line tool for this: open Terminal and run caffeinate -i before you start a long task. It keeps the Mac awake until you close that Terminal window or kill the process. Amphetamine (free, Mac App Store) gives the same idea a menu-bar UI with timers and triggers.

Both are a perfectly fine choice for a one-off long run. What neither does: know the difference between "Claude Code is mid-task" and "I forgot to close caffeinate three hours ago." You have to remember to start it, and remember to stop it — or your battery drains overnight on a Mac that's just sitting there with a finished task and an open terminal.

The more reliable way

AgentBarista watches Claude Code itself, not the clock.

Claude Code is one of the agents AgentBarista detects out of the box. Instead of a manual timer, it checks Claude Code's process activity and what's on screen, decides whether it's actually working, and only holds sleep off for that window.

No manual start/stop

Launch Claude Code, start your task, and AgentBarista picks up the activity on its own — no command to remember to run first.

Knows "thinking" isn't "idle"

A long model turn can sit at 0% CPU. AgentBarista checks for that case too, so the Mac doesn't sleep right as Claude Code is about to respond.

Lets go when it's done

Once Claude Code goes quiet, normal sleep comes back automatically. It doesn't sit there holding your battery hostage after the run finishes.

It also watches for the other agents most developers run alongside Claude Code, so you're not running one tool per agent:

Claude Code Codex Gemini CLI Copilot CLI OpenCode Cursor VS Code Windsurf Zed Antigravity Claude ChatGPT + more
What it can see

It checks that Claude Code is running. Here's exactly what it can see.

One honest caveat: this fixes the "macOS decided things look idle and slept" problem on any Mac, lid open or closed, plugged in or on battery — your Claude Code run finishes instead of stalling when you step away. We haven't verified lid-closed overnight battery behavior on real hardware yet, so we're not going to promise that part beyond what we've tested.

Getting it

$19/year, locked in for as long as you stay subscribed. Cancel any time.

It's a menu-bar app with a battery cutoff and an emergency restore, signed and notarized by Apple. The full agent list lives on the AgentBarista home page.

$19/year — less than one saved overnight run pays for a year of it. Lock that rate in before September 15; new subscribers after that pay $29/year. 30-day money-back guarantee — one email, full refund. The download is the trial — the full app, free for 14 days, no card needed.

More agents

Also running Codex CLI, Cursor, or another agent?

Same Mac-goes-to-sleep problem, different tool. Each of these guides covers the fix for that agent specifically: