Let your AI agents
work while you sleep.
Midnight Oil keeps your Mac awake so Claude Code, Codex, and Cursor can finish the job. Overnight, while you run an errand, even with the lid closed in your bag.
0 stars on GitHubmacOS 14 or later · Apple Silicon and Intel · Notarized by Apple · brew install --cask coreyhaines31/tap/midnightoil
Install Midnight Oil, a free macOS menu bar app that keeps my Mac awake (https://github.com/coreyhaines31/midnightoil): 1. Check this Mac runs macOS 14 or later with `sw_vers -productVersion`. Stop and tell me if it doesn't. 2. If Homebrew is installed (`command -v brew`), run `brew install --cask coreyhaines31/tap/midnightoil`. 3. Otherwise, download the latest release and copy it to Applications: url=$(curl -fsSL https://api.github.com/repos/coreyhaines31/midnightoil/releases/latest | grep -o 'https://[^"]*\.dmg' | head -1) curl -fsSL -o /tmp/MidnightOil.dmg "$url" mnt=$(hdiutil attach -nobrowse -readonly /tmp/MidnightOil.dmg | grep -o '/Volumes/.*' | tail -1) cp -R "$mnt/Midnight Oil.app" /Applications/ && hdiutil detach -quiet "$mnt" && rm /tmp/MidnightOil.dmg 4. Run `open -a "Midnight Oil"`, then confirm it's running with `pgrep -x "Midnight Oil"`. 5. Tell me to look for the flame icon in my menu bar, that closed-lid mode needs a one-time approval in Settings › Closed Lid, and that from now on I can just ask you to keep my Mac awake. You'll do it with the `midnightoil` command (see `midnightoil --help`; if it isn't on the PATH, it's at "/Applications/Midnight Oil.app/Contents/MacOS/midnightoil").
11:04 PM. You went to bed.
The migration didn't.
Midnight Oil holds the Mac awake through the night while the agent works, then hands it back at seven.
Last login: Tue Sep 29 22:58:41 on ttys003 ~/code/app $ claude ╭─ Claude Code · billing-migration ─────────────────────╮ 23:04 › Migrate the billing service off the legacy API. Run the full suite after each step. 23:05 Reading 41 files in services/billing… 23:09 Plan: 6 steps, each gated on the suite. Starting with the Invoice client. 23:31 Step 1/6 — replaced Invoice client ✓ 212 tests passing 23:52 Fixed 3 flaky assertions in invoice_spec ✓ 00:14 Step 2/6 — rewrote webhook handlers ✓ 212 tests passing 01:02 Step 3/6 — customer sync (retry after rate limit) ✓ 01:49 Step 4/6 — removed legacy adapter ✓ 198 tests passing, 14 skipped 02:37 Step 5/6 — updated fixtures and docs ✓ 212 tests passing 02:58 Removed 1,180 lines, added 640. No behavior changes outside billing. 03:11 Step 6/6 — opening pull request… 03:12 Running the full suite one more time
Your Mac sleeps.
Your agents stop.
macOS puts a Mac to sleep after a few idle minutes, and an agent that's mid-task doesn't count as activity. The terminal freezes, the SSH session drops, and you come back to half a job. Midnight Oil fixes that, whichever way you work.
Start the run at 11. Wake up to a finished PR.
Set “Keep awake until 7 AM” before bed. The refactor, the migration, the 400 test fixes: done while you sleep, and your Mac goes back to normal at seven.
Step out for forty minutes. It keeps going.
Lunch, the school run, a workout. Tie the session to Terminal or Cursor and walk away. When the agent's app quits, the session ends on its own.
Lid closed, in the bag, still working.
Check “Stay awake with lid closed,” shut the laptop, and get on the train. The agent doesn't notice. If you're on battery, an alarm tells you it's still running.
Work hours, every week
Schedules keep your Mac awake at the same times every week: 9 to 5 on weekdays, or every night while your agents run. Add “only while plugged in” and it pauses when you unplug, then picks back up. Taking a day off? Skip it from the menu.
Lid closed, still working
Shut the laptop, put it in your bag, get on the train. The agent keeps going, and the screen locks as you close it unless you're docked to a monitor. Normal sleep comes back the moment the session ends.
Overnight, or until it's done
Keep awake until 7 AM, for 8 hours, as long as Terminal is running, or until a download finishes. Extend a session without restarting it. When the app quits, your Mac goes back to normal.
Won't cook your laptop
End sessions when you unplug or when the battery drops below a level you choose. An alarm sounds if the lid closes on battery, and if a closed Mac gets hot, it's allowed to sleep and cool down, with closed-lid mode back on once it wakes.
Know what it did
How many hours your Mac worked while you were away, this week and all time, and what started each session.
Always on at your desk
Triggers keep your Mac awake on their own while conditions hold: docked to a display, on power, on your office Wi-Fi, or while Terminal or Cursor is open. Set them once and stop thinking about it.
Drives stay spun up
Some external drives nod off after a few idle minutes and stall whatever is writing to them. Drive Alive keeps the ones you pick awake.
And the small stuff, done right.
Until the download's done
Pick the file. The session ends when it finishes.
Hot keys and Control Center
Start or end a session from any app, or from Control Center on macOS 26.
Starts with your Mac
Launches at login, and can start a session right away if you want.
Cmd-drag the icon
It moves like every other menu bar icon. Amphetamine's doesn't.
Your own icon
Swap in your own menu bar images for on and off.
Notifications you control
Hear when a session ends or a schedule starts, with the sound you pick.
Export your history
Every session, with away time and what ended it, as a CSV.
Updates itself
Signed and notarized by Apple. New versions install when it quits.
Explains itself
Every setting has an ⓘ. Hover for a hint, click for the full story.
Three clicks, then walk away.
Or don't click at all.
Just tell your agent.
Midnight Oil comes with a midnightoil command, so Claude Code, Codex, and Cursor can keep your Mac awake for you. Ask in plain words. Your Mac stays awake for exactly as long as the work takes, lid closed included, then sleeps again on its own.
- “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
› Run the billing migration. Keep my Mac awake until it's done, I'm closing the lid. ⏺ Bash(midnightoil run --lid-closed -- npm run migrate) ⎿ Keeping your Mac awake: While “npm” runs Stays awake with the lid closed Migrating 1,284 invoices… (running) ⏺ Running. Your Mac stays awake until it's done, lid closed or not, then sleeps as usual.
The other ways to do this, honestly compared.
You can keep a Mac awake for free without any app. Here's what you give up. Deeper comparisons: Amphetamine, Caffeine, caffeinate, KeepingYouAwake, mouse jigglers.
| Midnight Oil | System Settings | caffeinate | Amphetamine | |
|---|---|---|---|---|
| One click to start, one to stop | Yes | Buried in Battery › Options | Type a command, remember to kill it | Yes |
| Timed and “until” sessions | Yes | No | Yes-t seconds, do the math | Yes |
| Ends when the agent's app quits | Yes | No | Only for one process | Yes |
| Works from the terminal | Yesmidnightoil run -- your-agent | No | Yes | AppleScript only |
| Keeps working with the lid closed | Yesrestores sleep automatically | Only on a display and power | No | Yesneeds a separate script download |
| Schedules (work hours, overnight) | Yeswith conditions like “only while plugged in” | No | No | Via a trigger |
| Triggers (Wi-Fi, display, app, schedule…) | Yes | No | No | Yes |
| Battery safety and lid alarm | Yesplus screen lock and a heat pause | No | No | Yes |
| Still maintained | Yes | Yes | Yes | Last update 2023 |
| Source code public | YesFSL, MIT after 2 years | No | No | No |
| Price | Free | Free | Free | Free |
Safe by design.
Keeping a laptop awake with the lid shut is the one thing macOS won't let a normal app do. Here's how Midnight Oil does it without ever leaving your Mac stuck awake.
A helper you approve once
macOS asks you to allow it in System Settings. It runs Apple's own pmset command and accepts instructions only from the signed Midnight Oil app.
Sleep always comes back
When the session ends, when the app quits, and even if the app crashes. The helper notices the dropped connection within a second and restores normal sleep.
Even if the helper dies
macOS restarts it, and the first thing it does on launch is restore sleep. Nothing is ever left disabled behind your back.
Free. Really.
No account, no subscription, no trial, no ads, no telemetry. Use it at home or at work, and read every line of how it works.
Why it exists. I run coding agents all day and let them keep going overnight. My Mac kept falling asleep on them, and Amphetamine, the app everyone used for this, hasn't been updated since 2023. So I built the replacement I wanted, and made it free.
Corey Haines, maker of Midnight OilQuestions
Which AI agents does it work with?
All of them. Midnight Oil keeps the Mac itself awake, so it doesn't matter what's running: Claude Code, Codex, Cursor, a cron job, a render, or a download. Tie a session to the app that runs your agent and it ends when that app quits.
Can I just tell my agent to keep my Mac awake?
Yes. Ask Claude Code, Codex, or Cursor something like “keep my Mac awake until the migration's done, I'm closing the lid.” It runs the midnightoil command that comes with the app, and your Mac stays awake until the job finishes. Add one line to CLAUDE.md or AGENTS.md and it does this for every long job without being asked. How it works.
Is it really free?
Yes, at home or at work. The whole source is on GitHub. No account, no subscription, no telemetry.
Can it stay awake only during work hours?
Yes. Add a schedule like Monday to Friday, 9 to 5, and your Mac stays awake during those hours every week. Add “only while plugged in” and it pauses when you unplug and picks back up when you plug in. Taking a day off? Skip it from the menu.
Won't it drain my battery?
No. On battery, sessions end on their own below 10%, so the Mac can sleep before it runs flat. Change the level or end sessions when you unplug in Settings. Plugged in, there's nothing to worry about.
Which Macs does it run on?
Apple Silicon and Intel Macs running macOS 14 Sonoma or later.
How is this different from Amphetamine?
Same idea, and everything Amphetamine could do is here. Amphetamine stopped being updated in 2023; Midnight Oil is maintained, its source is on GitHub, and you can drag its icon around the menu bar.
Does it update itself?
Yes. The app is signed and notarized by Apple, and checks for updates on its own. You can turn that off in General settings.
Does it keep the screen on too?
Only if you want it to. “Allow display sleep” keeps the Mac awake but lets the screen turn off, which is usually what you want for an overnight run.
What if I close the lid and forget it's running?
On battery, an alarm sounds when the lid closes during a closed-lid session, and the session ends below 10% battery so the Mac can sleep. On power, it just keeps working.
Does it need admin rights?
Only closed-lid mode does, and only once: you approve its helper in System Settings › Login Items. Everything else runs as a normal app.
Where do I report a bug or ask for a feature?
GitHub Issues. Pull requests are welcome too.
Give your agents the night shift.
Free. No account, no subscription.
macOS 14 or later · Apple Silicon and Intel · Notarized by Apple