I kept closing my MacBook mid Claude Code run, so I built a menu bar app that keeps it awake until the agent is done
retained text
The problem: start a long Claude Code task, close the lid, put the Mac in my bag, come back to nothing. macOS sleeps the second the lid closes, and `caffeinate` only stops idle sleep. So I built Double Shot with Claude Code. It's a small Swift menu bar app that keeps the Mac awake while an agent is actually working, lid closed too, and lets it sleep a few minutes after things go quiet. The interesting part was telling "working" from "open". A session sitting at the prompt or waiting for approval shouldn't keep the Mac awake. What ended up working: * every 10 seconds, check CPU used by each Claude session and the tool calls it started (MCP servers and browsers left out) * watch `~/.claude/projects` with FSEvents, so a write to the session log counts as activity. One folder per project, so each session only counts its own writes * `claude -p` runs count until the process exits How Claude Code helped: * wrote most of the Swift from scratch with me (no fork) * before launch I had several agents QA the app in parallel. They found 41 real issues, including a crash case that could leave the Mac unable to sleep, so I added a watchdog that turns sleep back on if the app dies * a second QA round caught the panel animation burning about 14% CPU while the panel was closed. I would never have noticed that What I learned: lid closed needs `pmset disablesleep`, which needs root. I didn't want an app running as root, so it adds one sudoers rule for exactly four pmset commands, and the README shows the rule. It also handles the bag: screen off, Low Power Mode on battery, stops if it gets warm. Free, open source (MIT), macOS 14+: [https://github.com/noahelhadedy/double-shot](https://github.com/noahelhadedy/double-shot) `brew install --cask noahelhadedy/tap/double-shot` Works with Codex, Gemini CLI and a few others too. If your agent isn't detected, tell me which one.
document fetched 2026-10-31 00:43 · canonical https://reddit.com/r/ClaudeCode/comments/1xjf62j/i_kept_closing_my_macbook_mid_claude_code_run_so