Artificial Intelligence
Separate work and personal profiles in Claude Code with CLAUDE_CONFIG_DIR
Plenty of developers run Claude Code with two Claude accounts on one machine: the one the company pays for and their own. Claude Code keeps everything in a single folder, ~/.claude, so moving between accounts means signing out with /logout and back in with /login. Even then the rest stays mixed together: prompt history, transcripts, the memory Claude keeps for each project, personal MCP servers and settings.
The official documentation has an answer: one configuration folder per account, picked with the CLAUDE_CONFIG_DIR environment variable. This post covers what each profile holds, how to set one up in bash, zsh, PowerShell and cmd, how to check which one is active and, above all, what stays shared even with two profiles.
The idea: one configuration folder per account
The authentication page puts it this way: "To stay signed in to multiple accounts at once, such as work and personal accounts, give each account its own configuration directory". When claude starts, it reads CLAUDE_CONFIG_DIR; if the variable is not set, it uses ~/.claude. The same page sums up what each folder gets: "Each directory has its own settings, session history, and claude.ai login or API key".
The simplest version is an alias. Plain claude keeps ~/.claude as the personal profile and claude-work opens the work one. The first time claude-work runs, Claude Code asks for a login and goes through first-launch setup in the new folder. From then on each terminal uses the account of the command it was started with, and both sessions can be open at the same time.
What each profile holds
According to the page on the configuration directory, with the variable set every ~/.claude path moves to the new folder. So does .claude.json, which without the variable sits next to it, at ~/.claude.json. In a test with an empty folder, claude auth status created .claude.json inside the profile folder.
| What | Where, inside the profile |
|---|---|
/login session (claude.ai or Console key) | .credentials.json; on macOS, a Keychain entry tied to the folder |
| App state, account details, personal MCP servers | .claude.json |
User settings: permissions, hooks, env, model | settings.json |
| User instructions | CLAUDE.md, rules/ |
| Skills, commands, subagents and keybindings | skills/, commands/, agents/, keybindings.json |
| Installed plugins | plugins/ |
| Transcripts and auto memory for each project | projects/ |
| Prompt history | history.jsonl |
Auto memory lives under the profile's projects/, so whatever Claude learned about a repository under the work account does not show up when the same repository is opened with the personal one. Skills and plugins enabled on the claude.ai account follow the account: they load in terminal sessions signed in with it. Their local copy, though, follows the profile: Claude Code downloads them into ~/.claude/skills/synced/ and ~/.claude/plugins/synced/, paths that move into each profile's folder once the variable is set.
Where credentials go depends on the operating system. On Linux they sit in .credentials.json with mode 0600. On Windows they use the same file, which inherits the permissions of the user's home folder. On macOS they go to the Keychain, and the documentation says the variable splits that entry too: "so a session with a different CLAUDE_CONFIG_DIR reads a different entry". In the Windows test, Claude Code started signed out with a new folder, even though the machine's default profile had a session.
Setting up the profiles
The rule is the same in every shell: the variable applies to that one claude command, not to the rest of the terminal. The bash, PowerShell and cmd versions below were tested on Windows with empty folders and no login.
bash and zsh
The alias goes in ~/.bashrc or ~/.zshrc, and it is the one from the environment variables page:
alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'
Writing the assignment right before the command sets the variable for that command only. In the tests, the shell had no variable after claude-work returned, and when it already had a different value it kept it. The shell expands the ~ because it is not quoted: claude auth status showed the full path. Written in quotes, "~/.claude-work", the ~ is not expanded and Claude Code created a folder literally named ~ inside the current folder.
An alias only exists in an interactive terminal. A script that calls claude-work fails with "command not found"; there, the variable has to be written in front of claude.
PowerShell
The documentation has no PowerShell example for this. The following function, saved in $PROFILE, does what the alias does:
function claude-work {
$old = $env:CLAUDE_CONFIG_DIR
$env:CLAUDE_CONFIG_DIR = "$HOME\.claude-work"
try {
if ($MyInvocation.ExpectingInput) { $input | & claude @args } else { & claude @args }
} finally { $env:CLAUDE_CONFIG_DIR = $old }
}
It saves the old value, sets the variable, runs claude with the same arguments and puts the old value back in the finally block, which runs even when claude fails. In the tests the variable came back as it was in three cases: empty before, set to another folder before, and with claude missing from PATH. The exit code of claude still reaches $LASTEXITCODE.
When text comes in through a pipe, as in the documentation's cat logs.txt | claude -p "explain", the $MyInvocation.ExpectingInput check detects the pipe and the first branch hands the text to claude through $input; without that branch, the text would be dropped with no error. With no pipe, the other branch runs and claude keeps reading from the keyboard.
$PROFILE is a script, and on Windows client computers the default execution policy is Restricted, which per Microsoft's documentation runs no scripts, PowerShell profiles included. Under it the function never loads. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser changes that for the current user only: local scripts run and scripts downloaded from the internet need a signature. If the $PROFILE file does not exist yet, this line creates it, folder included, without emptying one that already exists:
if (-not (Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
A bare New-Item -Force $PROFILE, by contrast, emptied an existing $PROFILE file in the test.
What to avoid is assigning $env:CLAUDE_CONFIG_DIR directly in the console. That sets it for the whole PowerShell session, and every claude started later in that window opens the work profile.
cmd
In cmd the simplest route is a claude-work.cmd file in a folder on the PATH:
@echo off
setlocal
set "CLAUDE_CONFIG_DIR=%USERPROFILE%\.claude-work"
claude %*
setlocal keeps the variable alive only while the file runs. The console kept its previous value and, when it had none, stayed without the variable. The quotes on the set line let %USERPROFILE% contain spaces, and the exit code of claude reaches the console.
VS Code and Claude Desktop
In the VS Code extension the variable goes in claudeCode.environmentVariables, with one caveat: "the extension doesn't expand ~ and ignores a relative value". The path has to be absolute. In Claude Desktop it is set wherever the variables for dev servers are set, and then the app has to be quit and reopened. The Desktop documentation does not explain how to keep two accounts open at once.
Checking which profile is active
claude auth status prints JSON with a configDirectory field, naming the folder the CLI uses, and an authMethod field, naming the credential it signs in with. configDirectory has been there since version 2.1.268. This is the output from one of the tests, with an empty profile folder and a fake key in the shell's ANTHROPIC_API_KEY:
"loggedIn": true, "authMethod": "api_key", "apiKeySource": "ANTHROPIC_API_KEY", "configDirectory": "<TEMP>/cfg"
The output shows two things at once: the folder is the profile's, but the session signs in with the shell's key. Inside a session, /status shows which credential is in use and marks the one that is not. In the shell, echo $CLAUDE_CONFIG_DIR (or $env:CLAUDE_CONFIG_DIR) only tells whether the variable was set for the whole terminal. With the alias, the function or the .cmd file it prints nothing.
What a profile does not separate
Repository files
.claude/settings.json, .claude/settings.local.json, .mcp.json, CLAUDE.md and CLAUDE.local.md live in the project folder, and both profiles read the same ones. Approvals do too: answering "Yes, and don't ask again" to a command saves the rule in the repository's .claude/settings.local.json. An approval given under the personal profile also holds under the work profile in that repository.
The other way round, a repository cannot switch profiles. Since version 2.1.251 the env block in a project's .claude/settings.json no longer sets CLAUDE_CONFIG_DIR; the variable has to come from the shell, user settings or managed settings.
Company policies
Managed settings installed on the machine live outside the user's folder: /etc/claude-code/ on Linux and WSL, /Library/Application Support/ClaudeCode/ on macOS and C:\Program Files\ClaudeCode\ on Windows. If the work machine has policies, they apply to the personal profile on that machine too. Policies set in the claude.ai console, on the other hand, depend on the account used to sign in.
Shell environment variables
The credential precedence order puts environment variables such as ANTHROPIC_API_KEY above the profile's /login session. A key exported in .bashrc or $PROFILE is used by both profiles, as the output in the previous section shows.
git identity
Claude Code does not touch user.email, SSH keys or the configuration of other CLIs such as gh, aws or az. A commit made from the work profile carries whatever email git has configured for that repository. git solves this per folder with includeIf: a condition in ~/.gitconfig reads another file when the repository sits under a given folder.
# ~/.gitconfig
[user]
email = personal@example.com
# Every repository under ~/work/ also reads ~/.gitconfig-work
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
# ~/.gitconfig-work
[user]
email = work@example.com
The includeIf has to come after [user]: when two lines set the email, the last one git reads wins. In the test with the order reversed, the repository at ~/work/api got the personal email.
The git documentation says that a pattern ending in / gets ** added, so subfolders match too. Repositories at ~/work/api and ~/work/team/web got the work email; one at ~/workshop, which starts with the same letters, got the personal one. A worktree of ~/work/api checked out somewhere else also got the work email, because the condition looks at where the .git folder is. To keep Claude's Co-Authored-By line out of those commits as well, there is a hook that blocks it.
Console sign-in without a key
A Console account used without an API key is stored outside the configuration folder, in ~/.config/anthropic on macOS and Linux or %APPDATA%\Anthropic on Windows. The authentication page warns: "Separate directories don't keep two Claude Console sign-ins without an API key apart". For that case there is ANTHROPIC_PROFILE, which picks which of the sign-ins stored there is used.
Hooks with hardcoded paths
If the work profile's settings.json runs node ~/.claude/hooks/x.mjs, that path points at the default folder, not at the work profile. When a hook is copied to another profile, the path in its command has to change too. The hooks guide explains how hooks are registered.
Common mistakes with the second profile
Copying the whole ~/.claude to start with the same setup. The copy takes the session in .credentials.json, the account details and MCP servers in .claude.json, and the transcripts in projects/. The documentation warns: "Transcripts and history are not encrypted at rest". If a tool read a .env file or a command printed a credential, that value is in the transcript. It is safer to start with an empty folder and copy settings.json, CLAUDE.md, agents/, skills/ and commands/ by hand, after checking that settings.json holds no secrets in env or apiKeyHelper. The post on hardening Claude Code against data leaks covers what else can leave a session.
A relative path. In the test, CLAUDE_CONFIG_DIR=rel-cfg was read relative to the current folder and created an empty profile there. With a path like that, every folder claude is opened from gets its own signed-out profile. The path has to be absolute, or start with a ~ that the shell expands.
Other ways to handle two accounts
/logoutand/loginswitch accounts inside one profile, but never leave two accounts active at once, and logging out also resets first-launch setup.apiKeyHelper, in a profile'ssettings.json, is a command that returns the credential. It fits a work account whose secrets live in a vault.claude setup-tokencreates a one-year token for the subscription, passed inCLAUDE_CODE_OAUTH_TOKEN. It is meant for scripts and CI, not daily use.--settingsloads settings for a single session without touching any file. It does not change the account.
Frequently asked questions
Can CLAUDE_CONFIG_DIR be set in a settings.json?
Project and local settings ignore it. The documentation allows it in user and managed settings, with an absolute path, but the user settings file already sits inside a profile folder. That case was not tested for this post, which picks the profile from the shell.
Checked on November 16, 2026 against Claude Code 2.1.325 and the official documentation as of that date. The tests ran on Windows 11 with new folders and no login; bash was tested with Git Bash. Linux, macOS and its Keychain, zsh, the VS Code extension and Claude Desktop were not tested.
References
- Authentication: log in with multiple accounts (code.claude.com)
- Environment variables (code.claude.com)
- Explore the .claude directory (code.claude.com)
- Settings files and precedence (code.claude.com)
- CLI reference (code.claude.com)
- Use Claude Code in VS Code (code.claude.com)
- git-config, conditional includes (git-scm.com)
- Claude Code changelog (github.com)
Tags
Share this post
Subscribe
Get the latest posts delivered right to your inbox.
Leave a comment