Skip to main content
Glama
claude-account-switcher

claude-account-switcher

by mannudev97
README.md
# claude-account-switcher

Switch between **your own** Claude Code accounts on macOS (for example personal and work, or a Pro plan and a Team seat) **without losing your conversations or memory**.

Claude Code has no built-in account switcher in the Desktop app. Signing out and in again works, but it's easy to lose track of logins and settings. This tool saves each account as a named profile and swaps between them in one command. It works for both the Terminal `claude` CLI and the Desktop app, because both read `~/.claude.json`, `~/.claude/` and the macOS Keychain.

> **Use it only with accounts that belong to you.** Sharing a Claude account, or signing into someone else's account to get past your usage limits, is against Anthropic's terms and can get the accounts suspended. If you keep hitting limits, look at a higher plan, extra usage, or an API key.

## How it works

- **Profiles** keep a copy of `~/.claude.json`, and optionally your conversations (`~/.claude/projects`, `~/.claude/sessions`).
- **Login tokens stay in the macOS Keychain.** They're saved under the Keychain service `ClaudeAccountSwitcher` (one item per profile), never in plain files. They're written through `security -i` on stdin, so they never show up in a process's command-line arguments.
- **Default switch = login only.** Your conversations, memory, settings, plugins and MCP servers stay exactly where they are, and only the account changes. Per-account caches in `~/.claude.json` are cleared so Claude Code fetches fresh ones for the new account.
- **Tokens stay fresh.** Claude Code refreshes OAuth tokens over time. When you switch away from an account, its profile is updated with the latest token first, so switching back doesn't hand you an expired login.
- **Backups:** every switch first backs up your config and conversations to `~/Library/Application Support/ClaudeAccountSwitcher/backups/` (the latest 10 are kept).

## Install

Requires macOS and Node 18+.

```bash
git clone https://github.com/mannudev97/claude-account-switcher.git
cd claude-account-switcher
./install.sh
```

This builds the CLI, links `claude-switch` globally, and registers the MCP server with Claude Code (if the `claude` CLI is on your PATH; otherwise it prints the JSON to add yourself).

## Usage

```bash
claude-switch save work            # save the account you're signed into
# In Claude Code, sign out and sign in with your other account, then:
claude-switch save personal

claude-switch list                 # * marks the active profile
claude-switch info                 # signed-in account + Keychain status

claude-switch use work             # switch login; conversations stay
claude-switch use personal --full  # also swap conversations (see below)

claude-switch backup               # manual backup
claude-switch delete old           # remove a profile and its saved login
```

**Quit Claude Code completely (Cmd+Q) before switching, and reopen it afterwards.** If Claude Code is running while you switch, it may write its old settings back over the new ones.

### Login only (default) vs `--full`

| | Default | `--full` |
|---|---|---|
| Account / login | switched | switched |
| Conversations + memory | **kept, shared by both accounts** | replaced with the profile's copy |
| Settings, MCP servers, plugins | kept | config replaced with the profile's copy |

With `--full`, the current conversations are saved to the outgoing profile before the swap, so nothing is lost. You can switch back with `--full` to get them again.

## Inside Claude Code (MCP)

Ask things like "list my saved accounts" or "save this account as work". Tools: `current_account`, `list_profiles`, `save_profile`, `switch_profile`, `backup_current`, `delete_profile`, `list_projects`, `list_sessions`, `clear_keychain` (signs you out; requires `confirm: true`).

Tool calls run one at a time, so overlapping requests can't interleave. Remember that a switch needs a Claude Code restart to take effect.

## Keychain prompts

macOS may ask whether `security` can access a Claude Code Keychain item. Click **Allow** (or **Always Allow**). After a switch, Claude Code itself may ask once to access its login item, because the item was rewritten. No `sudo` is needed.

## Testing

The test suite runs everything against a throwaway home folder and a fake `security` command, so it never touches your real account or Keychain:

```bash
npm test
```

## Known limits

- macOS only.
- Profiles with `--full` copies of conversations can take a lot of disk space.
- `--symlink` mode from v0.2 was removed because it hid `~/.claude` settings and plugins. If you used it, the next `save` or `use` turns the symlinks back into real files.
- Upgrading from v0.2: old `keychain.json` token files in profiles are moved into the Keychain and deleted the first time each profile is used. Delete old backups in `~/Library/Application Support/ClaudeAccountSwitcher/backups/` yourself, because v0.2 backups may contain plain token files.

## Uninstall

```bash
npm unlink -g claude-account-switcher
claude mcp remove claude-account-switcher
```

Then delete `~/Library/Application Support/ClaudeAccountSwitcher`, and remove the `ClaudeAccountSwitcher` items in Keychain Access if you want the saved logins gone.