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.
15 Comments
@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.
@vetterj73 I see a
primaryApiKeyitem 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_KEYenv var as suggested here: https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#automate-ci-and-infra-workflowsHowever, 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.
Yes we don't support this at the moment. The officially supported flow would be to
/logoutand/loginwith a different user in your respective directories/sessionsI 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?
@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.
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.
+1 for this feature
Same use case as @zalomб would be nice to use something like
direnvto swap API keys that Claude Code is using in interactive mode. And in CI mode just useCLAUDE_API_KEYor similar.Similar requirements, +1 for this feature
Yup. I am also using
direnvand looking for a solution to use something likeOPENAI_API_KEYand/orGEMINI_API_KEYfor different profiles.Hey guys, since I posted in this feature request issue, I've found a way to set the key in
envinside.claude/settings.json. ->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!
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.
The issue is still occurring and needs a better resolution.
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.
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.