Skip to content

fix: preserve Claude login when switching accounts on macOS - #5

Open
venshine wants to merge 2 commits into
2hmad:mainfrom
venshine:fix/macos-keychain-backend
Open

venshine wants to merge 2 commits into
2hmad:mainfrom
venshine:fix/macos-keychain-backend

Conversation

@venshine

Copy link
Copy Markdown

On macOS, switching accounts could report success while claude auth status reported signed out. Keychain writes copied JSON containing newlines; Apple's security -w returns hex for values with non-printable bytes, which Claude cannot parse as JSON. A stale .credentials.json could also cause ccswitch to select a different backend from Claude.

Default macOS to Keychain, and serialize Keychain writes as compact ASCII JSON without a trailing newline. Reject invalid JSON and non-finite numbers before replacing a live credential. Explicit CCSWITCH_BACKEND=file remains available. Update the security fixture to reproduce Apple's output behavior and keep the file smoke suite portable on macOS Bash 3.2.

Validation:

  • Corrected fixture reproduced the original unreadable-credential/signed-out warning before the fix.
  • 26 Keychain/integration checks passed with local Claude Code 2.1.305, including both accounts' login status and email, shared/isolated MCP credentials, Unicode/escaped newlines and invalid-write preservation.
  • ShellCheck 0.11, all six Bash syntax checks and version consistency passed.
  • Smoke suite: 88 passed; two process-inspection assertions fail because this host denies ps/pgrep. They still require CI verification.
  • User confirmed real macOS switching works after applying the fix.

The automated tests use synthetic credentials and a mocked security(1); real-account confirmation was provided by the user. Apple's output behavior is documented in its source.

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.

1 participant