Keep your PC awake while AI coding agents run
AI coding agents like Claude Code, Codex and Cursor's agent can work for an hour or more on their own. That only helps if the PC is still running when you come back. On Windows it often isn't: the PC went to sleep, the agent's connection dropped, and the run stopped halfway.
Why agent runs stop
- Windows doesn't see the agent as activity. It decides you've left based on the keyboard and mouse. A terminal busy with an agent doesn't count, so the PC sleeps after the usual idle time.
- Sleep freezes everything. The agent process pauses, and its connection to the AI service times out. When the PC wakes, the session has often failed or needs restarting.
- Closing a laptop lid sleeps it straight away, which is how most laptop runs end.
A dark screen or a locked PC is fine: the agent keeps running. Only sleep stops it.
What to do
- Keep the PC awake for the length of the run, not forever. A keep-awake app or the PowerShell one-liner in the caffeinate for Windows guide does this and lets Windows sleep normally afterwards.
- Plug in a laptop. Agents keep the CPU and network busy, and a long run on battery can end with a flat laptop.
- Let the screen turn off. You don't need it on; it only uses power.
- To close the lid, the lid action has to be "Do nothing" while the agent runs. See keeping a laptop running with the lid closed, and keep it on a desk, not in a bag.
- Give the agent the permissions it needs before you leave. A run that stops to ask "may I run this command?" waits for you either way.
Check it's working
With your keep-awake method running, open Command Prompt as administrator and run powercfg /requests. A keep-awake app such as Keeplit appears under SYSTEM. If the list is empty, Windows will sleep on its normal schedule.
When Windows still sleeps
No app can override choosing Sleep, pressing the power button, a critically low battery, or a policy set by your organization's IT. Keep-awake tools stop automatic sleep only.