Keep your Mac awake during long Claude Code and Codex runs

A long agent run can die when your Mac sleeps. Here are three ways to keep it awake, from the Terminal to one click in the menu bar.

PeekyMac team · · 2 min read

PeekyMac productivity settings with Stay Awake options

Part 4 of 5 in our AI coding on Mac series.

You start a long Claude Code or Codex task, walk away, and come back to find your Mac asleep and the run stalled. macOS sleeps the display and, on battery, the whole Mac when it thinks you are idle.

Option 1: caffeinate in Terminal

macOS includes a command for this:

caffeinate -dimsu

It keeps your Mac awake until you press Control-C. Add -t 3600 to stop after an hour. It works, but it ties up a terminal window and is easy to forget.

Option 2: Energy settings

You can stop the display from sleeping in System Settings → Lock Screen and Displays, but that changes it for everything, all the time.

Option 3: Stay Awake in the menu bar

PeekyMac's Stay Awake keeps your Mac awake for a set time, then lets it sleep normally:

  1. Choose Stay Awake in the PeekyMac menu and pick a duration, or no limit.
  2. Running long? Choose Extend +10 min, or tap +30 min on the Quick controls widget.
  3. When the time is up, you get a notification and your Mac goes back to normal.

You can also toggle it with Option-click on the menu bar icon or a keyboard shortcut, and the Today view counts how long Stay Awake ran.

Tips for long runs

  • Plug in. Some Macs still sleep on low battery.
  • Pair it with Continue at reset (Part 2) so a run that hits its limit picks up again without you.
  • Use the Needs you widget so you see at a glance if an agent is waiting for an answer.

FAQ

Does Stay Awake keep my Mac awake when the lid is closed? No. Closing the lid sleeps most Macs unless an external display is connected.

Will it drain my battery? It keeps the Mac awake, so plan for that on battery.

Can I lock the screen while it runs? Yes. You can let the display sleep while the Mac stays awake.

The AI coding on Mac series

  1. Claude Code usage limits explained: the 5-hour and weekly windows
  2. Hit your Claude Code limit? Continue the session at the reset
  3. How to track your Codex usage limits on a Mac
  4. Keep your Mac awake during long Claude Code and Codex runs (you are here)
  5. Desktop widgets for AI coding: limits, sessions and approvals at a glance

PeekyMac is free for 7 days, no card needed. Download PeekyMac

PeekyMac team

Writes about PeekyMac, Mac productivity and AI coding tools.