You know that feeling when you come back to your desk and your Claude Code session is just gone?
Not crashed. Not errored. Just a blank terminal because Windows put the machine to sleep while you were away.
It happened to me too many times. So I built something to fix it.
The Problem
Windows has a sleep timer. By default it kicks in after 10 or 15 minutes of no user input. The problem is that AI coding agents don't count as user input. You're not moving the mouse or typing. Claude Code is reading files, writing code, running tools in the background, and Windows has no idea anything is happening.
You lose your session, your context, sometimes your terminal state. If you kicked off a long agentic run and stepped away, that's genuinely painful.
The obvious fix is to disable sleep in Power Settings. But then you have to remember to turn it back on, and I never do. Laptop running hot at 3am for no reason.
What I wanted was something that keeps the machine awake while work is happening and backs off when it isn't.
What I Built
Insomnia is a small Windows tray app. It watches for AI coding activity and prevents Windows from sleeping. When activity stops, it releases. That's it.
No scheduled tasks. No registry edits. No "set sleep to Never."
How It Works
Three modes, all running at the same time if you want:
- Claude Code Hook Integration
Claude Code has a hooks system that fires shell commands on lifecycle events. Insomnia registers as a hook handler for:
PreToolUse and PostToolUse — Claude is using a tool
UserPromptSubmit — you sent a message
PermissionRequest — Claude is waiting for your approval
Notification — Claude is surfacing something
When any of these fire, Insomnia activates. When they stop, it releases. No polling, no guessing, responds to the actual lifecycle of the agent.
- Process Watching
For tools without a hooks API, Insomnia watches the process list. Cursor, Aider, Ollama, OpenAI Codex — if any of them are running, your PC stays awake. When they close, it backs off.
- Manual Toggle
One switch for when you just need the PC awake right now. Toggle it off when you're done.
The Tray Icon
Purple owl means awake. Grey owl means idle. Hover and it tells you why: "Staying awake for Claude Code." You always know what state you're in.
Stack
Electron, zero npm dependencies. Free, MIT licensed, Windows only.
Install
Direct download: Releases page Releases page
Scoop:
scoop bucket add stanley-projects https://github.com/stanley-projects/scoop-stanley
scoop install stanley-projects/insomnia
winget: submission pending, coming soon.
Enable the Claude Code integration inside the app and it wires up the hooks automatically. No manual config needed.
It also works for Cursor, Codex.. etc
Links
GitHub: github.com/stanley-projects/Insomnia
Landing page: stanley-projects.github.io/Insomnia
Stars and feedback welcome.
Top comments (0)