❝ Nico

Notes

How to keep Claude Code running 24/7 on a Mac

Three separate things have to stay alive: the session, the Mac, and the work itself. What each one needs, and the one most guides never mention.

Three things have to stay alive, and most guides only cover one. Start the work with claude --bg so a supervisor process owns it instead of your terminal. Stop the Mac sleeping with caffeinate -s on mains power. Then give the work itself a folder and a schedule, because a session is not a home.

The three layers, in order

  1. The session. Run claude --bg "your task", or press /bg inside a session you have already started. Anthropic's own documentation is flat about what that buys: "Background sessions don't need any terminal open to keep working. A separate supervisor process runs them, so you can close agent view, close your shell, or start a new interactive session and your dispatched work keeps going."
  2. The machine. A backgrounded session still stops when the Mac sleeps. caffeinate -s holds a system-sleep assertion for as long as it runs, and caffeinate -s claude --bg "…" holds it only for the life of that command.
  3. The work. This is the step the other guides skip. A session that stays up is not a tool that keeps running. If the job has to happen again next Tuesday, something outside the session has to own it: a folder it lives in, a place its output accumulates, and a schedule that starts it.

caffeinate, flag by flag

From man caffeinate on macOS, not from a blog. With no flags at all it prevents idle sleep and nothing else.

FlagWhat it asserts
-iPrevents the system idle-sleeping.
-sPrevents the system sleeping. Valid only while the Mac is on AC power.
-dPrevents the display sleeping.
-mPrevents the disk idle-sleeping.
-t nDrops the assertion after n seconds.
-w pidHolds the assertion until that process exits.

Two consequences worth knowing before you rely on it. -s does nothing on battery, so an unplugged laptop sleeps whatever you typed. And the lid is a separate case from idle sleep — if your plan is to shut the laptop and walk away, test that exact thing once rather than assuming the flag covers it.

If it has to run on a schedule, pick the right one

Claude Code now ships three schedulers, and they differ in the one way that matters: which of them can see the files on your Mac.

OptionRuns onNeeds the Mac onSees your local filesShortest interval
/loopYour machineYes, with the session openYes1 minute
Desktop scheduled tasksYour machineYesYes1 minute
Routines, in the cloudAnthropic's machinesNoNo — a fresh clone1 hour

So the tempting answer — put it in the cloud and stop worrying about sleep — is the one answer that cannot touch your receipts folder, your camera roll or your bank exports. For anything reading your own files, the Mac has to be awake, and that is not a limitation anyone can engineer away.

One more thing to know about /loop: tasks are scoped to the session, and recurring ones expire seven days after you create them. They fire a last time, then delete themselves. A forgotten loop is bounded on purpose, which is good design and also means /loop is not where a monthly job belongs.

What actually breaks it

  • Battery. caffeinate -s is void off mains.
  • Reboot. Nothing above survives a restart. A macOS LaunchAgent does, and it has one property cron lacks: per man launchd.plist, "Unlike cron which skips job invocations when the computer is asleep, launchd will start the job the next time the computer wakes up."
  • The seven-day expiry on recurring /loop tasks.
  • Nothing to come back to. A session that ran all night and wrote its output into the conversation has produced nothing you can open tomorrow.

That last one is the one Nico exists for. Each tool it builds gets a folder of its own outside any session, a data folder that survives every run, and ten kept versions — so the thing that ran at 3am has somewhere to have put the answer.

← All notes