{"slug": "multiple-accounts-in-claude-code-the-complete-setup", "title": "Multiple accounts in Claude Code: the complete setup", "summary": "A developer documented a method for managing multiple Claude Code accounts by using the CLAUDE_CONFIG_DIR environment variable to create isolated config directories. The approach involves creating separate directories per account, setting shell aliases or a wrapper script, and authenticating each instance independently. The developer also highlighted pitfalls such as fragile absolute binary paths, shared project-level settings, and missing custom hooks in new config directories.", "body_md": "You have a personal Claude Code subscription and a work one. Or you freelance for two clients who each provide their own API key. Or you want a sandboxed account for experiments that won't pollute your main config.\n\nWhatever the reason, Claude Code doesn't ship with a built-in \"switch account\" command. But the architecture makes it straightforward: everything lives in a single config directory, and you can redirect it.\n\nClaude Code keeps all its state in `~/.claude`\n\nby default. That includes:\n\n`.claude/`\n\ninside each repo)The key insight: the ** CLAUDE_CONFIG_DIR** environment variable overrides where Claude Code looks for all of this. Point it somewhere else, and you get a completely independent instance.\n\nCreate one config directory per account:\n\n```\nmkdir -p ~/.claude-personal\nmkdir -p ~/.claude-work\n```\n\nFind your Claude binary path:\n\n```\nwhich claude\n# e.g. /Users/you/.nvm/versions/node/v22.15.0/bin/claude\n```\n\nAdd aliases to your `~/.zshrc`\n\n(or `~/.bashrc`\n\n):\n\n```\nalias claude-personal='CLAUDE_CONFIG_DIR=~/.claude-personal claude'\nalias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'\n```\n\nReload your shell:\n\n```\nsource ~/.zshrc\n```\n\nThen authenticate each one separately:\n\n```\nclaude-personal   # run /login inside the session\nclaude-work       # run /login inside the session\n```\n\nEach alias now opens Claude Code with its own auth, memory, and settings.\n\nThe alias trick works, but it has gaps that will bite you in production use.\n\nIf you hardcode the binary path in your alias (as many guides suggest), upgrading Node via NVM silently breaks it. Use just `claude`\n\ninstead of the absolute path, and let `$PATH`\n\nresolve it:\n\n```\n# fragile\nalias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work /Users/you/.nvm/versions/node/v22.15.0/bin/claude'\n\n# resilient\nalias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'\n```\n\nClaude Code creates a `.claude/`\n\ndirectory inside your project repo. That directory stores project settings, `CLAUDE.md`\n\n, and `settings.json`\n\n. These are shared across all your aliases because they live in the repo, not in the config dir.\n\nThis means your work account and personal account see the same project-level instructions. That's usually fine, but if you need different MCP servers or permissions per account per project, you'll need to handle it differently (see the wrapper script section below).\n\nIf you've configured custom hooks or MCP servers in `~/.claude/settings.json`\n\n, those won't exist in your new config directories. You'll need to copy or symlink the parts you want shared:\n\n```\n# share hooks across accounts\nln -s ~/.claude/settings.json ~/.claude-work/settings.json\n```\n\nOr, if you want different hooks per account, copy and customize:\n\n```\ncp ~/.claude/settings.json ~/.claude-work/settings.json\n```\n\nEach config directory has its own memory system. Your personal account won't remember what your work account learned. If you use memory-heavy workflows, that isolation is sometimes a feature, sometimes a problem.\n\nInstead of simple aliases, a small wrapper gives you account switching with validation:\n\n``` bash\n#!/usr/bin/env bash\n# Save as ~/bin/claude-switch and chmod +x\n\nACCOUNT=\"${1:?Usage: claude-switch <account-name> [claude args...]}\"\nshift\n\nCONFIG_DIR=\"$HOME/.claude-$ACCOUNT\"\n\nif [ ! -d \"$CONFIG_DIR\" ]; then\n  echo \"Account '$ACCOUNT' not found. Available accounts:\"\n  ls -d ~/.claude-* 2>/dev/null | sed 's|.*/.claude-||'\n  exit 1\nfi\n\nCLAUDE_CONFIG_DIR=\"$CONFIG_DIR\" exec claude \"$@\"\n```\n\nUsage:\n\n```\nclaude-switch work\nclaude-switch personal --resume\nclaude-switch work -p \"fix the login bug\"\n```\n\nThis passes all arguments through, so flags like `--resume`\n\n, `--print`\n\n, and `-p`\n\nall work.\n\nIf a specific repo should always use a specific account, you can set it in a `.envrc`\n\nfile (if you use [direnv](https://direnv.net)):\n\n```\n# /path/to/work-project/.envrc\nexport CLAUDE_CONFIG_DIR=\"$HOME/.claude-work\"\n```\n\nNow every time you `cd`\n\ninto that project and run `claude`\n\n, it automatically uses the work account. No alias needed.\n\nWithout direnv, you can add it to the project's shell history or a local `.env`\n\nfile that your shell sources.\n\nThere are two authentication modes in Claude Code, and they interact differently with multi-account setups:\n\n**OAuth (default):** You run `/login`\n\nand authenticate through Anthropic's web flow. The token is stored in the config directory. This is what most people use with Claude Pro/Max subscriptions.\n\n**API key:** You set `ANTHROPIC_API_KEY`\n\nas an environment variable. This bypasses the config directory's auth entirely.\n\nFor API key setups, you don't even need separate config directories for auth. You can just switch the key:\n\n```\nalias claude-client-a='ANTHROPIC_API_KEY=$CLIENT_A_KEY claude'\nalias claude-client-b='ANTHROPIC_API_KEY=$CLIENT_B_KEY claude'\n```\n\nBut you'll still want separate config directories if you need isolated memory, hooks, or MCP servers.\n\nThe most robust setup for freelancers or consultants:\n\n```\n# ~/.zshrc\nexport CLIENT_A_KEY=\"sk-ant-...\"  # or source from a secrets manager\n\nalias claude-client-a='ANTHROPIC_API_KEY=$CLIENT_A_KEY CLAUDE_CONFIG_DIR=~/.claude-client-a claude'\nalias claude-client-b='ANTHROPIC_API_KEY=$CLIENT_B_KEY CLAUDE_CONFIG_DIR=~/.claude-client-b claude'\n```\n\nEach client gets:\n\nYou can run multiple Claude Code instances in parallel, each in its own terminal tab. The config directories are independent, so there's no locking or conflict.\n\n```\n# Terminal 1\nclaude-work\n\n# Terminal 2\nclaude-personal\n```\n\nBoth sessions run concurrently without interference. This is useful when you're waiting on a long task in one account and want to work on something else in another.\n\n| What you want | What to set |\n|---|---|\n| Different auth | `CLAUDE_CONFIG_DIR` |\n| Different API key | `ANTHROPIC_API_KEY` |\n| Different memory | `CLAUDE_CONFIG_DIR` |\n| Different MCP servers |\n`CLAUDE_CONFIG_DIR` + custom `settings.json`\n|\n| Per-project default |\n`.envrc` with `CLAUDE_CONFIG_DIR`\n|\n| All of the above | Combined alias with both env vars |\n\nEverything above covers Claude Code (the CLI). If you also use the **Claude desktop app** and want two instances running side by side with different accounts, the approach is different: you need to duplicate the app itself.\n\nOn macOS, [Parallels Toolbox](https://www.parallels.com/products/toolbox/) can create an \"app shortcut\" that acts as a second copy of Claude. Each copy maintains its own login session, so you can run your work account in one window and your personal account in another, without logging in and out. [This walkthrough](https://youtu.be/IF1qZmCLWFk) shows the full setup.\n\nThe process: open Parallels Toolbox, create an app shortcut pointing to Claude, give it a distinct name (like \"Claude Work\"), approve it in macOS security settings, and log in with your second account. Both instances live in your dock and run independently.\n\nThis pairs well with the CLI multi-account setup: use `CLAUDE_CONFIG_DIR`\n\naliases for terminal work, and Parallels app shortcuts for the desktop GUI.\n\nTwo config directories: `~/.claude-personal`\n\nfor my own projects, `~/.claude-work`\n\nfor client work. Direnv handles the switching per project, so I just type `claude`\n\nand it picks the right account. I symlink `settings.json`\n\nfrom my personal config to the work one because I want the same hooks everywhere, but memory stays separate.\n\nThe total setup took five minutes. The part that took longest was realizing I needed to re-run `/login`\n\nin each config directory after creating it.\n\n*Originally published on jguillaumesio.com*", "url": "https://wpnews.pro/news/multiple-accounts-in-claude-code-the-complete-setup", "canonical_source": "https://dev.to/jguillaumesio/multiple-accounts-in-claude-code-the-complete-setup-10ek", "published_at": "2026-06-25 19:54:15+00:00", "updated_at": "2026-06-25 20:12:59.716018+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-tools"], "entities": ["Claude Code", "Anthropic", "NVM", "direnv"], "alternates": {"html": "https://wpnews.pro/news/multiple-accounts-in-claude-code-the-complete-setup", "markdown": "https://wpnews.pro/news/multiple-accounts-in-claude-code-the-complete-setup.md", "text": "https://wpnews.pro/news/multiple-accounts-in-claude-code-the-complete-setup.txt", "jsonld": "https://wpnews.pro/news/multiple-accounts-in-claude-code-the-complete-setup.jsonld"}}