If you work on more than one project, you've probably done this: asked Claude Code to push or deploy, and it used the wrong account. Your computer is signed in as whoever you used last, and the AI doesn't know any better.
Here's the free do-it-yourself setup that fixes most of it, where it falls short, and what I ended up building.
1. Git: the right name and email per folder
Git can switch your identity by folder on its own. Put each project under a parent folder, then add this to ~/.gitconfig:
[includeIf "gitdir:~/projects/acme/"] path = ~/.gitconfig-acme And in ~/.gitconfig-acme:
[user] name = Your Name email = you@acme.com Every repo under ~/projects/acme/ now commits as that email.
2. Command-line tools: a token per folder
Most dev CLIs read a token from an environment variable, so the trick is setting that variable per folder. direnv does this. Add a .envrc file in the project folder:
export GH_TOKEN=... # GitHub CLI export VERCEL_TOKEN=... # Vercel export SUPABASE_ACCESS_TOKEN=... # Supabase export CLOUDFLARE_API_TOKEN=... # Cloudflare Run direnv allow, and those accounts switch on when you cd into the folder. Add .envrc to .gitignore so you never commit your tokens.
3. Claude Code: a separate profile per project
CLAUDE_CONFIG_DIR points Claude Code at a different settings folder, which means a separate set of MCP servers and logins:
export CLAUDE_CONFIG_DIR=~/.claude-acme Put that in the same .envrc and a terminal session in that folder gets the Acme profile.
Where this falls short
This setup works, but here's where it kept failing for me:
- It only works in a terminal. direnv runs when your shell changes folders. Claude Code desktop and editor buttons don't start from your shell, so they never see
.envrc. - Browser sign-ins ignore all of it. MCP servers that sign in through the browser (OAuth) use whichever account the browser is logged into.
- Tokens sit in plain text files on your disk.
- Nothing stops a mistake. If the wrong token is loaded, the push or deploy still goes through.
What I built instead
I'm not a developer. I build with Claude Code across several projects, and I got tired of keeping all of this in sync. So I built Hats, with Claude Code doing the coding.
Each project folder gets a "hat," meaning its set of accounts: GitHub, Vercel, Supabase, Cloudflare, Sentry and more. Open the folder, in the terminal or in Claude Code desktop, and that project's accounts are on. Keys stay in your computer's secure keychain, not in text files. If something tries to push or deploy as the wrong account, Hats stops it.
It runs on Mac and Windows, and I use it every day. There's a waitlist at gethats.dev.
If you juggle several projects: which accounts do you switch between the most? I'm deciding what to support next.
Disclosure: Hats is my project. The DIY setup above works without it.