DEV Community

Adesoji1
Adesoji1

Posted on

How I Run Two Claude Code Accounts Side by Side in VS Code on Ubuntu Without Losing My History

How i run 2 vscodeI 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
Enter fullscreen mode Exit fullscreen mode

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-user with 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

and in VS Code:

{
  "name": "CLAUDE_CONFIG_DIR",
  "value": "/home/your-user/.claude-account2"
}
Enter fullscreen mode Exit fullscreen mode

Not this:

{
  "name": "CLAUDE_CONFIG_DIR",
  "value": "~/.claude-account2"
}
Enter fullscreen mode Exit fullscreen mode

This is one of the most important details in the whole setup.

You can find your real home directory with:

echo "$HOME"
Enter fullscreen mode Exit fullscreen mode

If it prints:

/home/your-user
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then I checked for active processes:

pgrep -af claude
pgrep -af code
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Then:

ls -ld "$HOME"/.claude*
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

At this point the structure is:

/home/your-user/
|
|-- .claude
|     `-- Account 1
|
`-- .claude-account2
      `-- Account 2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Auto memory is stored per project under:

~/.claude/projects/<project>/memory/
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And checked for memory directories:

find /home/your-user/.claude-account2/projects \
  -type d -name memory | head
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

The result I wanted was:

GOOD: Account 2 has no credentials yet
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I initialized it cleanly:

printf '{}\n' > /home/your-user/.claude-account2/.claude.json
chmod 600 /home/your-user/.claude-account2/.claude.json
Enter fullscreen mode Exit fullscreen mode

Then I launched Claude using the alternate config directory:

CLAUDE_CONFIG_DIR=/home/your-user/.claude-account2 \
claude
Enter fullscreen mode Exit fullscreen mode

I completed the first-run theme screen and signed in with the second Claude account.

After login, I checked:

/status
Enter fullscreen mode Exit fullscreen mode

and, where available:

/usage
Enter fullscreen mode Exit fullscreen mode

Then I exited:

/exit
Enter fullscreen mode Exit fullscreen mode

Finally:

ls -l /home/your-user/.claude-account2/.credentials.json
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

without touching normal VS Code.

7. Create a separate VS Code user-data directory

mkdir -p /home/your-user/.config/Code-Claude-Account2/User
Enter fullscreen mode Exit fullscreen mode

My two VS Code states now look like:

Normal VS Code:
~/.config/Code

Account 2 VS Code:
~/.config/Code-Claude-Account2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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}"
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 \
    "$@"
Enter fullscreen mode Exit fullscreen mode

Then:

chmod 700 /home/your-user/.local/bin/code-claude2
Enter fullscreen mode Exit fullscreen mode

and:

which code-claude2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Search for:

Settings Sync
Enter fullscreen mode Exit fullscreen mode

If VS Code shows:

Settings Sync: Turn Off
Enter fullscreen mode Exit fullscreen mode

I run it.

If it offers:

Turn On Settings Sync
Enter fullscreen mode Exit fullscreen mode

or:

Backup and Sync Settings
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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 \
    "$@"
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

In the integrated terminal:

echo "$CLAUDE_CONFIG_DIR"
Enter fullscreen mode Exit fullscreen mode

It should print exactly:

/home/your-user/.claude-account2
Enter fullscreen mode Exit fullscreen mode

Then:

claude auth status
Enter fullscreen mode Exit fullscreen mode

Open the Claude Code panel and run:

/status
Enter fullscreen mode Exit fullscreen mode

or:

/usage
Enter fullscreen mode Exit fullscreen mode

That should show Account 2.

I also checked:

/memory
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

It should normally print nothing.

Claude then falls back to:

~/.claude
Enter fullscreen mode Exit fullscreen mode

which is Account 1.

A useful rule is:

Do not export the Account 2 CLAUDE_CONFIG_DIR globally 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 .
Enter fullscreen mode Exit fullscreen mode

Or directly:

code /home/your-user/projects/my-app
Enter fullscreen mode Exit fullscreen mode

Flow:

code .
  |
  v
Normal VS Code
  |
  v
Claude Account 1
Enter fullscreen mode Exit fullscreen mode

Open the same project with Account 2

From inside the project:

cd /home/your-user/projects/my-app
code-claude2 .
Enter fullscreen mode Exit fullscreen mode

Or directly:

code-claude2 /home/your-user/projects/my-app
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

It does not automatically know that I wanted Account 2.

For Account 2, I either use:

code-claude2 /path/to/project
Enter fullscreen mode Exit fullscreen mode

or create a separate Ubuntu desktop launcher called something like:

VS Code - Claude Account 2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Save it as:

~/.local/share/applications/vscode-claude-account2.desktop
Enter fullscreen mode Exit fullscreen mode

Then:

chmod +x ~/.local/share/applications/vscode-claude-account2.desktop
Enter fullscreen mode Exit fullscreen mode

That gives me two obvious graphical entry points:

Visual Studio Code
VS Code - Claude Account 2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)='
Enter fullscreen mode Exit fullscreen mode

and:

grep -nH \
  'ANTHROPIC_API_KEY\|ANTHROPIC_AUTH_TOKEN\|ANTHROPIC_BASE_URL' \
  ~/.bashrc ~/.profile ~/.bash_profile 2>/dev/null
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And for any project:

Want Claude Account 1?
code /path/to/project

Want Claude Account 2?
code-claude2 /path/to/project
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)