How to switch Claude accounts (without logging out)
Running a work and a private Claude account on the same machine - and how to make it fully automatic per project
I use Claude Code for work. I also use it privately, for side projects and experiments. Two accounts, one machine - and the one question how to keep those things separate.
The trick: CLAUDE_CONFIG_DIR
It turns out Claude Code reads its config directory from an environment variable called CLAUDE_CONFIG_DIR. Everything that makes up an account - auth token, settings, history, project state - lives in that directory. So pointing Claude at a different directory gives you a fully isolated second installation:
CLAUDE_CONFIG_DIR="$HOME/.claude-private" claude
Run /login once inside that directory and you have two accounts living side by side. One account stays on the default directory, the other gets its own. They never collide, and you can even run both at the same time in two terminals.
Credit where credit is due
After I figured this out, someone pointed me to a blog post by Christian Dangl - many will know him from the Shopware community - who wrote up exactly this setup in Company and private Claude on one machine: the five-minute fix. His post covers the whole thing in more depth than I will here, including the gotchas (a separate config dir is a fresh install, so your skills and MCP servers don’t carry over; macOS Keychain can be involved in credential storage). If you want the full walkthrough, go read his post - it’s good.
My small addition: make it automatic per project
Christian’s post suggests aliases, and that’s what I went with for the general case:
alias claude-private='CLAUDE_CONFIG_DIR="$HOME/.claude-private" claude'
So claude is my work account, claude-private is my private one. Simple.
But then I noticed something: most of my directories map 1:1 to one account. My private projects are always private. So why type the right command at all? This is what direnv is for. In a private project, I just drop an .envrc into the project root:
# .envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-private"
Then allow it once:
direnv allow
From now on, every shell I open in that directory automatically has CLAUDE_CONFIG_DIR set. Whichever way I start Claude from there, it picks up the private account. Leave the directory, and it’s unset again. No aliases to remember, no wrong-account mistakes.
The nice surprise: this also works with editors that load the project environment. I tested it with Zed - when I open a project that has this .envrc, the integrated agent panel starts Claude with my private account, no extra configuration needed. The project itself decides which identity it belongs to.
Take away
One environment variable, one directory per account, and you never log out again. For the general case, a claude-private alias is enough. For projects that are clearly tied to one account, an .envrc with direnv allow makes the switch fully automatic - in the terminal and even in editors like Zed. And if you want the deeper version of this story, Christian’s post has you covered.