I use Claude Code every day on my main PC. It’s the tool I talk to when making apps for my family. It worked well without problems for several weeks.
Then I wanted to use it on a second device. This is my daughter’s PC. Sometimes I work on her apps there. Same subscription, same account, everything was the same. I installed the VS Code extension and opened it. Then I saw this error:
API Error: 401 Invalid authentication credentials
That was the start of about 90 minutes I wish I could get back.
What I Tried First (Nothing Worked)
The Claude chatbot suggested the problem was an environment variable. It was showing an old API key. I opened the terminal. I saw that ANTHROPIC_API_KEY was indeed set. I deleted it and restarted. The same error happened again.
Next, I searched for the error and tried other things I found:
- I deleted the
%USERPROFILE%\.claudefolder. No change. - I checked Windows Credential Manager for anything labeled “claude” or “anthropic”. There was nothing.
- I uninstalled the VS Code extension and reinstalled it from scratch.
That last method looked promising. I thought a clean install would clear everything. But the extension seemed to remember the same broken state. The same error showed up again.
I also tried running claude logout and claude login in the terminal. Both commands put me into Claude’s interactive chat mode. They did not do anything helpful. I didn’t know what to do, so I closed it and kept searching.
I tried to find a “Sign Out” option in VS Code’s command palette. It wasn’t there in the version I was running.
I checked the VS Code extension logs. (You press Ctrl+Shift+U, then choose “Claude Code” from the dropdown.) All it said was this:
AuthManager initialized
Claude code extension is now active
And then nothing. No login flow. No error details. Just silence.
How I Actually Fixed the Problem
The solution was to use the same command I had already tried, but in a slightly different way.
Running claude logout by itself put me into interactive chat mode. It treated “logout” as a message to send, not a subcommand. Instead, this is what I had to do:
- Run
claudewithout any arguments. This brings you into interactive mode on purpose. - Once inside, type
/logoutas a slash command. - Then, type
/login.
At step 3, a browser window opened. I logged into my claude.ai account. Done. The VS Code extension saw this right away when I restarted it.
The difference was important. Running claude logout versus running claude first and then /logout. The first one treats “logout” as a chat message. The second one actually runs the logout action.
I don’t know why claude logout doesn’t work as a direct command. I am not a developer, so I can’t explain it at that level. I can only tell you that this sequence worked when nothing else did.
The Cost of Getting Here
I use Claude Code with a Pro subscription. It costs $20 per month. The 90 minutes I spent on this problem did not add to my costs. But it was time I could have used to build something.
If you use an API billing plan instead of a subscription, the cause of a 401 error is different. Most likely, your API key is set up incorrectly. The slash command fix I explained here is especially for users with a subscription (claude.ai Pro or Max).
Summary
If you are getting a 401 error with Claude Code in VS Code, and you have a claude.ai subscription:
- Open your terminal and run
claude(no arguments). - Inside the interactive prompt, type
/logoutand press Enter. - Then type
/loginand press Enter. - Complete the browser login that opens.
That’s it. It took me 90 minutes to find a 30-second solution. I am writing this so the next person can find it in under 30 seconds.
An Embarrassing User Error: SSH Connection to My NAS
Around the same time, I ran into another connection problem. This one was about SSH.
I tried to connect to my home NAS using ssh [email protected]. But I got a “Connection refused” error. I went through the usual checks:
- DSM auto-block list — It was empty.
- Terminal & SNMP settings — SSH was active.
- iptables startup task — It was already running.
- TCP port test — Ports 22, 445, and 5000 were all blocked.
I checked all of these before even thinking about running ipconfig. My laptop was connected to the wrong Wi-Fi. My home has two routers, so there are two Wi-Fi networks. I should have been on the one connected to the NAS, but I wasn’t. As soon as I changed the Wi-Fi, SSH connected right away.
If your SSH or SMB connection to a local NAS fails, check your Wi-Fi name first. Do this before changing any port or firewall settings.