For AI agents

Just tell your agent
to keep your Mac awake.

Midnight Oil comes with a midnightoil command, so Claude Code, Codex, and Cursor can run it for you. Say what you want in plain words. Your agent turns it into a command, and your Mac stays awake for exactly as long as the work takes, even with the lid closed.

Say it however you like

Your agent works out the command. A few ways to put it:

You sayYour agent runs
“Keep my Mac awake until 7am.”midnightoil start --until 7am
“Run the tests and keep the Mac awake till they're done. I'm closing the lid.”midnightoil run --lid-closed -- npm test
“Stay awake for two hours, but let the screen go dark.”midnightoil start --for 2h --allow-display-sleep
“Is anything keeping my Mac awake?”midnightoil status
“OK, let it sleep.”midnightoil stop

Every session shows up in the menu bar like one you started yourself, so you can see what's keeping the Mac awake, extend it, or end it with a click.

Or make it automatic

Add one line to your CLAUDE.md, AGENTS.md, or Cursor rules, and your agent keeps the Mac awake for every long job without being asked:

For CLAUDE.md or AGENTS.mdYour agent reads 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.

The commands

For your agent, your scripts, or you.

midnightoil run -- <command>Runs the command and keeps the Mac awake until it finishes. Exits with the command's own status, and prints its messages to stderr so the command's output still pipes cleanly.
midnightoil startKeeps the Mac awake until you stop it. Add --for 90m, --until 6:30pm, or --while-pid 4242 to end it on its own.
midnightoil statusSays whether the Mac is being kept awake, by what, and until when. Add --json for scripts.
midnightoil stopEnds the current session, the same as End Session in the menu.

Options

--lid-closedKeep running with the lid shut. Needs the one-time helper approval in Settings › Closed Lid.
--allow-display-sleepLet the screen turn off while the Mac keeps working. Best for overnight runs.
--jsonPrint the session as JSON.

Leave an option out and your defaults from Midnight Oil's settings apply. If the app isn't running, start and run open it in the background. When two agents keep the Mac awake at once, they share one session that lasts until the last one finishes.

Why not just caffeinate?

It's built in, and for a quick job on an open laptop it's fine. It stops short where agents need it most: a closed lid, a battery running low, and several jobs at once. More in the caffeinate guide.

Midnight Oilcaffeinate
Your agent can run itYesYes
Keeps working with the lid closedYes, and sleep comes back on its ownNo
Ends on low battery or unplugYes, using your settingsNo
Clock times--until 6amSeconds only, with -t
Agents running in parallelOne shared session until the last finishesOne assertion per process
Shows it's runningFlame and countdown in the menu barNothing; check pmset -g assertions
Also a menu bar appYes, with schedules and triggersNo
InstallComes with Midnight OilBuilt in

Get the command

It comes with Midnight Oil. Install with Homebrew and it's on your PATH:

brew install --cask coreyhaines31/tap/midnightoil

Installed the app from the DMG? Link the command once:

sudo mkdir -p /usr/local/bin
sudo ln -sf "/Applications/Midnight Oil.app/Contents/MacOS/midnightoil" /usr/local/bin/midnightoil

Closed-lid mode needs a one-time approval: open Midnight Oil's Settings › Closed Lid and click Install. The full reference is in the README.

Questions

Can I ask Claude Code to keep my Mac awake?

Yes. With Midnight Oil installed, ask in plain words, like “keep my Mac awake until the migration is done, I'm closing the lid.” Claude Code runs the midnightoil command, and the Mac stays awake until the job finishes, lid closed included.

Do I have to teach my agent the commands?

No. Agents read midnightoil --help like any other command. To make it automatic, add one line to CLAUDE.md or AGENTS.md telling them to run long commands through midnightoil run.

Which agents work with it?

Any agent that can run terminal commands: Claude Code, Codex, Cursor, Gemini CLI, and the rest. You can also use the command yourself or in scripts.

How is midnightoil different from caffeinate?

Both hold the same macOS power assertion. midnightoil adds closed-lid mode, your battery safety settings, clock times like --until 6am, a countdown in the menu bar, and one shared session for agents running in parallel.

What happens if two agents keep the Mac awake at once?

They share one session, which lasts until the last command finishes. One agent finishing never lets the Mac sleep under the other.

How do I get the midnightoil command?

Install Midnight Oil with Homebrew (brew install --cask coreyhaines31/tap/midnightoil) and it's on your PATH. If you installed the app from the DMG, link it once with sudo ln -sf "/Applications/Midnight Oil.app/Contents/MacOS/midnightoil" /usr/local/bin/midnightoil.

Let your agent handle the night shift.

Free. No account, no subscription.

macOS 14 or later · Apple Silicon and Intel · brew install --cask coreyhaines31/tap/midnightoil