Skip to content

fix(account): restore display name and org on switch#26

Open
jesse23 wants to merge 2 commits intoforeveryh:mainfrom
jesse23:fix/account-switch-display-name-and-org
Open

fix(account): restore display name and org on switch#26
jesse23 wants to merge 2 commits intoforeveryh:mainfrom
jesse23:fix/account-switch-display-name-and-org

Conversation

@jesse23
Copy link
Copy Markdown

@jesse23 jesse23 commented Apr 6, 2026

Problem

Fixes #25

When using ccm switch-account, the Keychain/credential token is swapped correctly (quota works), but ~/.claude.json still holds the previous account's oauthAccount block. 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.json contains an oauthAccount field:

{
  "accountUuid": "...",
  "emailAddress": "user@example.com",
  "displayName": "username",
  "organizationName": "...'s Organization"
}

ccm never touched this file, only the Keychain entry.

Fix

  • Add read_oauth_account() / write_oauth_account() helpers to read/write the oauthAccount block in ~/.claude.json via Python3 (no new dependencies)
  • save-account now also saves oauthAccount as <name>__oauth alongside the credential entry in ~/.ccm_accounts, 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 already expired

Usage

Re-save existing accounts once to capture the __oauth data, then switching will update the display name correctly:

ccm save-account work
# → ✅ Account saved: work
# →    Subscription type: pro
# →    Display name: yourname

ccm switch-account personal
# → ✅ Account switched: personal
# →    ✓ Display name updated: othername
# → ⚠️  Please restart Claude Code

🤖 Generated with Claude Code

Manual Test

image

jesse23 and others added 2 commits April 6, 2026 18:23
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ccm switch-account not working

1 participant