跳到正文
DEV Community· Dawon Lee·· 3 小時前AI 評分58

Claude Code 遇使用額度限制後可自動續跑,但 Mac 睡眠可能令工作停在確認提示

Claude Code now resumes after a usage limit — unless your Mac fell asleep

AI 導讀

Claude Code v2.1.234+ 在使用額度重置後會自動接續未完成工作,但若 Mac 睡眠超過約 30 分鐘且重置發生於睡眠期間,便會停在要求按 Enter 的提示。

正文

If you're on a Claude subscription, recent versions of Claude Code (v2.1.234+) do something quietly great: when a usage limit stops Claude mid-task, the session waits and continues the task on its own after the limit resets.

Usage limit reached · limit resets 3:45pm
Continuing automatically at 3:45pm · esc to cancel

That's exactly what you want for a long refactor you start before bed. There's one catch, straight from the docs:

If it slept for more than about 30 minutes and the limit reset while it slept, the first line reads Your usage limit has reset and the second reads Press enter to continue.

So if your MacBook goes to sleep during the wait — lid closed, or just idle sleep — you wake up to a prompt asking you to press Enter, and the work hasn't moved. The 5-hour window means the wait can easily be a few hours.

Keeping the Mac awake through the wait

The wait itself uses almost no CPU, which is the problem: from the outside, a session waiting for a reset looks idle.

DIY: if you're at a desk on power, caffeinate -i in another terminal (or caffeinate -w <pid> for the Claude process) blocks idle sleep for as long as Claude runs. Closing the lid on battery is different — macOS sleeps on lid close unless you're in clamshell mode with an external display, and the only switch for that is sudo pmset -a disablesleep 1 (remember to set it back to 0).

Know when the wait starts and ends. Claude Code's hooks tell you exactly:

  • StopFailure with "error": "rate_limit" fires when a turn ends because of a rate limit.
  • Notification with notification_type:
    • quota_auto_resume_fired — Claude continued after the reset
    • quota_auto_resume_stale — the reset happened while the computer slept for 30+ minutes; it's waiting for Enter
    • quota_auto_resume_disabled — the wait ended without continuing

A minimal logger to see it happen:

{
  "hooks": {
    "StopFailure": [{ "matcher": "rate_limit", "hooks": [{ "type": "command",
      "command": "echo \"$(date) limit hit\" >> ~/claude-limit.log" }] }],
    "Notification": [{ "matcher": "quota_auto_resume_fired|quota_auto_resume_stale|quota_auto_resume_disabled",
      "hooks": [{ "type": "command", "command": "cat >> ~/claude-limit.log" }] }]
  }
}

With those two signals you can keep the Mac awake from the rate_limit stop until quota_auto_resume_fired (or a few minutes past the 5-hour window), and let it sleep otherwise.

What I did in Lidnight

I build Lidnight, a menu bar app that keeps a MacBook awake with the lid closed while AI agents work and lets it sleep when they're done. It installs the StopFailure hook too: when Claude Code stops on a rate limit, the session shows "limit · resumes in 2h 14m" and the Mac stays awake through a 5-hour wait, so the automatic continue actually happens. quota_auto_resume_fired puts it back to "working".

For the cases Claude Code won't continue on its own — a weekly limit, a stale/disabled wait, or Codex — Lidnight sends a one-line "please continue" after the reset through official features (Claude Code's cross-session messaging, codex queue). You choose per AI whether that should happen; set it to "paused" and the session stays stopped.

The same docs pass also turned up two notification types I now count as "waiting for you": elicitation_url_dialog (an MCP server asks you to open a URL) and agent_needs_input (a background session needs input).

Lidnight's AI Auto mode is free (you turn it on); Pro adds auto-start, phone approvals and more — a one-time $9.99 (50% off through Oct 31) with a 7-day trial. brew install whereisdw/tap/lidnight

Sources: Claude Code hooks reference · Wait for a usage limit to reset

來源:DEV Community · dev.to