Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code 5-Hour Window Trigger

简体中文 | English


简体中文

让 Claude Code 的 5 小时用量窗口在你想要的时间开始喵~

核心思路

Claude Code 的用量窗口是第一条消息开始计时 5 小时后重置。所以可以通过定时发一条 hi 来精确控制窗口起点:

上班时间 推荐第一条触发时间 窗口 1 窗口 2
9:00-18:00,午休 12:30-14:00 9:00 9:00-14:00 14:00 后正常使用自动启动
9:00-18:00,午休 12:00-13:30 8:30 8:30-13:30 13:30 后正常使用自动启动

让窗口 1 在午休末尾自然过期,午休回来直接开新窗口,工作时间 100% 覆盖。

工作原理

每天 9:00(可调)通过 Windows 任务计划程序自动给 Haiku(最便宜模型)发一条 hi,触发当天 5 小时窗口的起点。每次触发的成本约 $0.0001。

前置条件

  • Windows 10 / 11
  • 已安装并登录 Claude Codeclaude.cmd 在 PATH 中)
  • Pro / Max 订阅

安装步骤

# 1. 克隆到本地(任意位置)
git clone https://github.com/<your-username>/claude-code-window-trigger.git
cd claude-code-window-trigger

# 2. 测试脚本
.\trigger-claude.bat
# 检查 trigger.log,应出现 "SUCCESS: 5-hour window triggered"

# 3. 注册定时任务
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\setup-task.ps1                        # 默认 9:00 AM
.\setup-task.ps1 -TriggerTime "8:30AM"  # 自定义时间

文件说明

文件 作用
trigger-claude.bat 实际触发脚本,自动从 PATH 找 claude.cmd
setup-task.ps1 注册 / 重注册定时任务(支持自定义时间)
trigger.log 运行日志(自动生成,已 .gitignore)

常用命令

# 手动触发测试
Start-ScheduledTask -TaskName 'ClaudeCode-Window-Trigger-9AM'

# 查看运行状态
Get-ScheduledTaskInfo -TaskName 'ClaudeCode-Window-Trigger-9AM'

# 暂停 / 恢复
Disable-ScheduledTask -TaskName 'ClaudeCode-Window-Trigger-9AM'
Enable-ScheduledTask  -TaskName 'ClaudeCode-Window-Trigger-9AM'

# 查看日志
Get-Content -Tail 40 .\trigger.log

# 卸载
Unregister-ScheduledTask -TaskName 'ClaudeCode-Window-Trigger-9AM' -Confirm:$false

注意事项

  • ⚠️ 触发时电脑必须开机 + 已登录,否则任务跳过(不补跑)
  • ⚠️ 周末 / 节假日如果电脑开着也会触发,但每天约 $0.0001 成本可忽略
  • ⚠️ 使用前请确保你的订阅级别符合 Anthropic 使用条款

自定义 claude.cmd 路径

如果 claude.cmd 不在 PATH 中,可设置环境变量:

[Environment]::SetEnvironmentVariable("CLAUDE_CMD", "C:\path\to\claude.cmd", "User")

English

Start Claude Code's 5-hour sliding window at exactly the time you want.

Why

Claude Code's usage window starts when you send your first message and resets 5 hours later. By scheduling a single hi every morning, the window expires during lunch and you get a fresh one when you return — covering both halves of your workday.

Quick Start

git clone https://github.com/<your-username>/claude-code-window-trigger.git
cd claude-code-window-trigger
.\trigger-claude.bat                              # test
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\setup-task.ps1 -TriggerTime "9:00AM"            # register

Requirements

  • Windows 10 / 11
  • Claude Code installed (claude.cmd on PATH)
  • Pro / Max subscription recommended

Notes

  • PC must be powered on and logged in at trigger time (no catch-up runs)
  • Each trigger costs ~$0.0001 (one Haiku message)
  • Make sure your usage complies with Anthropic's AUP

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages