Add idle-aware caffeinate management

Resolved 💬 2 comments Opened Feb 11, 2026 by mjgore1120 Closed Mar 12, 2026

Problem

Claude Code runs caffeinate -i -t 300 and respawns it every 5 minutes for the entire session, preventing macOS from sleeping even when the user has walked away and no tools/agents are running.

Proposed Solution

Only keep caffeinate alive while Claude Code is actively working (tool calls, subagents, awaiting user input after a response). When idle for >5 minutes with no activity, let the caffeinate assertion expire so the system can sleep normally.

Activity signals that should reset the timer:

  • Tool use (any)
  • User prompt submission
  • Subagent start/stop
  • Active streaming response

A config option would be nice too, e.g.:

{
  "caffeinate": "on-activity" | "always" | "never"
}

Default could remain "always" for backwards compatibility, with "on-activity" as an opt-in.

Current Workaround

Using hooks (PostToolUse, UserPromptSubmit, SubagentStart) to touch a heartbeat file, with a shell wrapper that monitors the heartbeat and kills caffeinate when stale. Works but is fragile compared to a native implementation.

Environment

  • macOS (Apple Silicon)
  • Claude Code CLI

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗