99

Concurrent visitors over the last 30 minutes. (~)

Peak concurrent visitors -
Yesterday: 0 / Today: 0

Fixing the Claude Code API Key Prompt That No Longer Appears

Claude CodeAPICLI
3 months ago
0

To use Claude Code with an API key instead of signing in with a personal account, you register the key in the ANTHROPIC_API_KEY environment variable.
When you run the claude command in a terminal with the key registered, a confirmation screen asks whether you want to use that API key.

Confirming whether to use the API key

To use the API key, you need to select Yes, but the default selection is No (recommended), so if you press Enter without reading the screen carefully, you end up choosing not to use the API key.
It works this way because signing in with an account is the recommended path, but if you meant to use an API key, it is the opposite of what you wanted.

Even if you notice the mistake, quit Claude Code, and run it again, this confirmation screen no longer appears.
That is because your choice is recorded in a file, and Claude Code does not ask again about an API key that already has a record.
The record is stored in the customApiKeyResponses property of the .claude.json file in your home directory.

  • macOS: ~/.claude.json
  • Windows: C:\Users\username\.claude.json
.claude.json
JSON
1
2
3
4
5
6
{ "customApiKeyResponses": { "approved": [], "rejected": ["AbCdEfGhIjKlMnOpQrSt"] } }

The values in the arrays are not the full API keys but the last 20 characters of each key.
They are identifiers that tell which API key a response belongs to, and they also keep the full key from being stored in this file as plain text.

When Claude Code starts, it takes the last 20 characters of the key in the environment variable, compares them with the two arrays, and decides on one of three states.

State Condition Behavior
Approved In the approved array Uses the API key without asking
Rejected In the rejected array Ignores the API key without asking
Undecided In neither array Shows the confirmation screen

The confirmation screen appears only in the undecided state.
If you select No by mistake, the API key goes into rejected and the state becomes rejected, so the confirmation screen does not appear and the API key is not used.
This record stays even if you log out or reinstall Claude Code.

So if you remove just that value from the rejected array, the state goes back to undecided, and the confirmation screen appears the next time you run Claude Code.
If the array has only one value, you can leave it as an empty array.

~/.claude.json
JSON
1
2
3
4
5
6
{ "customApiKeyResponses": { "approved": [], "rejected": [] } }

~/.claude.json is a file that Claude Code updates while it is running.
Quit every running Claude Code session before you edit it, so your changes are not overwritten.

There is also a way to fix this without editing the file directly.
With the ANTHROPIC_API_KEY environment variable registered, sign in with an account such as a personal subscription, then go to /config and change Use custom API key from false to true, and the API key moves from rejected to approved.
Then log out again and try using the API key.

The Use custom API key option needs to be turned on