Claude Code's macOS credential store is a composite named keychain-with-plaintext-fallback: it reads the Keychain first and falls back to <config dir>/.credentials.json, and a failed Keychain write migrates the credential into that file. ccswitch looked only at the Keychain, under a hardcoded service name, and passed the token on argv. Three consequences, all fixed here. Headless and SSH machines. Over SSH the login Keychain cannot be unlocked without a GUI prompt (security exits 36, errSecInteractionNotAllowed), so Claude Code lives entirely in the plaintext file. read() saw nothing, so save reported "no active credential" on a signed-in machine and sync_current silently dropped rotated tokens; write() could not land the incoming credential, leaving ~/.claude.json naming the new account while the live token still belonged to the old one, which Claude Code reports as not logged in. KeychainStore now mirrors the same arbitration and keeps exactly one authoritative copy: a successful Keychain write deletes the plaintext file, a failed one deletes the Keychain item, so a stale copy cannot shadow the switch from the other kind of session. $CCSWITCH_CREDENTIALS =file forces the plaintext path outright. $CLAUDE_CONFIG_DIR. It moves .claude.json and the credential fallback, and it renames the Keychain item: Claude Code namespaces the service with the first eight hex characters of sha256($CLAUDE_CONFIG_DIR). With the variable set, ccswitch was reading and writing a different account's credential. This affected ordinary use, because ccswitch isolate launches claude with CLAUDE_CONFIG_DIR set to the isolate directory. claude_env.rs owns the derivation, including the related $CLAUDE_SECURESTORAGE_CONFIG_DIR and $CLAUDE_CODE_CUSTOM_OAUTH_URL. Token exposure. add-generic-password -w put the OAuth token in argv, which ps shows to every user on the machine. It is now hex-encoded and piped to security -i, with the same argv fallback Claude Code uses past the stdin limit. The Keychain port collapses to one run(args, stdin) so that choice is a tested decision in creds.rs rather than shim detail. Also fixed: account_attr parsed stderr, but find-generic-password -g prints attributes on stdout and the password on stderr, so it always returned None and every profile stored an empty keychain_account. Writes fell through to $USER, which is what Claude Code looks items up by, so this was invisible. Account attributes are now sanitized the same way Claude Code sanitizes them. sha256.rs is hand-rolled against the FIPS vectors rather than pulling sha2 and six transitive crates for one eight-character string, per the dependency policy in AGENTS.md. Claude Code NFC-normalizes the directory before hashing and we hash the bytes as given; that agrees for every ASCII path, and the limitation is documented with its workaround. Behavior change: profile and isolate storage now default to accounts/ and profiles/ inside the resolved config directory rather than always ~/.claude. Identical with $CLAUDE_CONFIG_DIR unset; with it set, each config directory gets its own profiles. Set $CCSWITCH_HOME to a fixed path to share one set across all of them. legacy-fish is synced with the same three fixes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
8.0 KiB
Changelog
All notable changes to ccswitch are documented here. The format follows Keep a Changelog, and versions follow Semantic Versioning.
Unreleased
Fixed
-
Switching now works on headless and pure-SSH machines. Claude Code's macOS credential store is a composite — Keychain first, falling back to plaintext
~/.claude/.credentials.json, with a failed Keychain write migrating the credential into that file. Over SSH the login Keychain cannot be unlocked without a GUI prompt (securityexits 36,errSecInteractionNotAllowed), so Claude Code lives entirely in the file.ccswitchonly ever looked at the Keychain, sosavereported "no active credential" on a machine that was signed in,sync_currentsilently dropped rotated tokens, and a switch left~/.claude.jsonnaming the new account while the live token still belonged to the old one — which Claude Code reports as not logged in. The macOS store now mirrors Claude Code's arbitration and keeps exactly one authoritative copy: a successful Keychain write deletes the plaintext file, a failed one deletes the Keychain item, so a stale copy can never shadow the switch from the other kind of session. -
The Keychain
acctattribute is captured again.security find-generic-password -gprints attributes on stdout and the password on stderr;account_attrparsed stderr, so it always came back empty and every profile storedkeychain_account: "". (Writes fell through to$USER, which is what Claude Code looks items up by, so this was invisible.) -
$CLAUDE_CONFIG_DIRis honored. It moves.claude.jsonand the credential fallback, and — the part that is easy to miss — it renames the Keychain item: Claude Code namespaces the service with the first eight hex characters ofsha256($CLAUDE_CONFIG_DIR).ccswitchhardcoded"Claude Code-credentials", so with the variable set it read and wrote a different account's credential while patching the wrong config file. This affected ordinary use, becauseccswitch isolatelaunchesclaudewithCLAUDE_CONFIG_DIRset to the isolate directory. The related$CLAUDE_SECURESTORAGE_CONFIG_DIRand$CLAUDE_CODE_CUSTOM_OAUTH_URLfeed the same derivation and are honored too. -
The OAuth token no longer appears in
security's argv, wherepsexposed it to every user on the machine for the duration of a switch. It is now hex-encoded and piped tosecurity -i, with the same argv fallback Claude Code uses for a blob past the stdin limit. Account attributes are also sanitized the way Claude Code sanitizes them, so the two cannot end up addressing different items.
Changed
- Profile and isolate storage now default to
accounts/andprofiles/inside Claude Code's resolved config directory rather than always~/.claude. With$CLAUDE_CONFIG_DIRunset this is the same path as before. With it set, each config directory gets its own profiles; set$CCSWITCH_HOMEto a fixed path to share one set across all of them.
Added
$CCSWITCH_CREDENTIALS=file(orplaintext) forces the plaintext backend and skips the Keychain entirely — for a Mac you only ever reach over SSH.ccswitch savenow says when the Keychain is locked or unreachable, instead of reporting a reachable-but-empty store and a locked one identically.
[0.1.3] — 2026-07-16
Fixed
- Same-login, multi-org switching is no longer cosmetic. The default token
scope is now
PerAccountOrg(one credential per(account, org)), notPerAccount. A Claude Code OAuth token is bound server-side to the org it was minted under — it is opaque and the server re-derives the org from it at session start, overwriting~/.claude.json. The oldPerAccountscope shared one token across a login's orgs, sosync_currentpropagated one org's token into the sibling profile; every "switch" then only relabelled~/.claude.jsonwhile real sessions ran under the token's minting org. Each profile now keeps its own org-scoped token, andsync_currentre-snapshots only the outgoing profile. (Existing profiles saved before this release share one token and must be re-provisioned:claude /logininto the right org, thenccswitch save <name> --force.)
Removed
- The daemon-stop on switch (v0.1.1/v0.1.2). It addressed a misdiagnosis: there is no persistent Claude Code daemon holding auth, and stopping it never affected switching. v0.1.2's worker-kill also needlessly ended background sessions. Removed entirely.
[0.1.2] — 2026-07-08
Changed
- Daemon stop now includes session workers. v0.1.1 stopped only the daemon
supervisor (
--keep-workers), but a kept worker holds in memory the account it was started under — soclaude --resumereattached to the old worker and the switch appeared to have no effect (the resumed session kept the previous org). The switch now runsclaude daemon stop --any(no--keep-workers), so every subsequent session, resumed or fresh, picks up the switched account. Trade-off: switching ends any detached background Claude Code sessions.
[0.1.1] — 2026-07-08
Fixed
- Daemon-aware switching — recent Claude Code releases keep a background
daemon running that caches each account's auth in memory, so a profile switch
did not take effect until the daemon exited. Every switch (
useand the bareccswitch <name>form) now stops the daemon's supervisor first viaclaude daemon stop --any --keep-workers, so the next session re-reads the restored credentials while any detached background sessions keep running. It is best-effort: an older Claude Code, a missing binary, or no running daemon never blocks the switch (a warning is printed and the switch proceeds).
0.1.0 — 2026-07-08
First release of the Rust CLI, superseding the original fish plugin (now under
legacy-fish/).
Added
- Account switching —
save,use, and the bareccswitch <name> [args...]form snapshot both halves of a Claude Code identity (the OAuth credential and the~/.claude.jsonoauthAccount+userID) into a plain profile directory and restore them as a unit, launchingclaudeon the bare form. add— sign in to a new account (claude auth login) and save it in one step;--forceonadd/saveoverwrites an existing profile.list,current,rm— enumerate profiles (*marks the active one), show the active account, and delete a profile; with aliasesls,whoami, andremove/delete.- Token-rotation fix — on every switch the outgoing credential is
re-snapshotted into every profile that shares its per-account refresh
token (
TokenScope::PerAccount), so an actively used account never strands a sibling profile with a rotated-out token. - Concurrent sessions —
isolateruns a session under a per-profileCLAUDE_CONFIG_DIRwithprojects/,history.jsonl, andCLAUDE.mdsymlinked to a shared directory, andseedimports that shared memory from~/.claude(or a given dir). Empty shared memory triggers a confirm. search— bridges tocsx+fzfto fuzzy-pick and resume a past session, defaulting the scope to the active tool and resuming with the right command per tool (claude,codex).- Cross-shell completions —
completions <shell>for bash, zsh, fish, PowerShell, and elvish. - Cross-platform credentials — macOS Keychain via the
securitybinary, with a~/.claude/.credentials.jsonfile store fallback elsewhere. - Docs & distribution — README,
AGENTS.md, a GitHub release workflow with a cross-compile matrix, and an auto-bumped Homebrew cask.
Notes
- Test suite covers decision logic to ≥98% line and region; OS/network I/O
lives in
*_shim.rsfiles behind traits (seeAGENTS.md).