Nothing derails a long file transfer, render job, or overnight process quite like your computer deciding it’s time for a nap. Sleep mode is genuinely useful for saving battery and reducing heat during idle periods, but it becomes a real problem when you need your machine to stay active and working unattended. Here’s how to prevent it on both Windows and Mac, along with quick, temporary options if you don’t want to change your permanent settings.
On Windows: Adjust Power Options
The most straightforward, permanent fix is through Windows’ built-in power settings:
- Open Control Panel, then go to Hardware and Sound > Power Options
- Click Change when the computer goes to sleep on the left-hand menu
- In the Put the computer to sleep section, set both On battery and Plugged in dropdowns to Never
- Click Save Changes
If your display still turns off or your session locks even though the PC itself hasn’t gone to sleep, head into Change advanced power settings from the same menu for more granular control over individual components.
On Windows: Use Command-Line Control (for IT Pros or Repeated Setups)
If you need to configure this quickly across multiple machines, or want scriptable control, PowerShell/Command Prompt commands work well:
powercfg /SETACVALUEINDEX SCHEME_CURRENT SUB_SLEEP STANDBYIDLE 0
powercfg /SETACTIVE SCHEME_CURRENT
These disable sleep mode for both AC and battery power. If you only need the computer to stay awake during a specific task, like an overnight process, you can also configure this through Windows Task Scheduler to apply only around that window rather than changing your permanent power settings.
On Windows: Prevent Sleep on Lid Close (Laptops)
If you’re running a task on a laptop and need to close the lid without triggering sleep, Windows has a native setting for this specifically — search for “Choose what closing the lid does” in the Start menu, and set the When I close the lid options (both On battery and Plugged in) to Do nothing. This is the standard fix for keeping background tasks, like AI coding agents or long downloads, running uninterrupted after you close the laptop.
On Mac: Adjust System Settings
On current macOS versions (Sequoia, Tahoe, and similar recent releases):
- Click the Apple menu > System Settings
- Go to Battery, then click Options
- Enable Prevent automatic sleeping on power adapter when the display is off
- If you also want to prevent sleep on battery power, look for the equivalent option under the Battery section
On older macOS versions like Monterey, the same setting lives under System Preferences > Energy Saver, where you’ll find the same “Prevent computer from sleeping automatically when the display is off” checkbox.
On Mac: Use Terminal for a Quick, Temporary Fix
If you don’t want to permanently change your settings, macOS includes a built-in command-line tool for exactly this purpose:
caffeinate -d
This keeps your Mac (and its display) awake as long as the Terminal window stays open. If you only want to prevent sleep for a set period, you can specify a duration in seconds:
caffeinate -t 3600
To stop it early, switch back to the Terminal window and press Control-C.
On Mac: Keep It Awake With the Lid Closed
If you need a MacBook to keep running a task with the lid closed, the officially supported route is clamshell mode — connecting an external monitor (or simply an external power source with the Mac plugged into power and connected to Wi-Fi) allows the machine to stay fully awake and functional with the lid shut, rather than relying on workarounds.
Third-Party Tools If You Want More Control
If you’d rather not use Terminal or PowerShell commands regularly, a few lightweight, well-established apps handle this with a simple toggle:
- Windows: Caffeine simulates a keypress periodically to prevent sleep, while Move Mouse actually nudges the cursor slightly — useful if you also need to appear “active” in chat apps like Teams or Slack.
- Mac: Amphetamine is a widely used menu bar app offering fine-grained control over sleep prevention, including triggers based on specific conditions (like a particular app running).
A Quick Consideration Before You Disable Sleep Entirely
Sleep mode exists for good reasons — it conserves battery, reduces heat buildup, and gives your system’s components periodic rest. If you’re disabling sleep permanently rather than just for a specific long task, it’s worth reverting the setting once your task finishes, particularly on a laptop, to avoid unnecessary battery wear and heat over time.
Join The Discussion
Which method do you rely on to keep your computer awake during long tasks — the built-in settings, a command-line tool, or a third-party app? Share what’s worked best for your setup, or a time a sleep interruption cost you real progress on something important. If you’re running into a specific issue getting one of these methods to work, feel free to ask — there’s a good chance someone here has hit the same snag on the same OS version.