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 the second the task is done.

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 (14-day free trial, then $19 one-time), 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. It doesn't read what you're working on.

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.

Get it

14-day free trial. Then $19 once — not a subscription.

Pricing and the full agent list live on the AgentBarista home page.

Not live yet — leave your email and we'll ping you the moment it is.

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: