How I solved Claude Code's biggest missing feature

Published: (March 18, 2026 at 04:33 PM EDT)
4 min read
Source: Dev.to

Source: Dev.to

If you use Claude Code with more than one account, you know the pain.
Switching from work to personal means logging out, logging in, losing your session state, and watching your MCP servers vanish—over and over again.

The problem

Claude Code stores everything in two places:

  • ~/.claude.json – your OAuth token and session
  • ~/.claude/settings.json – your preferences

One set of files, one account. Want to switch? You have to destroy the first session and create a new one each time. For developers who use a corporate account during the day and a personal account at night, this is a daily annoyance.

The discovery

In Claude Code’s documentation (env‑vars) there is a variable called CLAUDE_CONFIG_DIR. It redirects where Claude Code reads and writes its config files.

“As an immediate workaround you can use CLAUDE_CONFIG_DIR env var to set the directory to keep your profile data in.” – Anthropic team member (GitHub issue #261)

The variable works, but using it manually is clunky—you have to remember paths, set environment variables, and manage directories yourself.

The solution: Cloak

I built Cloak, a CLI add‑on that wraps CLAUDE_CONFIG_DIR into a friendly interface.

npm install -g @synth1s/cloak

Save your current session

cloak create work

Log out, log in with another account, and save it too

cloak create home

Switch instantly

cloak switch work
cloak switch home

No logout, no login. Tokens, MCP servers, and settings are all preserved.

How it works

Each account gets its own isolated directory:

~/.cloak/
└── profiles/
    ├── work/
    │   ├── .claude.json
    │   ├── settings.json
    │   └── …
    └── home/
        ├── .claude.json
        └── …

When you run cloak switch, Cloak sets CLAUDE_CONFIG_DIR to point to the appropriate directory. Claude Code then reads from there—nothing is copied, moved, or overwritten.

Concurrent sessions

You can run different accounts in separate terminals at the same time:

# Terminal A
claude -a work

# Terminal B
claude -a home

No conflicts; each terminal has its own environment variable pointing to a different directory.

The shell integration story

A child process cannot modify its parent’s environment variables. When cloak switch work runs, the variable is set only inside the Cloak process, and the parent shell retains the old value.

The fix is a shell function that runs inside the current shell:

eval "$(cloak init)"

This injects two functions—cloak() and claude()—that intercept the switch command and export the variable in the current shell. The first time you run cloak switch, it offers to set this up automatically.

Built with TDD

Every feature was test‑first. The project has 113 tests across 13 suites, using Node.js’s native node:test runner—zero test‑framework dependencies.

The TDD discipline caught real bugs, such as:

  • A shell eval trying to execute "You're already wearing..." as Bash code (the apostrophe broke it).
  • A --print-env flag leaking user‑facing messages to stdout, corrupting the shell eval.

Both issues would have been invisible without tests that specifically asserted “stdout must contain only eval‑safe shell code.”

Security

The project underwent a security audit before publishing:

  • Path traversal: account names validated against ^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$.
  • Credential files: created with 0o700 (directories) and 0o600 (files) permissions.
  • Shell injection: export paths are double‑quoted in eval output.
  • Token safety: OAuth tokens are never read, logged, or transmitted—only copied as files.
  • RC file safety: .bashrc modifications include a backup file and a marker comment.

What’s next

Cloak is live on npm and has helped over 700 developers in its first day. The main gap is IDE support—VS Code and JetBrains extensions don’t yet respect CLAUDE_CONFIG_DIR (GitHub issue #4739).

If you’re juggling multiple Claude Code accounts, give it a try:

npm i -g @synth1s/cloak
cloak create work
cloak create home
cloak switch work

The source is on GitHub:

0 views
Back to Blog

Related posts

Read more »