I wanted a very specific setup on my Ubuntu machine: two different Claude accounts, both usable from the Claude Code VS Code extension, without repeatedly logging one account out to use the other.
I also wanted to keep the local Claude Code history and memory I had already built up, and I did not want the second account to interfere with my normal VS Code profile.
The setup that worked for me is simple once the pieces are separated properly:
Normal VS Code
|
v
~/.claude
|
v
Claude Account 1
VS Code launched with code-claude2
|
v
~/.claude-account2
|
v
Claude Account 2
The important idea is that Claude Code already supports a custom configuration directory through CLAUDE_CONFIG_DIR. Anthropic documents this variable as an override for the default ~/.claude directory and specifically notes that it is useful for running multiple accounts side by side.
VS Code also supports --user-data-dir, which lets you run isolated VS Code instances with separate settings, environment variables, extensions, and UI state.
Putting those two features together gives each Claude account its own home without requiring two Linux users or two separate installations of VS Code.
Important: This is the setup I used on Ubuntu with Bash and the Claude Code VS Code extension. Replace
/home/your-userwith your actual absolute home path.
The problem this solves
The obvious way to use two Claude accounts is to keep logging out and logging back in.
I did not want that.
Logging in and out of the same Claude profile means both identities are sharing the same configuration location. That creates unnecessary risk around credentials, session state, local history, and memory.
I wanted this instead:
ACCOUNT 1 ACCOUNT 2
--------- ---------
Own Claude login Own Claude login
Own Claude config Own Claude config
Own VS Code state Own VS Code state
Existing history Copied starting history
Existing memory Copied starting memory
No logout required No logout required
I also wanted both accounts to be able to open the same Git repository.
That means the source code remains in one place. Only Claude's account state and the second VS Code profile are isolated.
A GitHub issue you should know about before setting this up
There is an open Claude Code issue, anthropics/claude-code #78988, about CLAUDE_CONFIG_DIR values that contain a literal ~.
The reported problem is easy to miss.
If Claude Code receives something like this literally:
CLAUDE_CONFIG_DIR=~/.claude-account2
through a path where the shell does not expand ~, Claude Code can interpret it as a relative path. The issue report shows Claude creating a directory literally named ~ inside the current project and writing configuration data there.
That can include session transcripts, history, backups, and other Claude data.
The issue was still open when I checked it on 5 September 2026.
The fix I used
I never pass a tilde to CLAUDE_CONFIG_DIR.
I use the full absolute path:
CLAUDE_CONFIG_DIR=/home/your-user/.claude-account2
and in VS Code:
{
"name": "CLAUDE_CONFIG_DIR",
"value": "/home/your-user/.claude-account2"
}
Not this:
{
"name": "CLAUDE_CONFIG_DIR",
"value": "~/.claude-account2"
}
This is one of the most important details in the whole setup.
You can find your real home directory with:
echo "$HOME"
If it prints:
/home/your-user
use that absolute path everywhere in the Account 2 configuration.
Part 1: Preserve the existing Claude Code data
1. Close active Claude Code sessions
I first stopped active Claude sessions and closed VS Code before copying anything.
For the CLI:
/exit
Then I checked for active processes:
pgrep -af claude
pgrep -af code
I did not start killing processes blindly. The goal was simply to avoid copying files while Claude was actively writing to them.
2. Back up the original Claude profile
My original Claude profile stays in the default location:
/home/your-user/.claude
Before touching it, I made a timestamped backup:
STAMP=$(date +%Y%m%d-%H%M%S)
cp -a "$HOME/.claude" \
"$HOME/.claude-backup-$STAMP"
echo "Backup created at: $HOME/.claude-backup-$STAMP"
Then:
ls -ld "$HOME"/.claude*
I kept the original .claude directory exactly where it was. Account 1 would continue using it.
3. Create a second Claude configuration directory
mkdir -p /home/your-user/.claude-account2
chmod 700 /home/your-user/.claude-account2
At this point the structure is:
/home/your-user/
|
|-- .claude
| `-- Account 1
|
`-- .claude-account2
`-- Account 2
Part 2: Copy history and memory without copying Account 1's login
Claude Code stores local conversation transcripts under:
~/.claude/projects/<project>/<session-id>.jsonl
Auto memory is stored per project under:
~/.claude/projects/<project>/memory/
Anthropic's documentation describes those session transcripts as local JSONL files and auto memory as machine-local project memory.
That was useful for me because I wanted Account 2 to start with a copy of the local context I had already built.
4. Copy the useful data
The critical rule is this:
Do not copy Account 1's authentication credentials into Account 2.
I used rsync and excluded credentials and disposable runtime state.
A clean version of the copy command is:
rsync -a \
--exclude='.credentials.json' \
--exclude='backups/' \
--exclude='ide/' \
--exclude='sessions/' \
--exclude='session-env/' \
--exclude='shell-snapshots/' \
--exclude='debug/' \
--exclude='remote-settings.json' \
--exclude='policy-limits.json' \
/home/your-user/.claude/ \
/home/your-user/.claude-account2/
Why exclude backups/?
During my first pass I copied the backup directory. Claude then found an old .claude.json backup from Account 1 and suggested restoring it into Account 2. I did not want Account 1's application or OAuth state becoming the starting state for Account 2.
Excluding the backup directory avoids that confusion.
5. Verify that history and memory actually copied
Compare the sizes:
du -sh /home/your-user/.claude/projects
du -sh /home/your-user/.claude-account2/projects
In my case the directories were roughly the same size, which was a good sign.
I also checked the file counts:
find /home/your-user/.claude/projects -type f | wc -l
find /home/your-user/.claude-account2/projects -type f | wc -l
And checked for memory directories:
find /home/your-user/.claude-account2/projects \
-type d -name memory | head
The two copies do not need to be byte-for-byte identical, especially if runtime files were excluded.
6. Make sure Account 2 has no credentials yet
Before logging Account 2 in:
test -f /home/your-user/.claude-account2/.credentials.json \
&& echo "STOP: credentials already exist" \
|| echo "GOOD: Account 2 has no credentials yet"
The result I wanted was:
GOOD: Account 2 has no credentials yet
Never print the contents of .credentials.json to the terminal or paste it into a chat.
Part 3: Give Account 2 a clean Claude state and log it in
On my installation, Claude expected an Account 2 state file at:
/home/your-user/.claude-account2/.claude.json
I initialized it cleanly:
printf '{}\n' > /home/your-user/.claude-account2/.claude.json
chmod 600 /home/your-user/.claude-account2/.claude.json
Then I launched Claude using the alternate config directory:
CLAUDE_CONFIG_DIR=/home/your-user/.claude-account2 \
claude
I completed the first-run theme screen and signed in with the second Claude account.
After login, I checked:
/status
and, where available:
/usage
Then I exited:
/exit
Finally:
ls -l /home/your-user/.claude-account2/.credentials.json
At that point the account separation was real:
ACCOUNT 1
/home/your-user/.claude
|
|-- .credentials.json
`-- projects/
ACCOUNT 2
/home/your-user/.claude-account2
|
|-- .credentials.json
|-- .claude.json
`-- projects/
Part 4: Make the VS Code extension use Account 2
This was the part that mattered most to me because I use the Claude Code VS Code extension much more than the CLI.
VS Code can launch a completely separate user-data environment with --user-data-dir.
That means the second VS Code instance can have its own:
Settings
Extensions
UI state
Environment
Claude extension state
without touching normal VS Code.
7. Create a separate VS Code user-data directory
mkdir -p /home/your-user/.config/Code-Claude-Account2/User
My two VS Code states now look like:
Normal VS Code:
~/.config/Code
Account 2 VS Code:
~/.config/Code-Claude-Account2
8. Configure the Claude extension in Account 2
The Account 2 VS Code settings file is:
/home/your-user/.config/Code-Claude-Account2/User/settings.json
I use:
{
"claudeCode.environmentVariables": [
{
"name": "CLAUDE_CONFIG_DIR",
"value": "/home/your-user/.claude-account2"
}
],
"claudeCode.preferredLocation": "panel",
"window.title": "CLAUDE ACCOUNT 2 | ${activeEditorShort}${separator}${rootName}"
}
The custom window title is optional, but I like it because it makes it difficult to forget which VS Code window I am using.
Notice the absolute path again:
/home/your-user/.claude-account2
No ~.
Anthropic documents claudeCode.environmentVariables as a supported extension setting for environment variables passed to the Claude process.
Part 5: Create a dedicated code-claude2 launcher
I created:
/home/your-user/.local/bin/code-claude2
with:
#!/usr/bin/env bash
set -e
export CLAUDE_CONFIG_DIR="/home/your-user/.claude-account2"
CODE_BIN="$(command -v code)"
if [ -z "$CODE_BIN" ]; then
echo "Error: VS Code 'code' command not found in PATH."
exit 1
fi
exec "$CODE_BIN" \
--user-data-dir="/home/your-user/.config/Code-Claude-Account2" \
--new-window \
"$@"
Then:
chmod 700 /home/your-user/.local/bin/code-claude2
and:
which code-claude2
The result should point to the new launcher.
Why set CLAUDE_CONFIG_DIR in both the launcher and the extension settings?
I wanted the separation to be obvious at both levels:
code-claude2
|
|-- VS Code process gets CLAUDE_CONFIG_DIR
|
`-- Claude extension gets CLAUDE_CONFIG_DIR
Part 6: Keep Settings Sync off in Account 2
This deserves its own section.
I do not want Account 2's special VS Code settings syncing back into my normal VS Code environment.
In the Account 2 VS Code window:
Ctrl+Shift+P
Search for:
Settings Sync
If VS Code shows:
Settings Sync: Turn Off
I run it.
If it offers:
Turn On Settings Sync
or:
Backup and Sync Settings
then Sync is already off.
VS Code's documentation confirms that Settings Sync is something you explicitly turn on and that the Settings Sync: Turn off command disables it.
GitHub login is still fine
I can sign the second VS Code profile into the same GitHub account I normally use.
GitHub authentication and VS Code Settings Sync are separate concerns.
I use GitHub authentication for:
Clone
Pull
Push
Fetch
GitHub extensions
Repository access
but I leave Settings Sync off in the Account 2 VS Code profile.
When VS Code offers to enable Backup and Sync Settings, I decline it.
Optional extra protection
Check whether your VS Code build supports a --sync argument:
code --help | grep -A2 -B2 -- '--sync'
If your build explicitly shows support for --sync off, you can add it to the Account 2 launcher:
exec "$CODE_BIN" \
--user-data-dir="/home/your-user/.config/Code-Claude-Account2" \
--sync off \
--new-window \
"$@"
I would only add this after checking code --help on the machine. The important baseline is still the isolated --user-data-dir and keeping Settings Sync turned off in that profile.
Part 7: Verify the second VS Code before trusting it
Launch a project:
cd /home/your-user/projects/my-app
code-claude2 .
In the integrated terminal:
echo "$CLAUDE_CONFIG_DIR"
It should print exactly:
/home/your-user/.claude-account2
Then:
claude auth status
Open the Claude Code panel and run:
/status
or:
/usage
That should show Account 2.
I also checked:
/memory
and Session History to confirm the copied local context was available.
Will Account 2 see my old Claude Code sessions?
It can see the local history that was copied into its own projects/ directory, provided the project path matches.
Claude Code stores sessions using the project or working directory. If an old session was created from:
/home/your-user/projects/my-app
open that same project path when checking Session History.
Opening a duplicate of the repository from another path can make Claude treat it as a different project.
Also remember that the initial copy is a snapshot.
After the split:
Account 1 memory Account 2 memory
| |
v v
changes independently changes independently
| |
+----------- no automatic --------+
sync
I do not continuously rsync the two Claude directories back and forth. That could overwrite newer sessions, state, or credentials.
Project-level files such as CLAUDE.md that live inside the repository are naturally shared because both VS Code instances are opening the same source tree.
If I click the normal VS Code icon, which Claude account opens?
This is one of the questions I wanted answered clearly before relying on the setup.
My normal VS Code icon still launches the default VS Code environment.
Assuming I have not globally exported CLAUDE_CONFIG_DIR in .bashrc, normal VS Code uses Claude's default config:
Normal VS Code icon
|
v
~/.config/Code
|
v
No custom CLAUDE_CONFIG_DIR
|
v
~/.claude
|
v
Claude Account 1
That means clicking my ordinary VS Code icon opens the setup for Account 1.
I can verify this in normal VS Code with:
echo "$CLAUDE_CONFIG_DIR"
It should normally print nothing.
Claude then falls back to:
~/.claude
which is Account 1.
A useful rule is:
Do not export the Account 2
CLAUDE_CONFIG_DIRglobally in.bashrc.
The Account 2 override belongs in the Account 2 launcher and Account 2 VS Code settings only.
How I choose which Claude account opens a project
This is the part that makes the whole setup easy to live with.
Open a project with Account 1
From inside the project:
cd /home/your-user/projects/my-app
code .
Or directly:
code /home/your-user/projects/my-app
Flow:
code .
|
v
Normal VS Code
|
v
Claude Account 1
Open the same project with Account 2
From inside the project:
cd /home/your-user/projects/my-app
code-claude2 .
Or directly:
code-claude2 /home/your-user/projects/my-app
Flow:
code-claude2 .
|
v
Isolated VS Code
|
v
/home/your-user/.config/Code-Claude-Account2
|
v
CLAUDE_CONFIG_DIR=/home/your-user/.claude-account2
|
v
Claude Account 2
Both VS Code instances can open the same Git repository.
I just avoid asking both Claude sessions to edit the same file at the same moment.
One thing to be careful about when opening folders graphically
This is easy to forget.
If I double-click a folder or file in Ubuntu and choose Open with Visual Studio Code, Ubuntu normally launches the standard VS Code application.
In my setup that means:
Graphical "Open with Visual Studio Code"
|
v
Normal VS Code
|
v
Claude Account 1
It does not automatically know that I wanted Account 2.
For Account 2, I either use:
code-claude2 /path/to/project
or create a separate Ubuntu desktop launcher called something like:
VS Code - Claude Account 2
A desktop file can look like this:
[Desktop Entry]
Name=VS Code - Claude Account 2
Comment=Visual Studio Code using Claude Account 2
Exec=/home/your-user/.local/bin/code-claude2 %F
Icon=visual-studio-code
Terminal=false
Type=Application
Categories=Development;IDE;
StartupNotify=true
Save it as:
~/.local/share/applications/vscode-claude-account2.desktop
Then:
chmod +x ~/.local/share/applications/vscode-claude-account2.desktop
That gives me two obvious graphical entry points:
Visual Studio Code
VS Code - Claude Account 2
What about GitHub in the second VS Code?
I use the same GitHub account in both VS Code environments.
In Account 2 I can sign into GitHub from Source Control or when VS Code needs authentication for a pull or push.
The key distinction is:
GitHub sign-in OK
Settings Sync Keep OFF
Claude Account 2 path Keep isolated
Signing into GitHub does not mean I have to turn on Settings Sync.
A quick safety check for API environment variables
If an Anthropic API key is exported globally, it can change which authentication method Claude uses.
I check:
env | grep -E '^ANTHROPIC_(API_KEY|AUTH_TOKEN|BASE_URL)='
and:
grep -nH \
'ANTHROPIC_API_KEY\|ANTHROPIC_AUTH_TOKEN\|ANTHROPIC_BASE_URL' \
~/.bashrc ~/.profile ~/.bash_profile 2>/dev/null
For a normal Claude subscription login, I do not want an unexpected API key overriding it.
Never paste an actual API key or .credentials.json contents into a blog, issue, chat, or screenshot.
The final workflow
This is what I ended up with:
UBUNTU
|
+-----------+-----------+
| |
v v
NORMAL VS CODE ACCOUNT 2 VS CODE
code . code-claude2 .
| |
v v
~/.config/Code ~/.config/Code-Claude-Account2
| |
v v
~/.claude ~/.claude-account2
| |
v v
Claude Account 1 Claude Account 2
| |
v v
GitHub as normal GitHub as normal
Settings Sync as Settings Sync OFF
I normally prefer
And for any project:
Want Claude Account 1?
code /path/to/project
Want Claude Account 2?
code-claude2 /path/to/project
No logout.
No account swapping inside one Claude profile.
No second Linux user.
No duplicate source repository required.
Final checklist
Before I considered the setup finished, I checked all of these:
[ ] Account 1 still uses /home/your-user/.claude
[ ] Account 2 uses /home/your-user/.claude-account2
[ ] Account 1 and Account 2 each have their own .credentials.json
[ ] Account 2 started with copied project history and memory
[ ] CLAUDE_CONFIG_DIR always uses an absolute path
[ ] Account 2 VS Code uses its own --user-data-dir
[ ] echo "$CLAUDE_CONFIG_DIR" in Account 2 prints the Account 2 path
[ ] /status or /usage confirms the correct Claude account
[ ] Settings Sync remains OFF in Account 2
[ ] Normal VS Code still opens Account 1
[ ] code . opens Account 1
[ ] code-claude2 . opens Account 2
[ ] Graphical folder opening is treated as Account 1 unless I use the Account 2 launcher
For me, that is the cleanest way to run two Claude Code identities side by side on one Ubuntu workstation.
The main lesson is that the accounts themselves are not the difficult part. The important part is isolating the state around them: Claude's config directory, VS Code's user-data directory, and the environment variable that connects the two.
Once those are separate, switching accounts becomes nothing more than choosing the right launcher.
Sources and further reading
Anthropic, Claude Code environment variables
https://code.claude.com/docs/en/env-vars
Anthropic, Claude Code in VS Code
https://code.claude.com/docs/en/vs-code
Anthropic, Claude Code memory
https://code.claude.com/docs/en/memory
Anthropic, Claude Code sessions
https://code.claude.com/docs/en/sessions
Visual Studio Code command line documentation
https://code.visualstudio.com/docs/configure/command-line
Visual Studio Code Settings Sync documentation
https://code.visualstudio.com/docs/configure/settings-sync
Claude Code GitHub issue #78988
https://github.com/anthropics/claude-code/issues/78988
Top comments (0)