Skip to content

feat(metrics): warn on subscription mode, enforce maxSpendUSD / maxTokensIn under API key #111

@manzil-infinity180

Description

@manzil-infinity180

Context

PR #97 (closes #96) tried to extract token/cost from Claude Code's JSONL transcript. Result was unreliable — the numbers we computed didn't match reality. Cole + Rahul decided (2026-05-07 sync) to split behavior by agent billing mode rather than keep grinding on JSONL math.

What ships in v1

Subscription mode (Claude Pro / Max — no per-call cost signal):

  • Display costUSD = 0 with a subscription note in metrics output.
  • Stderr warning at SessionStart: limits like maxSpendUSD / maxTokensIn cannot be enforced under subscription billing.
  • Policies that declare these limits still load, but evaluation skips them.

API key mode (ANTHROPIC_API_KEY set — every Messages response carries authoritative usage):

Detection

Distinguish modes via env at SessionStart: presence of ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN) → API-key mode; otherwise subscription. Record the mode in SessionState so PreToolUse can branch enforcement without re-checking.

Open design call

How does the API-key-mode signal actually reach aflock?

  • Option A: keep parsing JSONL but only in API-key mode (where numbers match reality more closely than under subscription).
  • Option B: aflock as an Anthropic API proxy (ANTHROPIC_BASE_URL redirected) — precise but larger scope.

Decide before implementation. Pick A for v1 unless B is already in plan.

Out of scope

  • Cache-token pricing nuance beyond a flat discount.
  • Cross-session reconciliation.
  • Subscription tier upgrades (if Anthropic later exposes subscription usage via API, file a follow-up).

Supersedes

Metadata

Metadata

Labels

enhancementNew feature or requestpaper-85Close set → reaches ~85% paper compliance

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions