How do I keep my Mac awake while Claude Code works
On this page
  1. Does Claude Code keep the Mac awake by itself?
  2. How do I keep a Mac awake for one session?
  3. What about closing the lid?
  4. How do I do the same on Linux and Windows?
  5. What goes wrong with this by hand?
  6. Where does Joxo fit?
  7. Frequently asked questions
  8. Does caffeinate need administrator rights?
  9. Will my Mac still lock the screen?
  10. Can I keep an agent running after I close the laptop and leave?
  11. Does keeping the computer awake use my AI plan faster?
  12. Try it with your team

Guides

How do I keep my Mac awake while Claude Code works?

Keep a computer awake for a long Claude Code or Codex run: caffeinate on macOS, systemd-inhibit on Linux, Windows power settings, and what a closed lid does.

Start the agent through caffeinate: caffeinate -i claude keeps a Mac from idle sleep for as long as that session runs, then lets go by itself. Add -s to stay awake on mains power with the display off. A closed MacBook lid still sleeps unless the Mac is on power with an external display attached. On Linux, systemd-inhibit does the same job, and on Windows a power plan or PowerToys Awake does.

A sleeping computer does not lose your code, but it stops the work. A Claude Code session waiting on a test run, or a Codex task halfway through a refactor, simply pauses until someone wakes the machine, and a network call that was open when it slept may fail.

Does Claude Code keep the Mac awake by itself?#

Partly. While a session is actively working on macOS, Claude Code holds off idle sleep with short caffeinate -i runs (a feature request to make this optional describes the behaviour). That covers the time it is busy, not necessarily the hours a finished session or an unanswered question sits waiting for you, and it is not a documented setting you can rely on. Other agents behave differently, and a closed lid is a separate question.

How do I keep a Mac awake for one session?#

caffeinate ships with macOS. Wrap the agent in it:

bash
caffeinate -i claude
caffeinate -i codex
FlagWhat it prevents
-iIdle sleep of the system. The display can still turn off.
-sSystem sleep, only while on mains power.
-dThe display sleeping. Rarely needed for an agent.
-mThe disk idling.
-t 3600Ends the hold after 3600 seconds, whatever the process does.

caffeinate -i alone, with no command, holds until you press Control-C. To hold the machine while a session you already started keeps running, give it the process ID: caffeinate -i -w <pid>.

What about closing the lid?#

A MacBook normally sleeps when its lid closes, and caffeinate -i is not a reliable way to stop that. Clamshell mode is the supported way to run with the lid shut: the Mac on power, with an external display and a keyboard or mouse attached. Forcing sleep off entirely with sudo pmset -a disablesleep 1 works, but a laptop in a bag that never sleeps gets hot and drains its battery; turn it back with sudo pmset -a disablesleep 0.

How do I do the same on Linux and Windows?#

Linux. With systemd, run the agent under an inhibitor lock:

bash
systemd-inhibit --what=idle:sleep --why="agent run" claude

The lid switch is set separately, in HandleLidSwitch in /etc/systemd/logind.conf.

Windows. In Settings, under Power, set sleep to Never while plugged in, or use the Awake tool in Microsoft PowerToys to hold the machine awake for a set time. powercfg /requests shows what is currently keeping the computer awake.

What goes wrong with this by hand?#

  • It covers one session. A wrapper on one terminal does nothing for the second agent you started in another window, or for one a teammate's agent woke.
  • It ends too early or too late. A timer guesses how long the work takes. Wrapping the process holds for as long as the session stays open, so a session that finished hours ago keeps the machine awake until you quit it.
  • Batteries run flat. A machine held awake on battery overnight can be empty by morning, and then nothing runs.

The rule worth keeping: stay awake while any agent has work, let go when they are all done, and never hold a laptop on a low battery.

Where does Joxo fit?#

Joxo's desktop app, for macOS, Windows and Linux, has a keep-awake cup in the menu bar. It keeps the computer awake while your agents work, can last until they finish, and lets go when the battery runs low. It holds the whole computer, not one terminal, so every agent on it keeps working. The desktop app page lists what else it does, and the download page has the installers.

Frequently asked questions#

Does caffeinate need administrator rights?#

No. caffeinate runs as your user and holds an assertion only while it runs. Only pmset changes need sudo.

Will my Mac still lock the screen?#

Yes, with caffeinate -i. The display sleeps and the screen locks on your usual schedule, while the system keeps running. Use -d only if you need the display on.

Can I keep an agent running after I close the laptop and leave?#

Only in clamshell mode, or by running the agent on another computer: a desktop at home, a server, or a cloud session. A sleeping laptop in a bag runs nothing.

Does keeping the computer awake use my AI plan faster?#

No. Staying awake only lets work that was already running finish. Usage comes from what the agent does, not from how long the computer is on.