👁1views
Keep Your Mac Awake While Claude Code Works

CloudScale AI SEO - Article Summary
  • 1.
    What it is
    Keeping your Mac awake during Claude Code sessions requires a few proven system-level fixes — covering caffeinate flags, remote control mode risks, and Energy Saver settings.
  • 2.
    Why it matters
    An unexpected sleep mid-session kills active Claude Code tasks instantly, making sleep prevention essential for reliable agentic workflows and complex browser automation runs.
  • 3.
    Key takeaway
    Wrap every Claude Code session with `caffeinate -dims claude` to prevent Mac sleep automatically — no manual cleanup required.

If you run Claude Code in its default local mode, your Mac will happily fall asleep mid-task, killing the session and whatever was being built. The fix is simple, but it is worth knowing about before it bites you.

1. The quickest solution: caffeinate

macOS ships with a utility called caffeinate that prevents sleep for as long as it runs. The most surgical use is to wrap Claude Code directly:

caffeinate -dims claude

The flags break down as: -d keeps the display on, -i prevents idle sleep, -m prevents disk sleep, and -s prevents system sleep when on AC power. This way your Mac returns to normal behaviour the moment the Claude Code session ends.

If you want the protection to persist independently, just run caffeinate -dims in a separate terminal tab and kill it manually when you are done.

2. Remote control mode changes the picture

Claude Code has a remote control / computer use mode where it can drive your browser and desktop applications directly. In this mode, the stakes of an unexpected sleep are even higher because Claude may be mid-way through a multi-step browser workflow when the machine goes dark. The caffeinate -dims wrapper is non-negotiable here rather than just convenient.

3. System Settings as a fallback

If you prefer a persistent change, go to System Settings → Energy Saver (or Displays → Advanced on newer macOS versions) and set the inactivity timer to Never while you are in a heavy Claude Code session. Just remember to reset it afterwards if you are on a laptop and care about battery longevity.

4. Battery note

macOS can override sleep settings when running on battery even if you have set them manually. Plugging into power removes that constraint and is generally advisable for long agentic runs anyway, since Claude Code sessions can be surprisingly CPU intensive.