feat(cli): Allow pasting a long-lived OAuth setup token#253
Open
jwaldrip wants to merge 1 commit into
Open
Conversation
Adds a "Paste an OAuth Setup Token" section to the CLI Account
settings view so users can configure their profile with a token
generated by `claude setup-token` instead of relying on a
potentially-expired web sync flow.
The token is wrapped in a minimal claudeAiOauth JSON envelope and
stored in the active profile's cliCredentialsJSON; downstream usage
extraction (ClaudeAPIService.getAuthentication, hasValidCLIOAuth)
consumes it via the existing helpers. Long-lived setup tokens have
no expiresAt field, which intentionally makes isTokenExpired return
false ("no expiry info = assume valid").
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.
Description
Adds a "Paste an OAuth Setup Token" section to the CLI Account settings view so users can configure their profile with a long-lived token generated by
claude setup-tokeninstead of relying on a potentially-expired web sync flow from Claude Code's keychain. This is useful when a user's Claude Code session is dead/expired and re-running the OAuth web flow isn't viable (CI environments, remote machines, stale sessions).The token is wrapped in a minimal
claudeAiOauthJSON envelope and stored in the active profile'scliCredentialsJSON; downstream usage extraction (ClaudeAPIService.getAuthentication,Profile.hasValidCLIOAuth) consumes it through the existing helpers — no new code paths in the request layer. Long-lived setup tokens have noexpiresAtfield, which intentionally makesisTokenExpiredreturnfalse("no expiry info = assume valid"), matching the lifecycle ofclaude setup-tokenoutput.Changes
ClaudeCodeSyncService.saveManualOAuthToken(_:profileId:)— wraps a trimmed token in{"claudeAiOauth":{"accessToken":"…","subscriptionType":"manual","scopes":["user:inference","user:profile"]}}, writes it to the profile, and setshasCliAccount/cliAccountSyncedAt. Adds a newClaudeCodeError.invalidTokencase for empty input.CLIAccountView— newSettingsSectionCardcontaining a collapsibleDisclosureGroupwith a monospacedTextField(sk-ant-oat01-…placeholder), inline error display, and a Save button. Reuses existingDesignTokens(inputBackground,cardBorder,Radius.small, etc.) for visual consistency with the manual session-key entry inPersonalUsageView.cli.manual_token_title,cli.manual_token_subtitle,cli.manual_token_disclosure,cli.manual_token_help,cli.manual_token_placeholder,cli.manual_token_save,cli.manual_token_empty_error) translated into all 13.lprojfiles (en, de, es, fr, it, ja, ko, pt-BR, pt, tr, uk, zh-Hant, zh-ch).No changes to
ClaudeAPIService,Profilemodel, or the storage layer — the new token flows through the existing CLI OAuth fallback path ingetAuthentication()(priority 2, ahead of system Keychain lookup).Screenshots / Screen Recordings
Checklist
ProfileStore(standardUserDefaults), no new Keychain accessscripts/validate_localizations.shconfirms no new mismatches were introduced