I use Claude Code for my own work and for a client project that runs on its own Claude subscription. I don't want to log in and out, and I never want to spend the wrong account by accident. Here is the small setup that makes the right account follow the directory I'm in.
The trick: CLAUDE_CONFIG_DIR
Claude Code keeps its login, sessions and settings in ~/.claude. Point CLAUDE_CONFIG_DIR somewhere else and you get a completely separate
installation, with its own login.
mkdir ~/.claude-client
CLAUDE_CONFIG_DIR=~/.claude-client claude
Run /login once in that session and sign in with the project's account. From now on, everything started with that variable uses that account.
Automate with direnv
Typing the variable every time is the part you forget. direnv loads an .envrc whenever you cd into a directory, so put one in the folder that holds the project:
# ~/Projects/client/.envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-client"
cd ~/Projects/client
direnv allow
Now claude inside ~/Projects/client runs on the client account, and claude anywhere else runs on my personal one. No aliases, no wrapper scripts.
Worktrees and subfolders
I place the .envrc above the clients repositories, so every repository inherits it. A worktree that has its own .envrc (e.g. for a port or database) should start by loading the parent one:
# ~/Projects/client/app-123/.envrc
source_up_if_exists
export PORT=3001
Without that first line, the worktree quietly falls back to the personal account.
Shared skills and settings
A new config directory starts empty: no CLAUDE.md, no skills, no agents. I keep one setup in ~/.claude and link it into the other directory:
for entry in CLAUDE.md settings.json skills agents workflows; do
ln -s ~/.claude/$entry ~/.claude-client/$entry
done
The login and session history stay separate; the way I work stays the same.
Show the account in the status line
The last piece is a check I can see. My status line script prints the account and turns red when the account doesn't match the directory:
if [ "$CLAUDE_CONFIG_DIR" = "$HOME/.claude-client" ]; then
printf '\033[35mclient\033[0m'
elif [[ "$PWD" == "$HOME/Projects/client"* ]]; then
printf '\033[1;31m⚠ personal account\033[0m'
fi
That's it
- A config directory per account.
- An
.envrcthat setsCLAUDE_CONFIG_DIR. - Symlinks for the shared setup.
- A status line that tells you when something is off.
Four small pieces, and you will no longer burn tokens in the wrong subscription.