Repository navigation
feat(usage): read claude-cli limits from Claude Code's login - #94
Merged
Merged
Conversation
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.
What and why
claude-clisends every request through theclaudeCLI, so it bills the account Claude Code is logged into. The usage plugin still read Claude limits from pi's own Anthropic/login. After Claude Code switched accounts (in my case through tagteam), the widget showed limits for the wrong account.With this change:
claude-climodels: readsclaudeAiOauth.accessTokenfrom$CLAUDE_CONFIG_DIR/.credentials.json(default~/.claude/) and queries the same usage and profile endpoints as before. Theclaude-codelimits are cached apart from theanthropicones./usage: when theclaude-cliprovider is registered, the report adds a "Claude Code" section. It drops the pi "Claude" section unless pi has its own Anthropic OAuth login. Withoutclaude-cli, the report is unchanged.UsageServiceError.Verification
nix develop -c cipasses: format, lint, type check, build and tests.UsageService.claudeCode()and ran it:~/.claude.json(Claude Code (Max 5x) — <the Claude Code account>), with 4 limit rows.CLAUDE_CONFIG_DIRpointing at test directories: a missing file, invalid JSON, a file with noclaudeAiOauth, and an expiredexpiresAteach gave the expected error.Review findings I skipped
… — run /login to (re-)authenticate), which the report shows inline. Changing only the new ones would mix two styles.readStoredCredentialinindex.ts. The reviewer suggested running the section and dropping it onCredentialsMissinginstead. That would make sections optional results, which seemed more machinery than the one-line check.homedir()fromnode:os. Effect has no home-directory API, andHOMEisn't set on Windows.Open questions
Claude Code-credentials, with a hash suffix per config dir). The plugin doesn't read it, and says so in the missing-login error. Reading it throughsecurity find-generic-passwordwould raise a one-time access prompt, so I left it for a follow-up.