cd /news/ai-tools/using-separate-work-and-personal-cla… Β· home β€Ί topics β€Ί ai-tools β€Ί article
[ARTICLE Β· art-142152] src=segar.me β†— pub= topic=ai-tools verified=true sentiment=Β· neutral

Using Separate Work and Personal Claude Code Accounts on One Mac

A developer documented a method for running separate work and personal Claude Code accounts on a single Mac by setting the undocumented CLAUDE_CONFIG_DIR environment variable through direnv, which loads per-folder .envrc files so each directory selects its own profile. The setup requires installing direnv, adding the shell hook to ~/.zshrc, placing an .envrc exporting CLAUDE_CONFIG_DIR=~/.claude-work at the top of the work folder, and logging in once per profile, since Claude Code otherwise stores a single login in ~/.claude. The author warns that a missing shell hook fails silently, nested .envrc files replace the parent's unless source_up is added, and .envrc should be kept out of git.

by read4 min views1 publishedSep 29, 2026
Using Separate Work and Personal Claude Code Accounts on One Mac
Image: Segar (auto-discovered)

If you use Claude Code for work and personal projects, you have hit this limit: it assumes one signed-in account per machine. Switching from personal to work means logging out, logging back in through the browser, and remembering to reverse it later.

I wanted the folder to decide. Inside my work folder and any repo beneath it, Claude Code uses my work account. Everywhere else it uses my personal one. This post covers the setup.

The Problem with the Default Setup #

Claude Code keeps its login, settings, and history in ~/.claude. Each user has one of those directories, so each user gets one account. The environment variable CLAUDE_CONFIG_DIR points Claude Code at a different config directory. It is stable but undocumented. Set it to a new path and you get a separate profile with its own login.

Three things tripped me up:

  1. Setting the variable per folder needs a tool. Most guides use shell aliases likeclaude-work andclaude-personal . Those work, but you have to remember which one to type.
  2. A missing shell hook fails silently. I installed direnv, created the.envrc , randirenv allow , and saw nothing. No error appeared. The variable never got set because I had skipped the direnv hook in~/.zshrc .
  3. You can log into the wrong profile. With the variable unset, I signed into my work account in thedefault profile. Every repo on my machine then used my work account.

The Solution: CLAUDE_CONFIG_DIR + direnv #

direnv loads and unloads environment variables based on your current directory. An .envrc in a folder applies its exports to that folder and every subfolder. When you cd out, direnv unsets them.

Step 1: Install direnv and Hook It Into Your Shell

brew install direnv
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
exec zsh

The second line is the one I missed. Without the hook, direnv never runs when you change directories, and nothing tells you.

If you use bash, swap zsh for bash and add the line to ~/.bashrc.

Step 2: Add an .envrc to Your Work Folder

Put it at the top of the folder that holds your work repos. My layout:

~/matt/project1/
β”œβ”€β”€ .envrc
└── apps/
    β”œβ”€β”€ app1/
    β”œβ”€β”€ app2/
    └── ...
cd ~/path/to/your/work-folder
echo 'export CLAUDE_CONFIG_DIR=~/.claude-work' > .envrc
direnv allow

Every repo under that folder, including repos you add later, now uses the work profile.

Step 3: Verify the Variable Is Set

cd ~/path/to/your/work-folder/apps/some-repo
echo $CLAUDE_CONFIG_DIR     # β†’ /Users/you/.claude-work

cd ~/some/personal/repo
echo $CLAUDE_CONFIG_DIR     # β†’ (nothing)

You should also see a direnv: .../.envrc line each time you cd into the work folder. If it doesn't appear, return to Step 1.

Step 4: Log In Once Per Profile

  • Outside the work folder: runclaude and check/status . If it shows your work account, as mine did, run/logout , then/login with yourpersonal account.
  • Inside the work folder: runclaude and/login with yourwork account. This profile starts empty, so Claude Code prompts you.

Run /status in each location to confirm. After that, type claude and the folder picks the account.

Things Worth Knowing #

  • Nested .envrc files replace the parent's. direnv loads only the nearest.envrc . If a work repo has its own.envrc for app-specific variables, makesource_up its first line so it still inherits the work profile.
  • Keep .envrc out of git. Add it to.gitignore or your global gitignore so teammates don't inherit your local path.
  • Launch your editor from the terminal. direnv sets variables in your shell. To use Claude Code inside VS Code or Cursor, runcode . from inside the folder so the editor inheritsCLAUDE_CONFIG_DIR .
  • Each profile has its own settings. Settings, MCP servers, custom commands, and your globalCLAUDE.md live in the config directory. To share them, copy or symlink the files into~/.claude-work . Project-level.claude/ folders inside a repo behave the same under either account.
  • Update Claude Code on macOS. Claude Code stores credentials in the macOS Keychain instead of a file. Recent versions keep a separate Keychain entry for each config directory. If both profiles collapse onto the same account, runclaude update and log in again in each one.

Why This Works #

Claude Code reads CLAUDE_CONFIG_DIR at startup and keeps everything under that directory, including the pointer to its login. direnv sets the variable when you enter the work folder and clears it when you leave. Your folder layout then picks the account, which matches how I already sort work from personal.

Conclusion #

The setup takes one Homebrew install, one line in ~/.zshrc, one .envrc, and two logins. If echo $CLAUDE_CONFIG_DIR comes back empty inside your work folder, check the shell hook first.

Once it's in place, cd into a folder, type claude, and you're on the right account.

── more in #ai-tools 4 stories Β· sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/using-separate-work-…] indexed:0 read:4min 2026-09-29 Β· β€”