fix(quota): read Claude quota via claude /usage instead of keychain#111
Merged
Conversation
Today's QuotaProbe reads the OAuth token from the macOS Keychain and calls /api/oauth/usage itself. Claude Code rotates that keychain item every ~8h, which wipes the trusted-app ACL grant — so the next read prompts the user for their password. anthropics/claude-code#22144 tracks the upstream ask, closed not-planned. Shell out to `claude --print --output-format json "/usage"` instead. That's a client-side intercept (zero model cost: num_turns=0, duration_api_ms=0) that hits the same backend, but runs inside Claude Code — which has its own keychain ACL grant. Our process never touches the keychain, so the periodic prompt is gone. CLI-first / API-fallback: the legacy probe is kept and invoked only on hard-fail (`claude` not on PATH, spawn/timeout failure, unparseable envelope). The CLI's own soft-fail (rate-limited cold cache, no bucket lines) is treated as "leave the prior snapshot alone" so we don't re-trigger the keychain path on transient noise. Anthropic ToS (post Jan/Feb 2026) explicitly bans third-party OAuth tokens hitting /api/oauth/usage — the CLI path is also the only policy-clean route long-term. Cleanup: every `claude --print` writes a session rollout to ~/.claude/projects/<cwd>/<uuid>.jsonl. At 60s polling that'd be ~1.4k files/day, polluting `claude --resume`. cwd is pinned to ~/.stack-nudge and the just-written file is unlinked after each probe (UUID-shape guard prevents path traversal). Settings → Usage now stays silent when the CLI probe is the source. The plaintext-file warning and the keychain-fallback explainer remain in their respective modes. Codex and Antigravity are unaffected — local rollout files and loopback RPC respectively, no keychain involved. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/.stack-nudge` and unlinks the session rollout file (`/.claude/projects//.jsonl`) that every `claude --print` writes, so a 60s polling cadence doesn't litter `claude --resume` with ~1.4k empty sessions/day. UUID-shape guard on the unlink prevents any path-traversal escape.Anthropic ToS (post Jan/Feb 2026) explicitly bans third-party OAuth tokens hitting `/api/oauth/usage`, so the CLI path is also the only policy-clean route long-term. Codex and Antigravity are unaffected (local rollout files and loopback RPC respectively — no keychain involved).
Closes the source of the recurring "stack-nudge wants to access Claude Code-credentials" prompt that anthropics/claude-code#22144 documents and Anthropic closed as not-planned.
Test plan
🤖 Generated with Claude Code