Employer provided me with an Anthropic API key to use Claude Code but there's no way to configure this key
Resolved 💬 34 comments Opened May 13, 2025 by edgariscoding Closed Jan 19, 2026
💡 Likely answer: A maintainer (wolffiex, collaborator)
responded on this thread — see the highlighted reply below.
Environment
- Platform (select one):
- [X] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 0.2.108
- Operating System: macOS
- Terminal: iTerm2
Bug Description
My employer created a number of Anthropic API keys for each developer in our team, they take care of billing. We want to use Claude Code but there doesnt seem to be a way to configure the API key when calling claude /login.
34 Comments
Does it work if you do
ANTHROPIC_API_KEY=<key> claude@wolffiex, no that did not work.
I logged out from my personal account by using
/logoutThen I used
ANTHROPIC_API_KEY=<my-work-key> claudeAt this point I was asked to choose a dark/light mode for Claude Code and then I was shown the "Select login method" screen with an option for Anthropic Console and Claude app methods. Neither option worked for me. They both tried to get me to login on the website. I don't have a login for my work API key.
@bcherny, I noticed you thumbs upped @wolffiex's reply and closed this issue as completed. Is @wolffiex's suggestion supposed to work? Is it documented somewhere? I could not find it in on the official docs:
https://docs.anthropic.com/en/docs/claude-code/overview
Why was this closed as completed? It doesn't work. When using
ANTHROPIC_API_KEY="..." claudeyou are still greeted with this screen!Image
The next release should remove the login screen if a key or apiKeyHelper is provided externally.
and when is next release?
@fishuke release v1.0.4 just went out, can you give that a try?
I wasn't able to get
ANTHROPIC_API_KEYworking, but I figured I'd try out the documented variableANTHROPIC_AUTH_TOKENand it worked! 🎉Proper fix is landing in 1.0.6
I am getting an API error even thought it is a valid key
Same here. FWIW, it worked yesterday evening New York time (I generated a
CLAUDE.mdfor my app) but now I'm seeing a 401 as well.ANTHROPIC_AUTH_TOKENandANTHROPIC_API_TOKENboth return the 401 😭Hi folks, can you give this a try once the upcoming release
v1.0.11goes out? This cleans up the behavior aroundANTHROPIC_API_KEY(for Console keys) andANTHROPIC_AUTH_TOKEN(forAuthorization: Bearertokens), as well as adds some additional UI info - such as/statuscommand showing which auth method is being used.For anyone keeping an eye on this issue, I was able to get this to work on
v1.0.10by adding an environment config to~/.claude/settings.jsonWill try the more standard approach of exporting this as an env var in my shell once the next release is out!
@ant-kurt @bcherny Any update on this?
Tried setting ANTHROPIC_API_KEY as an env variable, using it as a prefix, via the settings.json file etc. However, still redirected to the login page. On the version 1.0.18
@RohitPShetty can you run
claude /statusto see if the key is picked up? Also please check your~/.claude.jsonto see if a key entry was approved or rejected. If rejected, you can manually remove that line or runclaude /logoutto force erasure of all the API keys from this file. Then on next launch, the "Do you want to use this API key?" prompt should appear again if the env var is picked up correctly.`(base) user@MonkeyPro test-claude-cli % claude /status
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/user/test-claude-cli │
╰───────────────────────────────────────────────────╯
Tips for getting started:
※ Tip: Ask Claude to create a todo list when working on complex tasks to track progress and remain on track
Claude Code Status v1.0.31
L Session ID: dce1xxxx-xf3x-xxxx-xxxx-9ff2exxx8437
Working Directory
L /Users/user/test-claude-cli
Account • /login
L Login Method: Claude Pro Account
L Organization: sxxxx@xxx.xxx's Organization
L Email: sxxxx@xxx.xxx
Model • /model
L Sonnet Sonnet 4 for daily use`
I hit enter and then i try to use claude
`(base) user@MonkeyPro test-claude-cli % claude /status
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code! │
│ │
│ /help for help, /status for your current setup │
│ │
│ cwd: /Users/user/test-claude-cli │
╰───────────────────────────────────────────────────╯
Tips for getting started:
※ Tip: Ask Claude to create a todo list when working on complex tasks to track progress and remain on track
⎿ (no content)
⎿ API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh
your existing token."}}
╭────────────────────────────
`
Is it not possible to authenticate using Claude Pro Account??!!
@sameehj try /logout and then /login
you'll get the option to use your subscription
Works like a charm, thank you 👍
Version 1.0.35 This sill appears to be a problem that It cannot accept ANTHROPIC_API_KEY as env variable, or via the settings.json . Any workaround?
@BigAl @bcherny @ant-kurt
Still the same problem in Version 1.0.44. Setting ANTHROPIC_API_KEY as env variable in ~/.claude/settings.json does not work (neither
export ANTHROPIC_API_KEY='..') and the intro keeps asking to choose one of the 2 login methods.The ony workround I found is:
~/.claude/settings.json:
And
~/.claude/get-api-key.sh:
Now it starts without asking for a login method.
PS: remember
$ chmod ug+x get-api-key.sh@ant-kurt None of this works (refer: https://github.com/anthropics/claude-code/issues/1084#issuecomment-2992990877)
The only thing that worked was the method listed by @slovanos above.
I'm experiencing the same behavior to @slovanos, also on v1.0.44.
Another way I found to work around this is to set both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN (the last one can be any dummy value, but must be non-empty).
Then, when you start Claude Code for the first time, accept the (non-recommended option) to use the ANTHROPIC_API_KEY env var for login.
<img width="1110" height="211" alt="Image" src="https://github.com/user-attachments/assets/929dda6d-9f05-4199-823a-c88419594b77" />
Claude Code then works using the ANTHROPIC_API_KEY auth, even though you get this error message of potential "unexpected behavior" (which tbh may be the case as I haven't extensively tested):
<img width="1156" height="80" alt="Image" src="https://github.com/user-attachments/assets/9d328cc7-e7fd-4660-b73d-b7395734e2e7" />
Same, confirming this bug exists for trying to use API Key in environment - even when loaded, it prompts for console login. Using the workaround sh file to point to the key is the only way to bypass that prompt and have it use my key.
MacOs - 1.0.64 (Claude Code)
EDIT - no, it only worked once. The second time, it now prompts me with:
Removed the env version - now it works with the helper file only.
I created a dummy account, and once you get past the login, you’ll see that it overrides with your ANTHROPIC_API_KEY.
<img width="1934" height="1238" alt="Image" src="https://github.com/user-attachments/assets/12087cda-e086-4b0c-9e43-ba16b0a40ece" />
My workaround was to set
ANTHROPIC_API_KEYto your api key andANTHROPIC_AUTH_TOKENtodummy. Then start claude and select Yes to using the api key. You can then remove theANTHROPIC_AUTH_TOKENdummy env var to get rid of the "Auth conflict" warning.I've run into this since yesterday, trying to get Claude Code to work from native (non WSL) powershell and/or (Git) bash shell, when _using a company provided API key_.
Note that the "normal" /login flow with option 2 (API usage) works fine from powershell. (Bought credit between the "credit balance too low" and the following "/status" call:)
<img width="709" height="654" alt="Image" src="https://github.com/user-attachments/assets/78be76ae-5234-40a5-814f-414f2a812b05" />
What I've tried:
ANTHROPIC_API_KEYbefore launching:ANTHROPIC_API_KEYenv var in the .claude/settings.json:Error getting API key from apiKeyHelper (in settings or ~/.claude.json): apiKeyHelper did not return a valid value.<img width="841" height="276" alt="Image" src="https://github.com/user-attachments/assets/c270bc75-62fb-4d0c-a789-a3dcc529912f" />
ANTHROPIC_API_KEY(note this git bash was started from within Powershell -- if you start it from the start menu with a full env then for some reason it just hangs):<img width="839" height="614" alt="Image" src="https://github.com/user-attachments/assets/fbe88877-254d-40c7-9bf2-689e5761ee38" />
What does work:
However I would really like to use a native shell/not WSL bash ideally.
(By the by if Claude can be made to directly/natively interact with the OS using Powershell, I suspect this would be extremely valuable because all Powershell outputs are objects, and the commandlet ecosystem is quite rich, with help generally always including for example
--examplesas an option, all of which would give Claude a major leg up in terms of interacting with command results and so on...)Can confirm that the workaround of setting both environment variables (as mentioned in https://github.com/anthropics/claude-code/issues/1084#issuecomment-3223079288) works for me as well, nothing else did.
Comment https://github.com/anthropics/claude-code/issues/1084#issuecomment-3223079288
This was the only workaround that worked for me.
@slovanos work-around using the api key helper was the answer.
For anyone that can't get it working,
chmod ug+x ~/get-api-key.shwas the kicker.Setting both
ANTHROPIC_API_KEYandANTHROPIC_AUTH_TOKENalso works for me, but as mentioned, claude complains about dueling environment variables.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.
Hi anthropics team,
please don't close this issue. This issue makes the introduction of new employees to claude code quite cumbersome.
Today the workaround didn't work for the first time and this leaves me wondering in which part of the hack I went wrong.
A fix similar to the suggestion of https://github.com/anthropics/claude-code/issues/1084#issuecomment-3258279381
"Why does /login not present an option 3.) Enter API key?"
would be much appreciated!
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 was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
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.