Keep your Mac awake
while Gemini CLI works.
Google's Gemini CLI runs in your terminal, so the Mac sleeping stops it cold. Midnight Oil keeps the Mac awake for as long as Gemini works, lid closed if you like, then gets out of the way.
The short answer
Run midnightoil run --lid-closed -- gemini for a session you'll walk away from, or wrap a single prompt: midnightoil run -- gemini -p "…". Add one line to GEMINI.md and Gemini keeps the Mac awake for long commands without being asked.
Gemini CLI at a glance
| Runs where | In your terminal, on your Mac |
| Interactive | gemini |
| Unattended | gemini -p "…" runs one prompt and exits |
| Instructions file | GEMINI.md in the repo, or ~/.gemini/GEMINI.md for every project |
| Needs your Mac awake? | Yes |
What happens when your Mac sleeps mid-run
Gemini CLI is an ordinary process to macOS. When the Mac sleeps it freezes, the request to Gemini drops, and any shell command it started pauses until you wake the Mac again.
It doesn't hold the Mac awake by itself, so idle sleep and a closed lid both stop it.
Just ask Gemini CLI
With Midnight Oil installed, Gemini CLI can run the midnightoil command for you. Say it in your own words:
| You say | Gemini CLI runs |
|---|---|
| “Keep my Mac awake until you've finished. Closing the lid now.” | midnightoil start --lid-closed |
| “Run the benchmarks and keep the Mac awake for them.” | midnightoil run -- npm run bench |
| “Is anything keeping my Mac awake?” | midnightoil status |
The session shows up in the menu bar like one you started yourself, so you can see it, extend it, or end it with a click.
Make it automatic
Add this line to GEMINI.md and Gemini CLI keeps the Mac awake for every long command without being asked:
midnightoil --help for the rest.For commands that take more than a few minutes, run them through `midnightoil run -- <command>` so the Mac stays awake until they finish.
Running Gemini CLI unattended
gemini -p runs a single prompt non-interactively, so the session lasts exactly as long as the run. Pair it with --yolo only in a repo where you're happy for Gemini to run commands without asking.
midnightoil run exits with Gemini's exit code and reports on stderr, so it drops into scripts and cron jobs without changing their output.
Keep the Mac awake for the whole session
midnightoil run --lid-closed -- gemini
Or for one unattended run
midnightoil run --lid-closed -- gemini -p "write tests for every module in src/"
Lid closed, battery safe
Add --lid-closed and Gemini CLI keeps working with the laptop shut. It needs a one-time approval in Midnight Oil's Settings › Closed Lid, and normal sleep comes back the moment the session ends, even if the app quits or crashes.
On battery, sessions can end when you unplug or drop below a level you pick, and an alarm sounds if the lid closes during a closed-lid session. Add --allow-display-sleep to let the screen go dark while the Mac keeps working. The full setup is in how to run AI agents overnight.
Questions
Does Gemini CLI keep running while my Mac sleeps?
No. Sleep pauses it mid-task. Wrap the run with midnightoil run -- gemini, or ask Gemini to keep the Mac awake and it runs midnightoil start for you.
What should I add to GEMINI.md?
One line: For commands that take more than a few minutes, run them through `midnightoil run -- <command>` so the Mac stays awake until they finish. ~/.gemini/GEMINI.md covers every project.
Can I close the lid?
Yes, with --lid-closed after the one-time approval in Midnight Oil's Settings › Closed Lid. Sleep comes back on its own when the session ends.
Using another agent?
Let Gemini CLI work the night shift.
Free. No account, no subscription.
macOS 14 or later · Apple Silicon and Intel · brew install --cask coreyhaines31/tap/midnightoil