cd /news/developer-tools/claude-awake-keep-your-mac-awake-eve… · home topics developer-tools article
[ARTICLE · art-84374] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

claude-awake: keep your Mac awake (even lid-closed) while Claude Code is working — heartbeat hooks + pmset watchdog

A developer created claude-awake, a pair of scripts that keep a Mac awake (even with the lid closed) while Claude Code is actively running tasks, using heartbeat hooks and a pmset watchdog. The daemon checks session state files and thermal throttling to decide whether to disable sleep, and restores sleep if the watchdog exits or the Mac overheats.

read3 min views1 publishedAug 2, 2026

| #!/bin/bash | | | | | | | | | | | | | | | | | | | | | | | STATE_DIR="$HOME/.claude/awake-state" | | LOG="$HOME/.claude/awake.log" | | POLL=20 # seconds between checks | | STALE_MIN=30 # a session file not refreshed within this many minutes = stale → ignored | | COOL_LIMIT=100 # CPU_Scheduler_Limit / CPU_Speed_Limit below this = throttling (hot) | | | | mkdir -p "$STATE_DIR" 2>/dev/null | | log() { printf '%s %s\n' "$(date '+%F %T')" "$" >>"$LOG"; } | | | | applied="" # last value we actually pushed to pmset (avoid redundant calls) | | set_sleep() { # $1: 1 = disable sleep (stay awake), 0 = enable sleep (allow sleep) | | [ "$applied" = "$1" ] && return | | if sudo -n /usr/bin/pmset -a disablesleep "$1" 2>>"$LOG"; then | | applied="$1" | | log "disablesleep=$1 $([ "$1" = 1 ] && echo '→ staying awake (lid-close OK)' || echo '→ sleep allowed')" | | else | | log "pmset FAILED — set up passwordless sudo for pmset (see /etc/sudoers.d/claude-pmset)" | | fi | | } | | | | overheating() { # 0 = hot/throttling, 1 = ok | | local therm field val | | therm="$(pmset -g therm 2>/dev/null)" | | for field in CPU_Scheduler_Limit CPU_Speed_Limit; do | | val="$(printf '%s' "$therm" | sed -n "s/.$field[[:space:]]=[[:space:]]([0-9])./\1/p" | head -1)" | | [ -n "$val" ] && [ "$val" -lt "$COOL_LIMIT" ] && return 0 | | done | | return 1 | | } | | | | active_count() { find "$STATE_DIR" -type f -mmin "-$STALE_MIN" 2>/dev/null | wc -l | tr -d ' '; } | | | | | trap 'sudo -n /usr/bin/pmset -a disablesleep 0 2>/dev/null; log "watchdog exit → sleep ENABLED"; exit 0' INT TERM | | | | log "watchdog up (poll ${POLL}s, stale ${STALE_MIN}m, cool<${COOL_LIMIT})" | | while true; do | | if [ "$(active_count)" -gt 0 ] && ! overheating; then | | set_sleep 1 | | else | | set_sleep 0 | | fi | | find "$STATE_DIR" -type f -mmin "+$STALE_MIN" -delete 2>/dev/null # reap stale markers | | sleep "$POLL" | | done |

── more in #developer-tools 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/claude-awake-keep-yo…] indexed:0 read:3min 2026-08-02 ·