How to Keep Windows Awake During AI Coding Sessions

2-minute setup · Free · Windows 10 / 11 · Works with Claude Code, Cursor, Aider, Codex, Ollama

The short answer: Install Insomnia — a free, open-source Windows app. It keeps your PC awake automatically while AI tools are working and lets it sleep the moment they stop. Setup takes under 2 minutes.

The Problem

You're running Claude Code on a complex refactor. You step away for 10 minutes. Your PC's sleep timeout kicks in, the process dies, and you come back to a broken session.

The naive fix — setting Windows sleep to "Never" — means your PC never sleeps when you actually want it to, wasting power and draining your battery. You want something smarter: awake while work is happening, asleep when it isn't.

The Solution: Insomnia

Insomnia is a lightweight Windows utility that uses Electron's powerSaveBlocker API to prevent Windows from sleeping. It evaluates whether to stay awake based on three signals:

When all signals are inactive, the sleep lock is released and Windows behaves normally.

Step 1 — Install Insomnia

Option A

Direct download

Head to GitHub Releases and download Insomnia.Setup.x.x.x.exe. Run the installer — it takes about 10 seconds.

Option B

winget (Windows Package Manager)

winget install StanleyProjects.Insomnia
Option C

Scoop

# Add the bucket once scoop bucket add stanley-projects https://github.com/stanley-projects/scoop-stanley
scoop install stanley-projects/insomnia

Step 2 — Add a Trigger

Open Insomnia from the system tray (or Start Menu). Click + Add in the main window.

For AI coding tools — use Integrations

Go to the Integrations tab and enable the tool you use:

Tool Detection What it does
Claude Code Smart Awake while Claude is running tools; idle for 3 min = asleep
Cursor Smart Awake while Cursor Agent is actively working; idle for 3 min = asleep
OpenAI Codex Smart Dual-path: CLI notify hook + session transcript polling
Aider Process Awake while aider.exe is running; 30s grace after it closes
Ollama Process Awake while Ollama is running local model inference

For presentations, renders, downloads — use Apps

Go to the Apps tab. Insomnia auto-discovers every installed app on your system. Search for it and click to add. The PC stays awake while that app runs, and sleeps normally when it closes.

For instant, on-demand sleep prevention

Use the Keep Awake toggle in the main window. Flip it on — PC stays awake. Flip it off — PC sleeps normally. Perfect for presentations. Setting persists across restarts.

Step 3 — Watch the Tray Icon

Insomnia lives in your system tray:

Right-click the tray icon for a quick toggle or to open the main window. Close the window to minimize to tray — Insomnia keeps running.

How the Claude Code Integration Works (Details)

When you enable Claude Code, Insomnia adds hooks to ~/.claude/settings.json that fire on:

This means Insomnia knows precisely when Claude is reading files, running commands, and writing code — and when it's just sitting idle waiting for your next prompt. Your PC only stays awake while work is actually happening.

How the Cursor Integration Works (Details)

Cursor writes ~/.cursor/projects/*/agent-transcripts/**/*.jsonl files during active Agent sessions. Insomnia polls these files every 5 seconds. If any transcript file changes in size or modification time, it means Cursor Agent is actively working — and the sleep lock is applied. When the files stop changing, the sleep lock is released within 3 minutes.

Alternatives (and why Insomnia is better)

ApproachDrawback
Windows power settings → "Never sleep" PC never sleeps, even when idle. Wastes power, drains battery.
Screen saver disabled manually Still sleeps when the system timer fires. Not targeted.
powercfg /change /standby-timeout-ac 0 System-wide change. Affects all programs, all the time.
Insomnia Targeted: awake only when your trigger is active. Automatic release when done.

Use Cases

↓ Download Insomnia — Free

Windows 10/11 · MIT License · No accounts

how to keep windows awake · prevent windows from sleeping · stop pc from sleeping · keep windows 11 awake · prevent sleep during claude code · keep pc on during ai coding · windows caffeine alternative · sleep prevention windows · powerSaveBlocker windows · prevent idle sleep windows · keep display on windows 11 · stay awake windows · disable sleep windows programmatically