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.

View original on GitHub ↗

34 Comments

wolffiex collaborator · 1 year ago

Does it work if you do ANTHROPIC_API_KEY=<key> claude

edgariscoding · 1 year ago

@wolffiex, no that did not work.

I logged out from my personal account by using /logout

Then I used ANTHROPIC_API_KEY=<my-work-key> claude

At 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.

edgariscoding · 1 year ago

@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

bendavis78 · 1 year ago

Why was this closed as completed? It doesn't work. When using ANTHROPIC_API_KEY="..." claude you are still greeted with this screen

!Image

ant-kurt collaborator · 1 year ago

The next release should remove the login screen if a key or apiKeyHelper is provided externally.

fishuke · 1 year ago

and when is next release?

ant-kurt collaborator · 1 year ago

@fishuke release v1.0.4 just went out, can you give that a try?

Cbeck527 · 1 year ago
@fishuke release v1.0.4 just went out, can you give that a try?

I wasn't able to get ANTHROPIC_API_KEY working, but I figured I'd try out the documented variable ANTHROPIC_AUTH_TOKEN and it worked! 🎉

export ANTHROPIC_AUTH_TOKEN='xxxxxxxxxxxxx'
claude
[...]
bcherny collaborator · 1 year ago

Proper fix is landing in 1.0.6

nandatheguntupalli · 1 year ago

I am getting an API error even thought it is a valid key

Cbeck527 · 1 year ago
@nandatheguntupalli I am getting an API error even though it is a valid key

Same here. FWIW, it worked yesterday evening New York time (I generated a CLAUDE.md for my app) but now I'm seeing a 401 as well.

API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}}

ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_TOKEN both return the 401 😭

ant-kurt collaborator · 1 year ago

Hi folks, can you give this a try once the upcoming release v1.0.11 goes out? This cleans up the behavior around ANTHROPIC_API_KEY (for Console keys) and ANTHROPIC_AUTH_TOKEN (for Authorization: Bearer tokens), as well as adds some additional UI info - such as /status command showing which auth method is being used.

Cbeck527 · 1 year ago

For anyone keeping an eye on this issue, I was able to get this to work on v1.0.10 by adding an environment config to ~/.claude/settings.json

$ cat ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_API_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
}

$ claude
╭────────────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                                  │
│                                                            │
│   /help for help, /status for your current setup           │
│   ──────────────────────────────────────────────────────── │
│   Overrides (via env):                                     │
│                                                            │
│   • API Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX │
╰────────────────────────────────────────────────────────────╯
...
...

Will try the more standard approach of exporting this as an env var in my shell once the next release is out!

RohitPShetty · 1 year ago

@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

ant-kurt collaborator · 1 year ago

@RohitPShetty can you run claude /status to see if the key is picked up? Also please check your ~/.claude.json to see if a key entry was approved or rejected. If rejected, you can manually remove that line or run claude /logout to 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.

sameehj · 1 year ago

`(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:

  1. Ask Claude to create a new app or clone a repository
  2. Use Claude to help with file analysis, editing, bash commands and git
  3. Be as specific as you would with another engineer for the best results
  4. ✔ Run /terminal-setup to set up terminal integration

※ 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:

  1. Ask Claude to create a new app or clone a repository
  2. Use Claude to help with file analysis, editing, bash commands and git
  3. Be as specific as you would with another engineer for the best results
  4. ✔ Run /terminal-setup to set up terminal integration

※ Tip: Ask Claude to create a todo list when working on complex tasks to track progress and remain on track

/status

⎿ (no content)

create a new app

⎿ 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??!!

wolffiex collaborator · 1 year ago

@sameehj try /logout and then /login
you'll get the option to use your subscription

sameehj · 1 year ago
@sameehj try /logout and then /login you'll get the option to use your subscription

Works like a charm, thank you 👍

BigAl · 1 year ago

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?

slovanos · 1 year ago

@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:

{
  "apiKeyHelper": "/home/user/.claude/get-api-key.sh"
}

And
~/.claude/get-api-key.sh:

#!/bin/bash
echo "sk-your-anthropic-api-key"

Now it starts without asking for a login method.

PS: remember $ chmod ug+x get-api-key.sh

RohitPShetty · 1 year ago

@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.

nmartorell · 1 year ago

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" />

EarthmanWeb · 11 months ago

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:


 ⚠ Auth conflict: Both a token (apiKeyHelper) and an API key (ANTHROPIC_API_KEY) are set. This may lead to unexpected 
   behavior.
    • Trying to use apiKeyHelper? Unset the ANTHROPIC_API_KEY environment variable, or claude /logout then say "No" to
     the API key approval before login.
    • Trying to use ANTHROPIC_API_KEY? Unset the apiKeyHelper environment variable.

Removed the env version - now it works with the helper file only.

aaronmedina-dev · 11 months ago

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" />

thejspr · 10 months ago

My workaround was to set ANTHROPIC_API_KEY to your api key and ANTHROPIC_AUTH_TOKEN to dummy. Then start claude and select Yes to using the api key. You can then remove the ANTHROPIC_AUTH_TOKEN dummy env var to get rid of the "Auth conflict" warning.

ByteJuggler · 10 months ago

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:

  • Powershell, setting ANTHROPIC_API_KEY before launching:
  • API key is not recognized, remains using the /login key. (I seem to remember this used to work and be recognized but no longer apparently)
  • Setting ANTHROPIC_API_KEY env var in the .claude/settings.json:
  • API key is not recognized, remains using the /login key.
  • apiKeyHelper method, I get the error Error getting API key from apiKeyHelper (in settings or ~/.claude.json): apiKeyHelper did not return a valid value.
  • Cannot debug what the problem but tried many permutations of paths and slashes to no avail (here I'd not yet logged out again):

<img width="841" height="276" alt="Image" src="https://github.com/user-attachments/assets/c270bc75-62fb-4d0c-a789-a3dcc529912f" />

  • Git bash then setting 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):
  • Same story, env var is ignored:

<img width="839" height="614" alt="Image" src="https://github.com/user-attachments/assets/fbe88877-254d-40c7-9bf2-689e5761ee38" />

What does work:

  • Windows WSL/bash

However I would really like to use a native shell/not WSL bash ideally.

  • Why does /login not present an option 3.) Enter API key?

(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 --examples as an option, all of which would give Claude a major leg up in terms of interacting with command results and so on...)

kiview · 10 months ago

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.

santhoshsram · 9 months ago

Comment https://github.com/anthropics/claude-code/issues/1084#issuecomment-3223079288

My workaround was to set ANTHROPIC_API_KEY to your api key and ANTHROPIC_AUTH_TOKEN to dummy. Then start claude and select Yes to using the api key. You can then remove the ANTHROPIC_AUTH_TOKEN dummy env var to get rid of the "Auth conflict" warning.

This was the only workaround that worked for me.

themartorana · 9 months ago

@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.sh was the kicker.

Setting both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN also works for me, but as mentioned, claude complains about dueling environment variables.

github-actions[bot] · 7 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.

fulrichandrena · 7 months ago

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!

github-actions[bot] · 5 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.

marcindulak · 5 months ago

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.

github-actions[bot] · 5 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.