Coada / writing

Many Claude(s)

Switching Claude Code Accounts Per Project

I run Claude Code under more than one account. Each account has its own config directory, so sessions, history and credentials stay separate. In my terminal, a small wrapper picks the account: claude uses my default, and claude -a <name> switches.

I wanted the same behavior inside a project, started from a pnpm script that loads the project's environment first:

pnpm claude:session -a client

This post covers how I set that up. It's a personal layer on top of the project. Teammates keep running claude exactly as they do today, and nothing about their setup changes.

Why the wrapper lives on PATH

A shell function only exists inside the interactive shell that loaded it. pnpm runs scripts in a fresh sh -c shell that doesn't read .bash_profile, and dotenvx starts its command as a plain process. Both find claude by looking it up on PATH.

So the wrapper is an executable file named claude, in a directory that sits ahead of the real install.

The override directory

Add this as the last change to PATH in .bash_profile:

case ":$PATH:" in
  *":$HOME/.local/bin/overrides:"*) ;;
  *) export PATH="$HOME/.local/bin/overrides:$PATH" ;;
esac

The case check keeps nested shells from adding the directory more than once.

The Anthropic directory for your accounts

mkdir -p ~/.anthropic/foo

Set the variable to the directory in your .bash_profile

export ANTHROPIC_DIR=/Users/listenrightmeow/.anthropic

The shim

Save this as ~/.local/bin/overrides/claude and make it executable:

#!/usr/bin/env bash
set -euo pipefail

REAL_CLAUDE="$HOME/.local/bin/claude"
: "${ANTHROPIC_DIR:?Error: ANTHROPIC_DIR is not set.}"

ACCOUNT="${CLAUDE_ACCOUNT:-foo}"

while [[ $# -gt 0 ]]; do
  case "$1" in
    -a|--account)
      ACCOUNT="${2:?Error: --account requires a value.}"
      shift 2
      ;;
    *) break ;;
  esac
done

ACCOUNT_DIR="$ANTHROPIC_DIR/.$ACCOUNT"
if [[ ! -d "$ACCOUNT_DIR" ]]; then
  echo "Error: account directory does not exist at $ACCOUNT_DIR" >&2
  exit 1
fi

CLAUDE_CONFIG_DIR="$ACCOUNT_DIR" exec "$REAL_CLAUDE" "$@"

What it does:

  • Picks the account from -a first, then CLAUDE_ACCOUNT, then the default.
  • Stops with an error if that account's directory doesn't exist.
  • Removes -a and its value before handing off, so the real binary only sees its own arguments.
  • Calls the real binary by absolute path, so the shim never calls itself.

-a needs to come first. The loop stops at the first argument it doesn't recognize and passes everything from there on through.

The project script

"claude:session": "npx @dotenvx/dotenvx run -f .env.claude -- claude"

My .env.claude is gitignored and sets the project's default account:

CLAUDE_ACCOUNT=client

From there:

pnpm claude:session              # project default from .env.claude
pnpm claude:session -a other     # override for this session
pnpm claude:session --resume     # other arguments pass straight through

What teammates see

Nothing new. Without the shim, claude resolves to the standard install and CLAUDE_ACCOUNT is an unused variable. The shim is something each person opts into on their own machine, if it fits how they work.

One thing to check

If Claude Code is also installed globally through npm under a Node version manager like asdf, that copy can land earlier on PATH when a script runs through npx. To see which claude the script will start, run the lookup through the same chain:

pnpm exec npx @dotenvx/dotenvx run -f .env.claude -- sh -c 'command -v claude'

It should print the override path. If it prints a path under your Node install, remove the npm copy with npm uninstall -g @anthropic-ai/claude-code, then run asdf reshim nodejs.


The full setup is in this gist. If you manage multiple Claude Code accounts another way, I'd like to hear how.

Filed under #ai-toolsclaude-code