claude-code-ping-start-5h-quota
When Claude subscription quota is exhausted before going to sleep or stepping away, set up a one-time local timer to automatically send a minimal `claude -p` message as soon as the quota resets, immediately opening a new 5-hour usage window—so by the time you wake up, most of the window has passed without burning your quota, effectively scoring a free cooldown period. Use when the user says things like: "My quota resets in X hours, ping Claude for me then", "I'm going to sleep, ping it when it resets to open a new window", "Out of quota, hit it right at reset time", "Set a timer to kick off a new 5-hour cooldown window", or mentions scheduled ping, ping Claude, quota ping, window opening, or sending a message right after quota reset. Limited strictly to one-time scheduled tasks on local macOS (caffeinate/BSD date); use /loop or cron for recurring tasks, use tibo-reset-codex to check when ChatGPT/Codex resets, and use claude-usage-analyst to diagnose why quota burned out.
1How It Works & Mechanism
Leverage the window onset semantics: a 5-hour window begins on the 'first request within the window' rather than rolling over at a fixed time. Thus, if no one sends a message after reset, the window timer does not start; sending a minimal automated message immediately upon reset shifts the start of the window into sleep time.
Claude 订阅的 5 小时用量窗口从**窗口内第一条请求**开始计时,而不是按固定时刻轮转。
The timer itself is a detached background process chain: caffeinate -is prevents sleep during the waiting period → sleep N seconds → cd $HOME → claude -p sends a single-turn message 'Reply with exactly: ok', launched via Bash run_in_background.
caffeinate -is /bin/sh -c 'sleep <SLEEP_SECONDS> && cd "$HOME" && claude -p "Reply with exactly: ok"'
run_in_background is the key semantic: a foreground sleep would be blocked by the harness; a detached background process does not rely on session survival, and its exit will wake the original session to form a 'double insurance'.
**必须 run_in_background**:前台 sleep 会被 harness 拦截;后台任务是 detached 进程,且退出时会重新唤醒当前会话(见 Step 5)。
Idempotency and read-back verification: run `ps` before launching to check if an identical timer is already running (if so, report and ask whether to replace it); after launch, verify via `ps` that all three lines of the process chain (sh/caffeinate/sleep) exist.
ps -ef | grep -E 'claude -p "Reply with exactly: ok"' | grep -v grep
Time conversion formula: wait minutes = minutes until reset + 5-minute buffer; absolute times earlier than or equal to current time are interpreted as the same time tomorrow (late-night inputs crossing midnight are standard); SLEEP_SECONDS = wait minutes × 60.
换算公式(占位符全文统一):`等待分钟数 = 距重置分钟数 + 5`;`SLEEP_SECONDS = 等待分钟数 × 60`。
Final verification and cancellation discipline: once woken up at the scheduled time, read the task output file, expecting 'ok' + '[exited with code 0]'; verify the actual trigger time using the output file mtime (stat -f '%Sm'); cancel using signature-string pkill and strictly forbid killing by sleep seconds.
**禁止按秒数 `pkill -f 'sleep <SLEEP_SECONDS>'`**:本机长驻脚本的心跳 sleep 可能恰好同秒数,实测发生过误杀
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | claude(官方 Claude Code CLI;claude -p 单轮 print 模式) |
| cli | caffeinate(macOS 防睡眠) |
| cli | sleep / date / ps / pkill / stat(macOS/BSD 系统工具) |
| cli | 宿主 Bash 的 run_in_background 后台任务 + task-notification 唤醒(harness 能力) |
4Recommended Governance & Evidence
- scripts/: Execute local script or command: Agent executes in the host background: caffeinate -is /bin/sh -c 'sleep <S> && cd $HOME && claude -p
- 网络端点: Declare external network access: Initiates an authentic subscription API request to Anthropic via the official claude CLI (single-turn claude -p; this is the core purpose of the skill)
5Second-Pass Verification
- [ok] 无自带脚本/资产(纯指令 skill) — glob 确认目录仅 SKILL.md;external_deps/internal_assets 不夸大(asset 列表为空)。
- [ok] caffeinate/sleep/claude -p 命令链存在且为固定模板 — Step 2 代码块逐字存在;命令解剖表逐组件解释;无 shell 拼接注入(数字换算后入占位符)。
- [ok] run_in_background 语义与双保险 — SKILL.md 原文『后台任务是 detached 进程,且退出时会重新唤醒当前会话』与 Step 5『被唤醒本身也是一次 API 请求』一致。
- [ok] 幂等检查与 ps 读回验证 — Step 0 的 ps grep 命令与 Step 3 的三行预期存在;Step 4 交代 output 路径进对话历史。
- [ok] 凭证接触面为零 — token 扫描(API_KEY/token/cookie/secret/Authorization)零命中;无 env/keychain/文件读取。
- [ok] pkill 取消纪律(防误杀) — 禁止按秒数 pkill 的原文与实测误杀背景存在;特征串 pkill 为唯一取消路径。
- [ok] 功能声明 vs 夸大检查 — 『5 小时窗口从窗口内第一条请求起算』是描述性机制声明(对 Claude 订阅语义的表述,标注 2026-08-29 实测);skill 边界(macOS/一次性/不查询重置时刻)自我声明清晰,无越界承诺。
- [ok] 元数据(license/stars/commit) — 仓库级 MIT、stars=1385、pushed_at=2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678cb5d4fd6acc9c922690df035dbd33d247。
6Verdict & Scenarios
c6f9d07b09144f82…