惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
博客园 - 聂微东
Y
Y Combinator Blog
罗磊的独立博客
博客园_首页
小众软件
小众软件
有赞技术团队
有赞技术团队
爱范儿
爱范儿
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Run Multiple Claude Code Accounts From One Terminal
Hariom Sharm · 2026-05-10 · via DEV Community

The first problem sounds simple: you have more than one Claude Code account.

Maybe one is personal and one belongs to your company. Maybe you use Claude Max personally but your org wants work to happen under its own account. Maybe you freelance and each client expects a clean boundary.

You can solve that with shell aliases.

But the better version is quieter: let the folder choose the Claude Code profile.

Once you do that, the trick opens up. It is not only for multiple Claude accounts. The same setup lets you keep different MCP credentials, GitHub orgs, Slack workspaces, Linear teams, Sentry projects, and customer tools separated without thinking about it every time you open a repo.

The small mechanism is direnv plus CLAUDE_CONFIG_DIR.

The bigger idea is that Claude Code should run inside the same trust boundary as the folder you are in.

Key Takeaways

  • Run multiple Claude Code accounts from one terminal without manual login/logout
  • Use one Claude Code profile per trust boundary, not one profile per repo
  • Put .envrc in parent folders like ~/personal, ~/work/company, or ~/clients/acme
  • Every repo under that folder can reuse the right Claude account, MCP auth, history, settings, and tool permissions
  • Split profiles when GitHub, Slack, Linear, Sentry, email, database, or customer credentials should not mix
  • Keep shared MCP server definitions in .mcp.json, but keep private auth in the local profile
  • This does not make untrusted MCP servers safe; it narrows the blast radius when tools go wrong

A notebook diagram showing many project folders flowing into separate reusable Claude Code profiles with isolated tool credentials

Why this is worth caring about

People are already running into the rough edges.

There are Reddit threads about multiple Claude Code accounts on one machine, with people using Docker, shell aliases, and CLAUDE_CONFIG_DIR to keep accounts and config apart.

There are also messier threads where users claim account switching or billing attribution got confusing. Treat that as anecdotal, not a verified platform rule. The useful signal is that manual account switching is fragile, especially when work and personal usage share the same machine.

That is the obvious use case. The less obvious one is MCP.

Someone asked how to handle multiple email accounts through MCP, and the practical answer was basically separate tool auth per account.

Then there are the actual security blunders:

The point is not that direnv magically fixes malicious packages. It does not.

The point is that one global Claude profile turns every connected service into one big pile of keys.

Separate profiles make the boundary visible.

The model: profiles are buckets

Do not create a new Claude profile for every repo by default.

Create a profile for every identity or credential boundary.

~/.claude-profiles/
  personal/
  org/
    company/
  clients/
    acme/
    nova/
  sandbox/

Enter fullscreen mode Exit fullscreen mode

Then use direnv at the folder level where that boundary starts.

~/personal/.envrc
~/personal/blog/
~/personal/open-source-tool/

~/work/company/.envrc
~/work/company/web-app/
~/work/company/api/
~/work/company/mobile/

~/clients/acme/.envrc
~/clients/acme/admin/
~/clients/acme/worker/
~/clients/acme/docs/

Enter fullscreen mode Exit fullscreen mode

The Acme repos all use the Acme profile. The company repos all use the company profile. Your personal repos all use the personal profile.

You only split further when the credentials need to split further.

This works because direnv checks the current directory and parent directories for an authorized .envrc, then loads and unloads those variables as you move around your filesystem.

Claude Code supports CLAUDE_CONFIG_DIR, which changes where Claude stores profile state. Claude's .claude docs also say that when CLAUDE_CONFIG_DIR is set, the normal ~/.claude paths live under that configured directory instead.

That means a folder can choose the Claude Code home directory.

Setup once per boundary

Create the profile directories:

mkdir -p ~/.claude-profiles/personal
mkdir -p ~/.claude-profiles/org/company
mkdir -p ~/.claude-profiles/clients/acme
mkdir -p ~/.claude-profiles/sandbox

Enter fullscreen mode Exit fullscreen mode

Put .envrc in the parent folder, not every child repo:

# ~/clients/acme/.envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/clients/acme"

Enter fullscreen mode Exit fullscreen mode

Approve it once:

cd ~/clients/acme
direnv allow

Enter fullscreen mode Exit fullscreen mode

Now any repo under ~/clients/acme gets the Acme Claude profile:

cd ~/clients/acme/admin
claude

Enter fullscreen mode Exit fullscreen mode

First run, log in and authenticate the MCP tools for that boundary:

/login
/mcp

Enter fullscreen mode Exit fullscreen mode

After that, the workflow is boring. You cd into a folder and run claude.

Use case 1: personal vs company

A notebook diagram showing personal projects and company projects flowing into two separate Claude Code profiles

This is the cleanest split.

Your personal folder points to your personal profile:

# ~/personal/.envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/personal"

Enter fullscreen mode Exit fullscreen mode

Your company folder points to your company profile:

# ~/work/company/.envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/org/company"

Enter fullscreen mode Exit fullscreen mode

Now your side projects can use your personal Claude account, personal GitHub, personal notes, personal MCP tools, and whatever experimental setup you are playing with.

Your company repos can use the org-approved account, org-safe MCP servers, work GitHub, work Slack, work Linear, and company settings.

This is not only about billing.

It is about not letting your personal toolchain become invisible background state inside a work repo.

Use case 2: same Claude account, different service auth

A notebook diagram showing one Claude account using separate MCP credential sets for different services

You may only have one Claude account.

That is fine. This pattern still matters.

The profile does not only isolate Claude login. It also isolates Claude Code settings, history, local config, plugins, and MCP auth state.

Maybe two products use the same Claude subscription but different services:

Product A profile:
  GitHub org A
  Slack workspace A
  Linear team A
  Sentry org A

Product B profile:
  GitHub org B
  Slack workspace B
  Linear team B
  Sentry org B

Enter fullscreen mode Exit fullscreen mode

Those should not be one profile.

The failure mode is simple:

  • "Find the Linear issue" searches the wrong team
  • "Check the deploy thread" reads the wrong Slack
  • "Look at Sentry" opens the wrong org
  • "Create a GitHub issue" writes to the wrong repo

Same Claude account. Different tool identities.

That is enough reason to split.

Use case 3: freelancers with client boundaries

A notebook diagram showing a freelancer routing separate client folders into isolated Claude Code profiles

Freelance and client work is where this stops being a nice trick.

Each client should get its own profile:

~/.claude-profiles/clients/acme
~/.claude-profiles/clients/nova
~/.claude-profiles/clients/orbit

Enter fullscreen mode Exit fullscreen mode

Each client folder gets one .envrc:

# ~/clients/acme/.envrc
export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/clients/acme"

Enter fullscreen mode Exit fullscreen mode

All Acme repos can reuse the Acme profile:

~/clients/acme/admin
~/clients/acme/api
~/clients/acme/worker
~/clients/acme/docs

Enter fullscreen mode Exit fullscreen mode

There is no need to create acme-admin, acme-api, and acme-worker profiles unless those repos genuinely use different service credentials.

This keeps the important stuff separated:

  • client GitHub orgs
  • client Slack workspaces
  • client Linear teams
  • client Sentry orgs
  • customer support tools
  • per-client Claude Code history and permissions

Offboarding is cleaner too. When Acme ends, revoke Acme OAuth access and archive the Acme profile. You are not trying to remember which parts of a global Claude setup belonged to which client.

Use case 4: shared MCP definitions, private credentials

A notebook diagram showing shared MCP definitions and private credentials feeding into one Claude Code profile

Claude Code supports MCP scopes: local, project, and user.

The useful team pattern is:

  • project scope for shared server definitions
  • local or user scope for personal setup
  • profile-specific OAuth through /mcp
  • no real secrets committed to Git

Project-scoped MCP creates or updates .mcp.json, which is meant to be shared with the team.

That file should answer:

Which MCP servers does this repo use?

It should not answer:

Whose Slack, Linear, GitHub, Sentry, database, or email account should Claude use?

That belongs to the developer's profile.

Claude Code's MCP docs also support environment variable expansion in .mcp.json, including URLs, headers, and env values. That is useful for shared structure. It is not permission to commit credentials.

Keep the definition shared. Keep the auth local.

Optional split: sandbox and production

Once you have the pattern, two extra profiles are often useful.

Sandbox:

export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/sandbox"

Enter fullscreen mode Exit fullscreen mode

Use this for trying unknown MCP servers, random plugins, hook experiments, or anything you do not want in your daily profile.

Production or support:

export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/org/company-support"

Enter fullscreen mode Exit fullscreen mode

Use this when the same repo sometimes needs safer, narrower access. For example: read-only Sentry, support Slack, no write-capable deployment tools, no experimental MCP servers.

You do not need this everywhere.

But the safest profile is often the one that simply does not have the dangerous tool installed.

What belongs where?

Layer What it should own
Parent .envrc Select the Claude profile for a folder tree
CLAUDE_CONFIG_DIR Claude Code login, settings, history, plugins, rules, and profile state
.mcp.json Shared MCP server definitions for a repo
/mcp auth OAuth/account connection for the active profile
Git repo config Commit name/email and repo-local Git behavior

The line I care about is the first one.

Put .envrc where the trust boundary starts.

Not necessarily in every repo.

A good default layout

For most people:

~/personal/.envrc
~/work/company/.envrc
~/scratch/.envrc

Enter fullscreen mode Exit fullscreen mode

For freelancers:

~/clients/acme/.envrc
~/clients/nova/.envrc
~/clients/orbit/.envrc

Enter fullscreen mode Exit fullscreen mode

For each .envrc, point at one reusable profile folder:

export CLAUDE_CONFIG_DIR="$HOME/.claude-profiles/clients/acme"

Enter fullscreen mode Exit fullscreen mode

Then stop thinking about it.

If you are in an Acme repo, Claude gets Acme's context.

If you are in your personal repo, Claude gets personal context.

If you are in the company repo, Claude gets company context.

The folder tree chooses the identity.

The whole point

Claude Code is no longer just a code editor with a chat box.

Once you connect MCP, it becomes a tool operator. It can read tickets, inspect errors, search messages, query systems, and sometimes take action.

So the question is not only:

Which model should I use?

It is:

Which identity and tool boundary should this repo run inside?

My answer is simple: let the folder decide.


Originally published at harryy.me