Here's the direct fix: your Mac sleeps on a timer that only looks at keyboard/mouse activity and screen wake-locks — it has no idea Gemini CLI is still waiting on a response or mid-tool-call, so it sleeps anyway and your terminal session gets cut off. Stop it by keeping the Mac's display/system sleep from kicking in for as long as Gemini CLI is actually running — either with a free always-on tool, or with something that turns off again the moment Gemini CLI is done.
To keep your Mac awake while Gemini CLI 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 Gemini CLI working and lets your Mac sleep when the run finishes.
Most of a Gemini CLI run is spent waiting on the model or a tool call — which means actual CPU use sits near zero for long stretches. macOS's sleep timer doesn't check "is a process doing meaningful work," it checks "has anyone touched the keyboard or trackpad recently." No input for a few minutes, on battery especially, and the display sleeps, then the system follows. If Gemini CLI was mid-task — writing a file, waiting on a long tool call, running a multi-step plan — that session just stops. On reconnect you'll usually find a half-finished edit or a dead terminal tab.
This isn't a Gemini CLI bug. Any long-running terminal agent has the same problem on a default macOS sleep policy — Claude Code, Codex, Cursor's agent mode, all of it.
Open Terminal and run caffeinate -i in the same window before you
start Gemini CLI (or run caffeinate -i gemini to scope it to just that command). It's a
built-in macOS tool — no install needed — and it'll hold off idle sleep for as long as that terminal
tab stays open. Amphetamine
(free, Mac App Store) does the same thing with a menu-bar UI if you'd rather not touch the command
line — pick "indefinite" or trigger it on an app launching.
Either one is a completely fine choice if you only run Gemini CLI occasionally. The catch: both keep the Mac awake the whole time you have that terminal/app open, even when Gemini CLI itself isn't doing anything — so if you forget to turn it off, your battery pays for it. You also have to remember to start it every time, and remember to stop it when you're done.
Gemini CLI is in the list of agents AgentBarista detects out of the box — alongside Claude Code, Codex, Cursor, Copilot CLI, OpenCode, Windsurf, Zed, Antigravity, and the Claude and ChatGPT desktop apps.
Matches the process and on-screen text for Gemini CLI specifically, not "any terminal with activity" — so it doesn't keep your Mac awake for the wrong reason.
Gemini CLI waiting on a model response looks idle by CPU alone. AgentBarista catches that and holds sleep off through it.
When Gemini CLI finishes or goes idle, normal sleep comes back within your grace window — 90 seconds by default — no terminal tab to remember, no battery held hostage overnight.
The honest comparison: "detect the agent and keep the Mac awake" isn't a hard problem —
free tools already do a version of it. Where AgentBarista is different from caffeinate
or Amphetamine: it turns off by itself when Gemini CLI stops, so you're not manually starting and
stopping it every session and you're not at risk of leaving it on and draining your battery
overnight. It also has an emergency restore if anything gets stuck, and it shows you how much time
it actually kept a run from being interrupted.
Founding price $15 for the first 200 customers.
Same Mac-goes-to-sleep problem, different tool. Each of these guides covers the fix for that agent specifically: