[BUG] Unable to log into Claude Code on Windows
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.67 (Claude Code)
- Operating System: Windows 11
- Terminal: PowerShell
Bug Description
I'm unable to log into Claude Code from PowerShell. This is true whether I try from within a normal PowerShell instance or from inside my IDE (VS Code).
Steps to Reproduce
- Install Claude Code, either through npm or using the native binary.
- Open a new terminal.
- Start
claude. - Select a preferred theme and press Enter.
- Select a login method and press Enter.
Expected Behavior
I would expect to either be prompted for my credentials in the terminal or to be sent to the browser to complete the login flow.
Actual Behavior
The application errors out with the following message:
OAuth error: Port 45454 is already in use. Please ensure no other applications are
using this port.
Press Enter to retry.
Important to note: Port 45454 is _not_ already in use, as you'll see below.
Additional Context
I've tried the following:
- Running
netstat -aon | findstr :45454. Its output is empty. - Running
netsh int ipv4 show dynamicport tcpto ensure that 45454 is not in my dynamic port range. It isn't:
Protocol tcp Dynamic Port Range
---------------------------------
Start Port : 49152
Number of Ports : 16384
- As administrator, running
Get-Process -Id (Get-NetTCPConnection -LocalPort 45454).OwningProcess. This errors out withNo MSFT_NetTCPConnection objects found with property 'LocalPort' equal to '45454', as nothing's using that port. - Restarting my computer, just in case. It didn't help.
- Using
claude migrate-installerto migrateclaudefrom a global npm install to a local one, then restarting PowerShell. The port error persisted. - Removing the above, installing
claudeas a native binary directly, then restarting PowerShell. The port error persisted.
I'm currently managing to use Claude Code via an API key, which appears to have landed in settings.json somehow. (I both set it in PowerShell via ANTHROPIC_API_KEY and passed a batch script to apiKeyHelper in .claude.json -- not sure which one actually did the trick, as the former didn't work initially and the latter regularly throws an "Error getting API key" message in Claude Code.) I'd much rather be using my Pro account, though, for obvious reasons. Is there some way to pass Pro account credentials to Claude Code without having to use the tool's broken login flow?
12 Comments
I have the same problem.
Have the same issue
I got the same issue as well, so can help test new fix if needed
Seems to work when I run as an administrator.
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This issue still exists in the latest version of the build for windows (1.0.72) and this particular issue references the port number for this version.
I got an email with the following comment, and I tried this and it worked.
_@vanhemsj left a comment
anthropics/claude-code#5008
Run these commands in PowerShell as Administrator:
wsl --shutdown
net stop hns
net start hns
Note: The net stop hns command might show an error or hang, but continue with net start hns anyway - it should still fix the issue. ( i dont know why it worked for me )_
I didn't have to stop WSL, only run the net stop and start commands as an admin and then the claude authentication worked.
Same error. Running netstat -a -b doesn't show any other processing using the port. In WSL (where I also have Claude Code installed, but not running) executing netstat -pln also doesn't show any processes using this port.
However running
net stop hnsand thennet start hnsworked.Can you try
netsh int ip show excludedportrange protocol=tcp?C:\Users\xxx>netsh int ip show excludedportrange protocol=tcp
Protocol tcp Port Exclusion Ranges
Start Port End Port
---------- --------
5357 5357
5985 5985
47001 47001
49711 49810
49811 49910
50000 50059 *
50131 50131
50132 50231
50260 50359
50460 50559
55437 55536
55537 55636
55646 55745
55746 55845
59444 59543
This should be working better in the upcoming release!
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.