Support macOS login keychain for credentials (fixes #3)#5
Open
shackstack wants to merge 1 commit into
Open
Conversation
On macOS, Claude Code stores OAuth credentials in the login keychain
(generic password, service "Claude Code-credentials") rather than in
~/.claude/.credentials.json. The switcher only did file I/O, so on a
default macOS install it failed with ENOENT on read, and a "successful"
switch wrote a file Claude Code never reads (active account unchanged).
Bridge credential I/O to the keychain via the `security` CLI when, on
darwin, the credentials file is absent but a keychain item exists:
- read: security find-generic-password -s "Claude Code-credentials" -w
- write: security add-generic-password -U -s "Claude Code-credentials"
-a <acct> -w <json>
- backup: dump the current keychain value into the backup dir before
overwriting (the file backup step is a no-op when no file exists)
The keychain payload already matches the expected shape
({ claudeAiOauth, mcpOAuth }), so only the I/O layer changes; sync / list
/ switch logic is untouched. Non-darwin and file-based macOS installs are
unaffected (the bridge only activates when the file is missing).
Fixes Leuconoe#3
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.
Problem
On macOS, Claude Code stores OAuth credentials in the login keychain (generic password, service
Claude Code-credentials), not in~/.claude/.credentials.json. Since the switcher only does file I/O for credentials, on a default macOS install:cc-switch/ sync fail withENOENT: ... open '~/.claude/.credentials.json'Fix
lib/store/io.cjsnow bridges credential I/O to the keychain via thesecurityCLI, but only when running ondarwin, the credentials file is absent, and a keychain item exists. Otherwise behavior is unchanged.security find-generic-password -s "Claude Code-credentials" -wsecurity add-generic-password -U -s "Claude Code-credentials" -a <acct> -w <json>(-Uupdates in place;<acct>taken from the existing item)The keychain payload already has the exact shape the tool expects (
{ claudeAiOauth, mcpOAuth }→credentials.claudeAiOauth), so only the I/O layer changes — sync / list / switch logic is untouched.Scope / safety
Testing
On macOS (Darwin, Node 18+), with credentials in the keychain and no
.credentials.json:cc-sync-oauthcaptures the current accountcc-switchlists accounts with usagecc-switch <i>switches and Claude Code picks up the new account after restartclaudeAiOauthandmcpOAuthpreserved), and akeychain-credentials.*.bakis written before each switchFixes #3