{"slug": "how-to-keep-your-mac-awake-for-claude-code-and-codex", "title": "How to keep your Mac awake for Claude Code and Codex", "summary": "A developer documented how Claude Code, Codex, and Grok Build each prevent Mac idle sleep only while an agent turn is actively running, releasing the assertion between turns and while waiting for user approval. The writeup recommends wrapping agents in macOS's built-in `caffeinate -i` (optionally with `-t` for a fixed duration) to keep the machine reachable from a phone or SSH between turns, and notes that `pmset -g` shows which processes are currently holding sleep off. It also flags that closing the lid or choosing Sleep overrides all of these measures.", "body_md": "You leave Claude Code running, lock the screen, and go to lunch. Later you check in from your phone, and the session doesn't answer: the Mac went to sleep. Locking wasn't the problem. Locked, the Mac keeps running everything. Idle sleep is what pauses the agent.\n\nEach agent keeps the Mac awake only while it's working on a turn:\n\n`caffeinate -i` while a turn is running. It lets go while it waits for your approval and after the turn ends.`/experimental`. It also covers only a running turn.` sleep_prevention`, on by default) and releases it when the turn ends.\nNo. Locking the screen, or letting the display turn off, leaves every process running. An agent halfway through a task carries on.\n\nSleep is different. When the Mac sleeps, processes pause and the network goes down. A request that was on its way to the model can fail, and anything that connects to the Mac from outside can't reach it: Claude Code's remote control from the phone app, an SSH session, a tunnel. When the Mac wakes, the agent picks up where it paused, and you may need to tell it to continue if a request failed.\n\nSo the question isn't whether the screen is locked. It's whether the Mac is allowed to go to sleep while you're away.\n\nOnly while a turn is running.\n\n**Claude Code** starts `caffeinate -i` when it begins working and stops it when the turn ends or when it stops to ask for your approval. So if it's waiting on a permission prompt, the Mac can fall asleep.\n\n**Codex** has the same idea as an experimental feature, off by default. Type `/experimental` and turn on **Prevent sleep while running**, or set it in `~/.codex/config.toml`:\n\n```\n[features]\nprevent_idle_sleep = true\n```\n\n**Grok Build** keeps the display awake while the agent works and releases it when the turn ends. It's on by default; to turn it off, set this in `~/.grok/config.toml`:\n\n```\n[ui.notifications]\nsleep_prevention = false\n```\n\nNone of them keep the Mac awake between turns. That's exactly when you're waiting to send the next message, from the keyboard or from your phone.\n\nUse `caffeinate`, which ships with macOS. `-i` stops idle sleep and lets the display sleep and lock as usual:\n\n```\n# For as long as this agent runs\ncaffeinate -i claude\n\n# For two hours, in the background\ncaffeinate -i -t 7200 &\n```\n\nThe first form lasts exactly as long as the agent: when you quit Claude Code, normal sleep comes back. The same works with `codex` or `grok`.\n\nTo keep a MacBook awake whenever it's plugged in, open **System Settings → Battery → Options** and turn on **Prevent automatic sleeping on power adapter when the display is off**. That's a standing change, so remember to undo it if you only needed it for one evening.\n\nRun:\n\n```\npmset -g\n```\n\nThe `sleep` line names the apps holding the Mac awake right now, for example `sleep prevented by caffeinate`. For the full list, with what each one is preventing, run `pmset -g assertions`.\n\nThis is a quick way to check before you leave. If the line doesn't name anything and the agent is between turns, the Mac will sleep on its normal schedule.\n\nClosing the lid puts a MacBook to sleep, whatever `caffeinate`, the agents, or the power settings say. Choosing **Sleep** from the Apple menu does the same.\n\nThe exception is running with the lid closed on purpose: with the Mac on power and connected to an external display, keyboard, and mouse, closing the lid keeps it awake. Without that setup, keep the lid open while you need the agent reachable.\n\nYes. In [PonyMux](https://ponymux.com), click the coffee cup at the bottom of the sidebar. It turns accent-colored, and its tooltip reads **Keep Awake (On)**.\n\n*The bottom of PonyMux's sidebar with Keep Awake on: the coffee cup is highlighted.*\n\nWhile it's on, PonyMux keeps the Mac from idle sleep, including between turns and while an agent waits for you. The display can still turn off and lock. It doesn't override closing the lid or choosing Sleep, and it has no timer: it stays on until you click the cup again. Turn it off when you're done so the Mac can go back to saving energy.\n\nFor the rest of PonyMux's power settings, see [Settings and Accessibility](https://ponymux.com/docs/settings-accessibility).\n\n*Originally published on [ponymux.com](https://ponymux.com/guides/keep-mac-awake-claude-code-codex), where the demos are interactive.*", "url": "https://wpnews.pro/news/how-to-keep-your-mac-awake-for-claude-code-and-codex", "canonical_source": "https://dev.to/heylittlepan/how-to-keep-your-mac-awake-for-claude-code-and-codex-n2n", "published_at": "2026-10-07 16:39:26+00:00", "updated_at": "2026-10-07 16:47:17.213640+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools"], "entities": ["Claude Code", "Codex", "Grok Build", "macOS", "PonyMux", "caffeinate", "pmset"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-to-keep-your-mac-awake-for-claude-code-and-codex", "markdown": "https://wpnews.pro/news/how-to-keep-your-mac-awake-for-claude-code-and-codex.md", "text": "https://wpnews.pro/news/how-to-keep-your-mac-awake-for-claude-code-and-codex.txt", "jsonld": "https://wpnews.pro/news/how-to-keep-your-mac-awake-for-claude-code-and-codex.jsonld"}}