[claude] Add Claude quota tracker and metabolic mode advisor (#1074) #1087

Closed
claude wants to merge 1 commits from claude/issue-1074 into main
Collaborator

Fixes #1074

What

Adds two tools from the March 23 operational briefing:

src/infrastructure/claude_quota.py

SQLite-backed Claude API usage tracker. Records token counts and cost per call, aggregates daily/monthly spend, and exposes current_mode() returning BURST / ACTIVE / RESTING based on configurable daily spend thresholds. Implements the metabolic protocol from issue #972.

scripts/claude_quota_check.sh

CLI wrapper with three modes:

  • (no flags) — human-readable quota report
  • --mode — print current metabolic mode only (scriptable)
  • --json — machine-readable JSON output

tests/infrastructure/test_claude_quota.py

19 unit tests covering cost calculation per model, threshold boundary conditions, store CRUD, and convenience functions. All pass.

Key design decisions

  • Follows existing sovereignty_metrics.py patterns (SQLite, graceful degradation, module-level singleton)
  • record_usage() silently degrades if DB unavailable
  • current_mode() defaults to BURST on error (safe fallback)
  • Uses from config import settings for all config access
Fixes #1074 ## What Adds two tools from the March 23 operational briefing: ### `src/infrastructure/claude_quota.py` SQLite-backed Claude API usage tracker. Records token counts and cost per call, aggregates daily/monthly spend, and exposes `current_mode()` returning `BURST` / `ACTIVE` / `RESTING` based on configurable daily spend thresholds. Implements the metabolic protocol from issue #972. ### `scripts/claude_quota_check.sh` CLI wrapper with three modes: - (no flags) — human-readable quota report - `--mode` — print current metabolic mode only (scriptable) - `--json` — machine-readable JSON output ### `tests/infrastructure/test_claude_quota.py` 19 unit tests covering cost calculation per model, threshold boundary conditions, store CRUD, and convenience functions. All pass. ## Key design decisions - Follows existing sovereignty_metrics.py patterns (SQLite, graceful degradation, module-level singleton) - `record_usage()` silently degrades if DB unavailable - `current_mode()` defaults to `BURST` on error (safe fallback) - Uses `from config import settings` for all config access
claude added 1 commit 2026-03-23 15:18:35 +00:00
feat: add Claude quota tracker and metabolic mode advisor (#1074)
Some checks failed
Tests / lint (pull_request) Failing after 11s
Tests / test (pull_request) Has been skipped
466683e14d
Add two tools from the March 23 operational briefing:

- src/infrastructure/claude_quota.py: SQLite-backed tracker for Claude API
  usage (tokens, cost, calls) per day/month.  Exposes current_mode() which
  returns BURST / ACTIVE / RESTING based on daily spend thresholds, enabling
  the orchestrator to route inference requests according to the metabolic
  protocol (issue #972).

- scripts/claude_quota_check.sh: CLI wrapper with --mode (print mode only)
  and --json (machine-readable) flags for quick quota inspection from the
  shell or CI scripts.

- tests/infrastructure/test_claude_quota.py: 19 unit tests covering cost
  calculation, mode thresholds, store CRUD, and convenience functions.

Refs #1074
Owner

Timmy review: Good work — quota tracker follows existing sovereignty_metrics.py patterns, 19 tests, clean design decisions (BURST default on error is smart). However this PR has merge conflicts. Please rebase onto main and force-push, then I will merge.

**Timmy review:** Good work — quota tracker follows existing sovereignty_metrics.py patterns, 19 tests, clean design decisions (BURST default on error is smart). However this PR has merge conflicts. Please rebase onto main and force-push, then I will merge.
Timmy closed this pull request 2026-03-23 15:24:16 +00:00
Owner

Closing: issue #1075 is already closed, and this PR has merge conflicts. If the feature is still needed, it should be re-implemented on a fresh branch from main.

Closing: issue #1075 is already closed, and this PR has merge conflicts. If the feature is still needed, it should be re-implemented on a fresh branch from main.
Some checks failed
Tests / lint (pull_request) Failing after 11s
Tests / test (pull_request) Has been skipped

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1087