[claude] Integrate Claude Quota Monitor + Metabolic Protocol into cascade router (#1075) #1086
Reference in New Issue
Block a user
Delete Branch "claude/issue-1075"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #1075
Summary
src/infrastructure/claude_quota.py— NewQuotaMonitorclass that reads the Claude Code OAuth token from macOS Keychain, callshttps://api.anthropic.com/api/oauth/usagewith 30s caching, and exposesQuotaStatuswith 5-hour and 7-day utilization. Implements the Metabolic Protocol: BURST (5h < 50%) → cloud allowed; ACTIVE (5h 50-80%) → Qwen3-14B only; RESTING (7d > 80%) → Qwen3-8B only. Degrades gracefully to local-only on Linux (no Keychain).src/infrastructure/router/cascade.py— IntegratesQuotaMonitorinto the cascade router. Before routing to anyanthropic/openai/grokprovider,_quota_allows_cloud()is called — if quota is too low the cloud provider is skipped and the next provider (Ollama) is tried instead.scripts/claude_quota_check.sh— CLI tool: human-readable color-coded quota bars,--jsonfor piping,--watchfor 60s refresh. Requires macOS with Claude Code authenticated.tests/infrastructure/test_claude_quota.py— 30 unit tests covering all MetabolicTier thresholds,select_model,should_use_cloud, caching TTL, and the singleton.Test plan
tox -e unit -- tests/infrastructure/test_claude_quota.pypasses (30 tests, all green)./scripts/claude_quota_check.shshows quota status🤖 Generated with Claude Code