Guide · Updated October 2, 2026 · 6 min read

Keep Your Mac Awake and Locked at the Same Time

You're about to step away while something long-running finishes: a big download, a video export, a test suite, a Claude Code or Codex session. You want the Mac locked, because leaving it open is asking for trouble. But you also don't want it to fall asleep and pause everything.

The good news: those two goals don't conflict. The key fact most people miss is this — locking a Mac does not stop your work. Sleep does. Programs keep running behind the lock screen exactly as before. So the real task is: lock the Mac, and separately stop it from sleeping. Here's how, starting with the free, built-in ways.

Step 1: Lock the Mac

Press ⌃⌘Q (Control-Command-Q), or choose Apple menu → Lock Screen. On a Mac with Touch ID you can also set the Touch ID button to lock the screen. Your apps, terminals and downloads keep running.

Step 2: Stop it from sleeping

Option A: caffeinate (built in, free)

macOS ships with a command-line tool called caffeinate that keeps the Mac awake for as long as it runs. Open Terminal and use one of these:

  • caffeinate -i — prevent idle system sleep until you press ⌃C. The display may still turn off, which is fine for background work.
  • caffeinate -d — also keep the display from sleeping.
  • caffeinate -i -t 7200 — stay awake for 7,200 seconds (two hours), then return to normal.
  • caffeinate -i your-command — stay awake exactly as long as your-command runs, e.g. caffeinate -i npm test.
  • caffeinate -w 12345 — stay awake until the process with PID 12345 exits. Handy for a job that's already running.

Start caffeinate, then lock with ⌃⌘Q. This is the cleanest free answer for most people. Whether the display stays lit on the lock screen depends on your macOS version and settings; either way, your processes keep running.

Option B: Energy / Battery settings (built in, free)

On a MacBook, go to System Settings → Battery → Options and turn on "Prevent automatic sleeping on power adapter when the display is off". On a desktop Mac, the equivalent options live under System Settings → Energy. This is a permanent setting rather than a per-session one, so remember it's on. It only applies while you're plugged in — which you should be for any long job anyway.

Option C: a free menu bar app

If you don't want to open Terminal, free apps like Amphetamine (Mac App Store) and the open-source KeepingYouAwake put the same "stay awake" switch in your menu bar, with timers and conditions. They work alongside the normal lock screen.

The lid problem

Closing a MacBook lid normally puts it to sleep, regardless of caffeinate. The supported exception is clamshell mode: connect power and an external display (plus an external keyboard or mouse), and the Mac can keep running with the lid closed. Some third-party apps offer to override lid-close sleep, but watch temperatures if you go that way — a closed laptop cools less effectively. The simplest advice: leave the lid open.

When you also want to see the screen

Everything above has one trade-off: the macOS lock screen hides your work. You can't glance over from the coffee machine to check whether the build failed or whether the agent is waiting for an answer. Some workarounds people use:

  • Check remotely. SSH in from a phone, or have your job send a notification when it finishes. Free, and works from anywhere — but you have to set it up.
  • Leave it unlocked. The most common choice and the worst one. An unlocked Mac with a terminal open gives anyone who sits down full access to your files, repos and accounts. We wrote about that in the unlocked laptop problem.

This "locked but still visible" gap is why we built VibeLock. While it's locked:

  • the apps you choose (your terminal, Claude desktop, VS Code…) stay on screen, and everything else is hidden;
  • all key presses, clicks, drags and scrolls are blocked, including Spotlight, Force Quit and ⌘Q;
  • the display is kept awake with a macOS power assertion, which also keeps the Mac from idling to sleep;
  • unlocking needs Touch ID or your Mac login password, checked locally.

It has honest limits. Anyone walking past can read what your visible apps show, so don't leave secrets on screen. It doesn't stop lid-close sleep. And it isn't as hard to get around as the real macOS lock screen for someone with time and remote access — the full list is on the security model page. For a quick coffee run in an office or café, it's the difference between "anyone can type into my terminal" and "everyone can only watch."

Quick recipes

GoalDo this
Long download or build, don't need to watchcaffeinate -i + ⌃⌘Q
Stay awake only while one command runscaffeinate -i <command> + ⌃⌘Q
Always stay awake on powerBattery → Options / Energy settings
No Terminal, menu bar switchAmphetamine or KeepingYouAwake (free)
Locked, awake and screen visibleVibeLock ($10)

Leaving an AI agent running specifically? See how to leave Claude Code running while you're away.

More guides