Every account starts with a 7-day trial. How to open it

Latte
Guide

Why your Mac stops long AI agent runs

Idle sleep, the lock screen, a closed lid, update restarts and a prompt nobody answers: the five ways a run dies, and the fix for each.

By Harsh Soni, maker of Latte · Updated

AI coding agents like Claude Code, Codex and Grok can work for an hour or more on their own. A MacBook isn't built for that: it's built to save power the moment you step away. Here are the five things that stop a long run, and how to deal with each.

1. Idle sleep

Leave the Mac alone for a few minutes and macOS sleeps it, even mid-task, unless something holds it awake. Claude Code does this for itself while it works on recent versions. For anything else, check what's holding the Mac awake right now:

pmset -g assertions

Look for a PreventUserIdleSystemSleep line from your agent or terminal. If there isn't one, wrap the command with caffeinate -i.

2. The lock screen

Locking the Mac on its own doesn't stop your agent, but it often comes with the screen going dark and the Mac drifting into sleep shortly after. As long as idle sleep is held off, work carries on behind the lock screen.

3. Closing the lid

This is the one that catches everybody. Closing the lid sleeps the Mac straight away, and keep-awake holds like caffeinate don't stop it. The exceptions are clamshell mode (power plus an external display) and the pmset disablesleep setting. The full list of options is in how to keep Claude Code running with the lid closed.

4. Overnight update restarts

macOS can install updates and restart overnight. That ends every session in your terminal. If you leave agents running overnight, either turn off automatic macOS updates while they run, or use a tool that defers them only during a run (Latte does this and puts your setting back afterwards).

5. A prompt nobody answers

The quiet one. The Mac is awake, the agent is fine, and it's been sitting on “Allow this command?” for an hour because you're at dinner. The fix is getting the prompt to your phone: see how to approve Claude Code prompts from your phone.

Watch out for the opposite problem

Once you fix all of this, the risk flips: a Mac that never sleeps, running hot in a bag with a draining battery. Whatever you use, make sure something lets the Mac sleep again when the work is done.

Summary

What stops the runQuick fixWith Latte
Idle sleepcaffeinate -i <command>Held while an agent works
Lock screenHold off idle sleepHeld while an agent works
Closed lidClamshell mode or pmset disablesleepHeld, on battery too if you turn it on
Update restartTurn off automatic updatesDeferred during a run, then restored
Unanswered promptRemote Control or a phone bridgePrompt sent to Telegram or ntfy

Common questions

Why does my AI coding agent stop when I walk away from my Mac?
Usually because the Mac went to sleep: idle sleep after a few minutes, a closed lid, or an overnight update restart. The other common cause is a permission prompt waiting for your answer.
How do I see what is keeping my Mac awake?
Run pmset -g assertions in Terminal. A PreventUserIdleSystemSleep entry means something is holding off idle sleep, and the line names the process.
Will my agent's work be lost if the Mac sleeps?
Usually not. The process is frozen and resumes on wake, but network requests in flight can fail or time out, which may end the run with an error.
Close the lid. Keep shipping.

Latte keeps Claude Code, Codex and Grok working with your MacBook closed, sends approvals to your phone, and lets the Mac sleep the moment the work is done.

Start your 7-day trialNo card needed · $2 a month after