claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Invalid API key · Please run /login

Open devload opened this issue 6 months ago • 8 comments

Bug Description

Environment Info

  • Platform: darwin
  • Terminal: ssh-session
  • Version: 1.0.68
  • Feedback ID:

Errors

[{"error":"Error: Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the \"X-Api-Key\" or \"Authorization\" headers to be explicitly omitted\n    at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1269:6454\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)","timestamp":"2025-08-05T11:45:50.789Z"},{"error":"SyntaxError: Unexpected token 'I', \"Invalid AP\"... is not valid JSON\n    at JSON.parse (<anonymous>)\n    at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:813:9932\n    at Q (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:674:14418)\n    at XOB (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1294:10811)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)","timestamp":"2025-08-05T11:45:50.797Z"},{"error":"Error: Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the \"X-Api-Key\" or \"Authorization\" headers to be explicitly omitted\n    at oP.validateHeaders (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1278:930)\n    at oP.buildHeaders (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1278:8380)\n    at oP.buildRequest (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1278:7461)\n    at oP.makeRequest (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1278:3310)\n    at async yY1.showErrors (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3030:14400)\n    at async yY1 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:2512:3471)\n    at async _pB (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3030:14251)\n    at async file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3030:9308\n    at async vP0 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3030:1689)\n    at async z01 (file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:3030:9278)","timestamp":"2025-08-05T11:45:50.864Z"},{"error":"Error: Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the \"X-Api-Key\" or \"Authorization\" headers to be explicitly omitted\n    at file:///opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js:1269:6454\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)","timestamp":"2025-08-05T11:46:50.244Z"}]

devload avatar Aug 05 '25 11:08 devload

I solved it by looking at this link

https://github.com/anthropics/claude-code/issues/5118

devload avatar Aug 05 '25 11:08 devload

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/5118
  2. https://github.com/anthropics/claude-code/issues/3849
  3. https://github.com/anthropics/claude-code/issues/3506

If your issue is a duplicate, please close it and 👍 the existing issue instead.

🤖 Generated with Claude Code

github-actions[bot] avatar Aug 05 '25 11:08 github-actions[bot]

This issue is still happening I'm noticing it happens every day maybe 24 hours? The way I fix it is:

Uninstall Claude Code Install 1.00.67 LogIn /Exit Open Claude Code This resolves the problem temporarily for at least 24 hours.

titofebus avatar Aug 08 '25 12:08 titofebus

Still usign 1.0.67. Even after 1.0.84 update...

I tried lots of things, unistalled, removed folder, re installed global, local, re login, logout, re login, migrate etc... None works....

timyal avatar Aug 19 '25 21:08 timyal

also had to install a older version, login, then update the a new version.

elitan avatar Oct 02 '25 13:10 elitan

I had not used Claude Console before. I went straight to trying to use the VS Code extension. When doing /Login it would update the api key in my .claude/config and add it to the api keys in my claude console account but the extension UI still always said the key was invalid.

What fixed it for me was I ran the command "claude" in my terminal which ran me through a setup process. It also created a new api key. And I was able to run prompts in the terminal successfully. Then I closed and reopened VS Code and the Claude extension UI was working and no longer said my api key was invalid

potatofoo avatar Oct 31 '25 20:10 potatofoo

Hi all, as @potatofoo mentioned:

When doing /Login it would update the api key in my .claude/config and add it to the api keys in my claude console account, but the extension UI still always said the key was invalid.

I am experiencing the same issue using Windows with WSL. I have claude-code working in WSL, so I was trying to figure out what's wrong by looking at the configs. I noticed that claude-code is using "~/.cloude.json". I believe that running claude from the terminal generates that file. It wasn't working for me, tho, as it's a different home directory for WSL and Windows for me. VScode extension is using Windows' user home directory to place .claude folder with some files (like .claude/config where it sets API key), but it seems to be ignoring that. I was also trying to add different vscode settings.json for API key for the extension, but all seemed to be ignored.

After all, setting up .claude.json file in Windows' user home directory with {"primaryApiKey": "your_api_key_here"} entry solved it for me.

So it looks like extension reads ~/.claude.json for api key, despite updating ~/.claude/config.json after the /login command.

Hope that gives some insight. I wasn't investigating it further after getting it working ;D

Cheers! 🍻

K4LiN avatar Nov 18 '25 21:11 K4LiN

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.

github-actions[bot] avatar Dec 19 '25 10:12 github-actions[bot]