# Running Multiple Claude Code Accounts on One Linux Server

You can run multiple Claude Code accounts on one Linux server, side by side, each with an environment variable and an alias. No logging out, no second machine, no hacks.

I run Claude Code on a headless homelab server and needed a second account for a separate stream of work. Claude Code only keeps one login per user, and switching meant running `/logout` and `/login` every time. Here's the setup I ended up with, plus a script that does it for you.

## Why not just use the desktop app?

Fair question. The Claude desktop app can run Claude Code on a remote server over SSH. If you have two machines, each signed in to a different account, both can connect to the same server and you don't need anything in this post.

That breaks down quickly, though:

*   **The desktop app holds one account at a time.** On a single laptop, you're back to logging out and in every time you switch.
    
*   **The work lives on your desktop's connection.** Close the laptop and the sessions stop. Here, both accounts run on the server in tmux and keep going after you disconnect.
    
*   **You can check in from anywhere.** Any SSH client works, including your phone. No desktop app needed.
    
*   **Plenty of setups have no desktop app at all.** Terminal-only workflows, unsupported Linux distros, scripts and automation all go through the CLI.
    

So this is for one specific setup: one machine, a server you SSH into, and two or more accounts running side by side on that server.

## How it works

Claude Code keeps everything about an account in one folder, `~/.claude` by default: the login, settings, session history and your custom setup. The `CLAUDE_CONFIG_DIR` environment variable tells it to use a different folder instead.

Point it at a new folder and you get a completely separate account:

| Command | Config folder | Account |
| --- | --- | --- |
| `claude` | `~/.claude` | Your existing account |
| `claude2` | `~/.claude2` | The second account |

Same binary, two independent logins, two separate session histories.

## The manual setup: three steps

This assumes Claude Code is already installed and logged in to your first account.

### 1\. Add an alias for the second account

```bash
echo "alias claude2='CLAUDE_CONFIG_DIR=\$HOME/.claude2 claude'" >> ~/.bashrc
source ~/.bashrc
```

Using zsh? Put it in `~/.zshrc` instead.

**SSH gotcha:** this bit me the next day. `claude2` worked fine, then after a fresh SSH login I got `claude2: command not found`. SSH starts a login shell, which reads `~/.bash_profile` or `~/.profile`, and on some systems those don't load `~/.bashrc` at all. Fix it once:

```bash
grep -qs bashrc ~/.bash_profile ~/.profile || echo '[ -f ~/.bashrc ] && . ~/.bashrc' >> ~/.bash_profile
```

Then check that a fresh login shell sees the alias:

```bash
bash -lic 'type claude2'
```

You should see `claude2 is aliased to ...`. Only add the alias line to `~/.bashrc` once, too: running the `echo` again adds a duplicate.

### 2\. Log in, even without a browser

```bash
claude2
```

Inside it, type `/login`. On a headless server it prints a URL. Open that URL on your laptop or phone, sign in with the second account, and paste the code back into the terminal.

Check it worked by running `/status` in both `claude` and `claude2`. Each should show a different email.

### 3\. Run both at once with tmux

```bash
tmux new -s acc1    # run: claude
# detach with Ctrl+b, then d
tmux new -s acc2    # run: claude2
```

Reattach with `tmux attach -t acc1` or `tmux attach -t acc2`. Both keep running after you close your SSH session.

## Copying your setup to the new account

The new account starts empty: no global `CLAUDE.md`, no settings, no skills. You can copy those over, but only the portable parts.

| Item | Copy it? | Why |
| --- | --- | --- |
| `CLAUDE.md`, `settings.json` | Yes | Your global instructions and preferences |
| `skills/`, `commands/`, `agents/` | Yes, if they exist | Your custom skills, slash commands and subagents |
| `plugins/` | No | Install paths are tied to the first folder; add them again with `/plugin` |
| `.credentials.json` | Never | That's the login. Copying it makes `claude2` use the first account |
| `projects/`, `sessions/`, `history.jsonl`, `cache/` | No | The first account's own history and working data |

```bash
cp ~/.claude/settings.json ~/.claude/CLAUDE.md ~/.claude2/
cp -r ~/.claude/skills ~/.claude2/
```

### First issue that tripped me up

My first attempt was a one-liner copying `commands` and `agents` with `2>/dev/null` on the end. It printed nothing, so I assumed it had failed.

It hadn't done anything wrong. Those folders only exist if you've created custom commands or agents, and I hadn't. The `2>/dev/null` hid the "no such file" message, so success and failure looked identical. Run `ls ~/.claude` first and only copy what's actually there.

## Or let a script do all of it

I wrapped the whole process into `add-claude-account.sh`. Grab it from [GitHub](https://github.com/TahrimWalid/claude-multi-account), then:

```bash
chmod +x add-claude-account.sh
./add-claude-account.sh            # creates claude2
./add-claude-account.sh work       # or any name you like
./add-claude-account.sh --dry-run  # preview without changing anything
```

It creates the config folder, copies the portable setup, adds the alias and tells you how to log in. It also handles the cases that bit me or could bite you:

*   **Missing folders** are reported as "nothing to copy", and real copy errors are shown, never hidden.
    
*   **Re-running** updates its own alias instead of adding a duplicate, and keeps an existing login.
    
*   **An alias you already wrote by hand** is detected and left alone.
    
*   **Bad names** are rejected: `claude` itself, names with spaces, or names that are already programs, like `ls`.
    
*   **Running with sudo** is refused, because it would set up the account for root instead of you.
    
*   **Claude Code not installed** prompts to run the official installer.
    
*   **bash, zsh and fish** are detected, and it warns if SSH logins won't load your `~/.bashrc`.
    
*   **Your** `.bashrc` is backed up before every change.
    

| Flag | What it does |
| --- | --- |
| `--dry-run` | Show what would happen, change nothing |
| `--login` | Start the new account right away so you can `/login` |
| `--no-copy` | Start the new account with a clean setup |
| `--force` | Overwrite files already copied to the new folder |
| `--remove` | Remove the alias, and optionally the folder |
| `--yes` | Accept defaults, no prompts |

## Things to know before you start

*   **Don't point both accounts at the same project folder at once.** Each keeps its own sessions, but they edit the same files and will overwrite each other. Use separate folders, branches or git worktrees.
    
*   **Sessions stay separate.** `/resume` in `claude2` only shows `claude2` sessions.
    
*   **Project files are shared.** A project's own `CLAUDE.md`, `.claude/` folder and `.mcp.json` live in the project, so both accounts see them.
    
*   **By the way,** just to save my skin if your account is banned doing this somehow which is very unlikely, don't blame me.😄
    

If you try it on a different distro or shell and something breaks, open an issue on the repo or drop a comment below.
