Skip to content
Technology

How to Stop Your Computer From Sleeping While AI Works

Webstarted Academy ·

You ask Claude Code for a two-hour task, go grab lunch, and when you come back everything has stopped. The agent did not fail: the computer went to sleep. It happens with Codex, with any agent that works on your machine, and with a big download or a long build too.

We fix it with one click: Keep Awake, part of Toolbox, our free menu bar app for Mac and Windows. Tell it “while claude runs” and the computer will not sleep while Claude Code is open. Further down you will also find the options that come with Mac and Windows, in case you would rather not install anything.

The simplest way: Keep Awake in Toolbox

Toolbox Keep Awake set to "While a process runs" with claude, next to a terminal where Claude Code is working

Keep Awake lives in your menu bar, inside Toolbox: click the coffee cup, pick anything from 30 minutes to 8 hours, your own length or “Until turned off”, and watch the countdown. When it ends, it lets go on its own.

For working with AI, the option we use most is under Condition: While a process runs. Type the name of a process (for example, claude) and the computer stays awake only while that process is alive. When that process closes, Keep Awake stops holding off sleep and the machine goes back to its usual settings. Note that the process is what counts, not the task: if Claude Code stays open waiting for your next request, the machine stays awake until you close it. It is the idea behind caffeinate -i claude, without Terminal and on Windows too.

Two more options that help:

  • Only when plugged in: pauses it when the machine switches to battery and resumes when you plug it back in (the timer keeps counting while paused).
  • Screens: Turn off and lock: after 5 to 30 minutes without input, it locks the session and turns off the screens, while the computer keeps working.

If you want every way to keep the machine awake while you are away, with pros and cons, there is this guide: keep your computer awake while you’re away.

Get Toolbox free, for Mac and Windows →

Why it stops: sleep is not turning off the screen

  • Turning off the screen saves power and stops nothing: the agent keeps working.
  • Locking your session stops nothing either: programs keep running behind the lock screen. That said, a locked computer that nobody touches will still go to sleep when its timer runs out.
  • Sleep is different: the computer stops running programs until you wake it, and connections can drop. Some tasks pick up again when it wakes and others have to start over.

This applies to whatever runs on your own computer. What you want to avoid is sleep. The screen can turn off, and it should if you step away.

A note on laptops: closing the lid can put it to sleep even if you prevented idle sleep (on Windows it depends on your lid setting). If you are leaving a laptop to work, leave it open and plugged in.

Nothing to install on a Mac: caffeinate

macOS ships with a command for this. Open the Terminal app and type:

caffeinate -i

As long as that window stays open, the Mac will not idle sleep. Press Control-C, or close the window, and it lets go. If you also want the display on, use caffeinate -i -d, and -t sets a limit in seconds (caffeinate -i -t 7200 is two hours).

The trick we use most with AI is putting it in front of another command. That way the Mac stays awake exactly as long as that command runs:

caffeinate -i claude

That opens Claude Code, and the Mac will not sleep until you close that session. The same works for a build (caffeinate -i npm run build) or any long command. If the process is already running, caffeinate -i -w 12345 waits for it to finish, replacing 12345 with its process number (the PID, shown in Activity Monitor).

There is also a permanent setting: in System Settings, under Battery and then Options (on a desktop Mac, under Energy), you can stop it from sleeping on its own while plugged in with the display off. It suits a machine that is always working; for a one-off task we prefer something that lets go on its own.

Nothing to install on Windows: power settings, powercfg or PowerToys Awake

Windows has no caffeinate. It has two built-in options, and Microsoft offers a third one you install separately:

  • Power settings. On Windows 11, in Settings, System, Power & battery (names can vary a little between versions), under the screen and sleep timeouts: set sleep to “Never” while plugged in. It works, but it stays that way until you remember to change it back.
  • From a terminal. powercfg /change standby-timeout-ac 0 does the same while plugged in (0 means “never”). To undo it, run the same command with the minutes you had before, for example 30.
  • PowerToys Awake. PowerToys is a free Microsoft utility pack, and Awake keeps your PC awake from the system tray: indefinitely, for a while, or until a date and time. If you only use Windows and already have PowerToys, it is a very good choice.

More detail, with screenshots, in how to stop Windows from going to sleep.

What to use when

Situation Simplest option
You use Mac and Windows, or would rather not open Terminal Keep Awake, with “While a process runs”
An agent or a build on a Mac, and you are comfortable with Terminal caffeinate -i in front of the command
You only use Windows and already have PowerToys PowerToys Awake
A machine that always has to be working The power setting, knowing it stays put

Three precautions

  • Lock your session when you step away. An awake, unlocked computer is an open door. On a Mac, Control + Command + Q; on Windows, Windows + L. The agent keeps working either way.
  • Watch the battery. An hours-long task can drain it. For long jobs, stay plugged in.
  • Check what the agent can do. Before leaving it to work unattended, check which files it can change and which actions it is allowed to take, and keep it inside the project folder. We explain how that works in how to use Claude Code.

Keep going

If you are just starting to hand tasks over to AI, in AI for your everyday work we build a workflow around real tasks, no coding required. And if you want your assistant to do more on its own, the next step is giving it tools: we cover that in MCP servers.

Looking for your first job in tech? Every week we hand-check junior and trainee openings in LATAM at Junior Jobs, and internships have their own list.

Workshops on this

Did you like it? Receive more content like this in your email.

Join the newsletter