Use Different API Key For Each Project

Status Closed — not planned
Maintainer reply ✓ Yes — sid374
Activity 15 comments · opened Mar 31, 2025 · closed Dec 30, 2025
💡 Likely answer: A maintainer (sid374, contributor) responded on this thread — see the highlighted reply below.

I am a consultant and I have a personal API Key that I want to use for all my personal stuff. It is possible I could have different api key for each client I work for. Is it possible to configure claude code to use a different api key per project? I have tried some things but nothing has worked for me.

View original on GitHub ↗

15 Comments

vetterj73 · 1 year ago

@sid374 I take it this isn't possible right now. Is there a way to enter an existing API Key into my config file to use it? It isn't ideal but if I can at least swap out API Key's would be great.

acrefoot · 1 year ago

@vetterj73 I see a primaryApiKey item in ~/.claude.json. Does swapping that work for you?

EDIT: that's linux-only it seems, not on Mac.

On darwin, it does security find-generic-password -a $USER -w -s "Claude Code".

So, you could first try to set the ANTHROPIC_API_KEY env var as suggested here: https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#automate-ci-and-infra-workflows

However, I'm not certain that works outside of headless flows. The worst case would be to update the password each run:
security add-generic-password -a $USER -U -s "Claude Code" -w "password"

Curious to know which works! I'm a bit too lazy to delete/recreate multiple keys in the console to thoroughly test this.

sid374 contributor · 1 year ago
@sid374 I take it this isn't possible right now. Is there a way to enter an existing API Key into my config file to use it? It isn't ideal but if I can at least swap out API Key's would be great.

Yes we don't support this at the moment. The officially supported flow would be to /logout and /login with a different user in your respective directories/sessions

vetterj73 · 1 year ago

I tried changing the api key in the config file but I end up getting a rate limit error.

I know Claude Code create a special work space but we tried creating a new API Key in there and it isn't allowed.

This isn't stopping me from doing work but I feel it is something that should work. For now I am fine with substituting a key when I want to use a different organizations key if I could.

Is there any way from the admin console that I could create a key that will not get a rate limit?

bluesherpa · 1 year ago

@acrefoot I confirmed that the environment variable is only for non-interactive, headless mode for CICD.

I can't find a way to achieve what we're wanting here, so far it seems like an unsupported feature but one that is very important.

zalom · 1 year ago

I come here with similar requirements.
I have a personal and a company API key. I would like to switch between API keys when switching between personal and company projects.

luisdalmolin · 1 year ago

+1 for this feature

uson1x · 1 year ago

Same use case as @zalomб would be nice to use something like direnv to swap API keys that Claude Code is using in interactive mode. And in CI mode just use CLAUDE_API_KEY or similar.

isasmendiagus · 1 year ago

Similar requirements, +1 for this feature

ruchernchong · 1 year ago
Same use case as @zalomб would be nice to use something like direnv to swap API keys that Claude Code is using in interactive mode. And in CI mode just use CLAUDE_API_KEY or similar.

Yup. I am also using direnv and looking for a solution to use something like OPENAI_API_KEY and/or GEMINI_API_KEY for different profiles.

zalom · 1 year ago

Hey guys, since I posted in this feature request issue, I've found a way to set the key in env inside .claude/settings.json. ->

{
  "model": "opus",
  "env": {
    "ANTHROPIC_API_KEY": "your_key_here"
  }
}

I was also exporting the key in my .zshrc, and it was picked up.

There was the thing where I needed to log in anyway. But if you put the key in env, this is the welcome screen.

<img width="1242" height="271" alt="Image" src="https://github.com/user-attachments/assets/8d3d4961-cfae-40f3-aae2-c6375200961d" />

This does not suit everyone, especially if the requested feature is "profiles" for each key.

BUT, if you check the documentation about settings and check Project settings in particular, you can set up different keys for each project.

That should suffice!

github-actions[bot] · 10 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

bluesherpa · 9 months ago

The issue is still occurring and needs a better resolution.

github-actions[bot] · 8 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 7 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.