Keep Your Mac Awake Only While Claude Code Is Working
A claude process at the prompt is still alive, so caffeinate keeps the Mac awake all night. Here is how Glowmoth separates Working from Waiting.
GuideUpdated 7 min read
On this page
You start Claude Code on a long task, walk away, and want the Mac to sleep once the agent has finished and is just sitting at the prompt. But the claude process is still running at the prompt, so anything that keeps the Mac awake "while the process exists" keeps it awake all night.
Why "the process is running" is the wrong signal
An interactive agent such as Claude Code or Codex keeps running for as long as its terminal tab is open. When it finishes a task and waits for your next message, the process is still alive. A hold tied to process lifetime therefore can't tell working from waiting.
People who discuss this problem on Reddit suggest two better signals: the CPU use of the agent's child processes, and the modification time of the session log. Glowmoth uses the first kind: it looks at the agent's process tree for CPU use, child processes and terminal writes. It does not read Claude Code's session log or any prompts.
| Approach | Signal | At the prompt |
|---|---|---|
caffeinate -w <pid> | Process exists | Stays awake |
| Glowmoth agent mode | CPU, child processes, terminal writes | Waiting, then sleep allowed after the cool-down |
Method 1: caffeinate (built in, tied to process lifetime)
caffeinate ships with macOS. To hold the Mac awake while an existing process runs, pass its process ID:
caffeinate -i -w 12345-i prevents idle system sleep, and -w 12345 ends the hold when process 12345 exits. Press Control-C in that Terminal tab to stop it early. Nothing else needs undoing.
It works well when you wrap a command with a clear end:
caffeinate -i ./run-tests.shThe Mac is held until the script exits. It can't tell that an interactive agent is idle. For more flags, see the caffeinate command guide.
Method 2: Glowmoth agent mode
Agent mode is off by default. It needs a MacSuite license or an active trial, and macOS 14 Sonoma or later.
- Right-click the moth icon in the menu bar and choose Settings…. (You can also use Settings… in the panel footer, or press ⌘,.)
- Open the Automation tab.
- Under Coding Agents, turn on Stay awake while coding agents work.
- Set Allow sleep after to 2, 5 or 15 minutes. The default is 5.
- Optional: open Each Agent and set an agent to Keep Awake (default), Track Only (listed, never holds the Mac) or Ignore (not detected).
- Start your agent in a terminal. The live list shows each detected session with its agent name, project folder and state, or "No agents running".
The welcome window's AI Agents card also switches agent mode on, turns Keep the display on off and makes left-click open the panel. To reopen the welcome window, go to Settings > General > Startup > Welcome window > Show Welcome.
How Glowmoth decides Working or Waiting
Glowmoth polls every 5 seconds while an agent is around, every 15 seconds otherwise, and not at all while the switch is off. A session is Working if, since the last poll, any of these happened:
| Signal | What counts |
|---|---|
| CPU | The agent's process tree used at least 3% of a core |
| Child processes | The tree started or finished a child process |
| Terminal output | The tree wrote to its terminal |
If none happened, the session is Waiting. When the agent exits, it is Finished. The Mac stays held until the cool-down has passed since the last busy poll, so there is a short, deliberate delay between the agent going quiet and the Mac being allowed to sleep.
Picking a cool-down
| Pick | Choose it if |
|---|---|
| 2 minutes | You want the Mac asleep soon after the agent stops and it rarely goes quiet mid-task |
| 5 minutes (default) | You want a reasonable gap for pauses between steps |
| 15 minutes | Your agents often go quiet mid-task and you'd rather stay awake than risk sleep |
If a task goes quiet for longer than the cool-down, Glowmoth reads that as Waiting and the Mac can sleep. Raise the value if that happens.
Docker jobs and other work the agent doesn't do itself
A common follow-up is whether a docker compose job counts, since the terminal mostly waits. We haven't verified whether work inside a container counts toward an agent's activity, so don't rely on it. The signals above describe the agent's own process tree. If the real work happens elsewhere, give Glowmoth a direct reason. Reasons stack: the Mac is held while any of them is active.
- Wrap the command. Install the tool in Settings > Advanced > Command Line > Command-line tool > Install, then run
glowmoth run -- <command>. The Mac stays awake while the command runs, andrunreturns its exit code. If your shell can't findglowmoth, add~/.local/binto your PATH. See the command-line doc. - Watch a process. Right-click the icon, choose Keep Awake While > A Process Runs… and pick the process. For one you start often, add its executable name under Settings > Automation > Processes.
- Use a rule. In Settings > Automation > Rules, choose Add Rule > Custom Rule…, then Add Condition > More > CPU Busy. It averages the whole Mac's CPU, so other busy apps count too. Folder Busy watches a folder for growing files.
Check that it's doing what you expect
- Click the moth. The Held By list shows one row per reason, such as "Claude Code working in glowmoth". When the agent goes quiet, the row goes away after the cool-down.
- The icon shows the Automatic state (ring bulb) when only automatic reasons hold the Mac, and Sleep Allowed when nothing does.
- This read-only command lists current power assertions; Glowmoth's is named "Glowmoth: " followed by its first reason:
pmset -g assertionsChecklist before you test
- Agent mode is on and the panel shows Automatic, not Manual.
- The agent is one of the 11 command-line agents and is set to Keep Awake.
- Your trial or license is active.
- You have not used Stop Everything since the last session.
Why it might not work
- The agent never shows in the list. It may be the desktop app, not one of the 11, or set to Ignore.
- It's listed but the Mac still sleeps. It may be set to Track Only.
- Nothing holds the Mac. Manual mode ignores every automatic reason, and Stop Everything suspends them until you start a session (relaunching also clears it).
- The trial ended. The panel says "Your trial has ended. Enter a MacSuite license to keep your Mac awake."
- A safety pause. Low battery or a hot Mac releases the hold; the icon shows Paused. See battery and heat limits.
- The lid is closed. A MacBook still sleeps unless closed-lid mode is on. See the closed-lid doc.
- Something else. Show More in the panel includes "Also Keeping This Mac Awake". See what's keeping your Mac awake.
If nothing works
Contact support through the support page. Include your Glowmoth and macOS versions, which agent you run, what the Coding Agents list shows, and the output of pmset -g assertions.
Subject: Glowmoth agent mode not holding my Mac awake
Glowmoth version: (from About Glowmoth)
macOS version:
Agent and how I run it: Claude Code in Terminal
Coding Agents list shows: (Working / Waiting / not listed)
Allow sleep after: 5 min
Panel mode: Automatic
Output of pmset -g assertions: (paste here)
What I expected vs what happened:Common questions
Does Glowmoth read Claude Code's session log?
No. It looks at process activity: CPU, child processes and terminal writes. It doesn't read prompts or payloads, and nothing leaves your Mac.
What happens after an agent finishes?
Its state becomes Finished when the process exits, and the Mac can sleep once the cool-down since the last busy poll has passed.
Can I make the Mac sleep right away?
The shortest cool-down is 2 minutes. To end a hold immediately, click the moth and use the ✕ on its row in Held By, or choose Stop Everything.
What if I need exact turn boundaries?
Glowmoth uses a cool-down, not hooks. Some open-source tools, such as iannuttall's Caffeine, offer optional Claude Code and Codex hooks (as of November 2026, an early release); that approach suits you better if exact turns matter.
We make Glowmoth, so weigh our view accordingly. It is part of MacSuite and you can try it free for 7 days. See the Glowmoth page, the coding agents doc, or the broader guide on keeping your Mac awake while Claude Code or Codex runs.