Skip to content

feat: add auto trigger CD on quota reset#143

Open
Achilng wants to merge 1 commit intoXerxes-2:masterfrom
Achilng:feat/auto-trigger-cd
Open

feat: add auto trigger CD on quota reset#143
Achilng wants to merge 1 commit intoXerxes-2:masterfrom
Achilng:feat/auto-trigger-cd

Conversation

@Achilng
Copy link
Copy Markdown

@Achilng Achilng commented Apr 1, 2026

Summary

  • Add auto_trigger_cd config option that automatically sends a minimal message to Claude API when quota resets,
    pre-starting the 5-hour cooldown timer to reduce wait time when quota is later exhausted
  • Trigger CD for cookies whose session/weekly quota windows expire, and freshly added cookies with no active session
    window
  • Use cheapest model (claude-haiku-4-5-20251001) with max_tokens=1 to minimize quota impact

How it works

Claude's 5h session quota timer starts from the first message sent, not when quota runs out. By sending a trigger
message right when quota resets (or when a new cookie is added), the next 5h window starts immediately — reducing
effective wait time from hours to minutes.

Changes

  • src/config/clewdr_config.rs: Add auto_trigger_cd boolean config field (default: false)
  • src/services/cd_scheduler.rs: New independent background scheduler (60s polling) that detects expired quota
    windows via usage API and triggers CD
  • src/claude_code_state/chat.rs: Add trigger_cd() method that authenticates and sends a minimal request
  • src/router.rs: Spawn scheduler after CookieActorHandle creation
  • src/services/mod.rs: Register new module
  • Frontend: Add auto_trigger_cd toggle in Config UI with en/zh translations

Add a decoupled CD scheduler that automatically sends a minimal message
to start the cooldown timer when quota windows reset. This avoids the
need to wait for a user message to begin the countdown.

- Add CdScheduler as an independent background task (60s polling)
- Use usage API to detect expired quota windows (session, weekly, sonnet, opus)
- Add trigger_cd() method to ClaudeCodeState (haiku, max_tokens=1)
- Add auto_trigger_cd config toggle with frontend UI support
- Zero modifications to cookie_actor.rs
@LeenHawk
Copy link
Copy Markdown
Collaborator

LeenHawk commented Apr 2, 2026

You don't understand.... You could ask /usage to api.anthropic.com or https://claude.ai/settings/usage , then you don't need to send message to /message

@Achilng
Copy link
Copy Markdown
Author

Achilng commented Apr 2, 2026

My implementation already uses fetch_usage_metrics(), which internally calls api.anthropic.com/api/oauth/usage to detect quota resets. The call to /v1/messages is only used to trigger the cooldown timer after a reset is detected, querying /usage alone does not start the 5-hour countdown.

@LeenHawk
Copy link
Copy Markdown
Collaborator

My implementation already uses fetch_usage_metrics(), which internally calls api.anthropic.com/api/oauth/usage to detect quota resets. The call to /v1/messages is only used to trigger the cooldown timer after a reset is detected, querying /usage alone does not start the 5-hour countdown.

you don't need to send a message to make a credential healthy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants