fix(account): restore display name and org on switch#26
Open
jesse23 wants to merge 2 commits intoforeveryh:mainfrom
Open
fix(account): restore display name and org on switch#26jesse23 wants to merge 2 commits intoforeveryh:mainfrom
jesse23 wants to merge 2 commits intoforeveryh:mainfrom
Conversation
When switching accounts, ccm only swapped the Keychain/credential token but left ~/.claude.json's oauthAccount untouched, causing Claude Code to show the previous account's display name, org, and email after restart. Fixes: foreveryh#25 Changes: - Add read_oauth_account() / write_oauth_account() helpers to read and write the oauthAccount block in ~/.claude.json - save-account now also saves oauthAccount as <name>__oauth alongside the credential entry, and prints the display name on save for confirmation - switch-account now restores oauthAccount to ~/.claude.json so display name and org update correctly after restart - switch-account warns upfront if the saved token is expired Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The sed-based append to ~/.ccm_accounts could produce double commas (,,) when the last entry already had a trailing comma, corrupting the JSON file and breaking list-accounts. Replace sed/grep manipulation of the __oauth key with python3 json module, which handles reads and writes atomically and correctly regardless of file state or base64 content. Co-Authored-By: Claude Sonnet 4.6 <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.
Problem
Fixes #25
When using
ccm switch-account, the Keychain/credential token is swapped correctly (quota works), but~/.claude.jsonstill holds the previous account'soauthAccountblock. Claude Code reads display name, email, and org from this field, so after restart it always shows the last-login user's info regardless of which account was switched to.Root cause:
~/.claude.jsoncontains anoauthAccountfield:{ "accountUuid": "...", "emailAddress": "user@example.com", "displayName": "username", "organizationName": "...'s Organization" }ccm never touched this file, only the Keychain entry.
Fix
read_oauth_account()/write_oauth_account()helpers to read/write theoauthAccountblock in~/.claude.jsonvia Python3 (no new dependencies)save-accountnow also savesoauthAccountas<name>__oauthalongside the credential entry in~/.ccm_accounts, and prints the display name on save for confirmationswitch-accountnow restoresoauthAccountto~/.claude.jsonso display name and org update correctly after restartswitch-accountwarns upfront if the saved token is already expiredUsage
Re-save existing accounts once to capture the
__oauthdata, then switching will update the display name correctly:🤖 Generated with Claude Code
Manual Test