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
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):
costUSD = 0with asubscriptionnote in metrics output.maxSpendUSD/maxTokensIncannot be enforced under subscription billing.API key mode (
ANTHROPIC_API_KEYset — every Messages response carries authoritativeusage):input_tokens/output_tokens/ cache tokens from API responses.costUSD = tokens × modelPriceusing a hardcoded table withAFLOCK_PRICE_*env overrides (carry over from feat(usage): track tokens, cost, and turns from Claude Code session JSONL #97's pricing work).maxSpendUSD/maxTokensIn/maxTokensOutfail-fastat PreToolUse.Detection
Distinguish modes via env at SessionStart: presence of
ANTHROPIC_API_KEY(orANTHROPIC_AUTH_TOKEN) → API-key mode; otherwise subscription. Record the mode inSessionStateso PreToolUse can branch enforcement without re-checking.Open design call
How does the API-key-mode signal actually reach aflock?
ANTHROPIC_BASE_URLredirected) — precise but larger scope.Decide before implementation. Pick A for v1 unless B is already in plan.
Out of scope
Supersedes