[BUG] ubuntu 24.04 cannot login to account with google chrome due to bad localhost lookup
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I have just downloaded claude code and have not been able to diagnose a problem around inital login.
when I starte claude code it opens a window in my Chrome browser aith the "Authorise" button on it. When I press the button I get a chrome error about not being ablke to access a URL for localhost.
What Should Happen?
I should be able to login in to my anthropic accound and claude code should complete authentication and show me the code prompt.
Error Messages/Logs
Steps to Reproduce
start claude code on ubuntu 24.04 and got through the login steps
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.58 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
The fault is associated with the clever way the localhost is looked up by google-chrome.
My /etc/hosts file had the following entgries at the top of the file:
127.0.0.1 localhost
127.0.1.1 DT1139
DT1139 is the hostname of my computer.
According to the claude chat agent, there is a well known bug with ubuntu and google-chrome's clever localhost lookup that translates a search into localhost into a search for (in my case) DT1139, and since that is on 127.0.1.1 and not on 127.0.0.1, which is where claude is listening for an authentication key, it fails!
I did a curl using the failing browser URL and the authentication completed. Since then I changed /etc/hosts to have
127.0.0.1 localhost
127.0.0.1 DT1139
This is my last interation with the your chat agent on the topic
I'm not able to contact Anthropic directly, but you can! The best ways to report it: - Feedback button — use the thumbs down 👎 on any Claude response and leave a note in the feedback box - GitHub — file an issue at [github.com/anthropics/claude-code](https://github.com/anthropics/claude-code) — that's probably the most effective route since it goes directly to the Claude Code team and is publicly visible - Support — [support.anthropic.com](https://support.anthropic.com) Given how specific and well-diagnosed the issue is, a GitHub issue would be ideal. You could describe exactly what you found — Ubuntu 24.04,127.0.1.1hostname entry in/etc/hosts, Chrome resolvinglocalhostvia hostname rather than the first/etc/hostsmatch, and the fix. That's exactly the kind of actionable bug report that gets added to troubleshooting docs.
The long-winded explanation of the google-chrome bug is
Great question — it's subtle. Here's what actually happens: The/etc/hostslookup is sequential. When Chrome resolveslocalhost, it reads/etc/hoststop to bottom and returns the first match. Since127.0.0.1 localhostappears first,localhostshould always resolve to127.0.0.1— and it does for most things. But Chrome is special. Chrome (and Chromium-based browsers) have their own internal DNS/hostname resolution stack that doesn't always follow the simple top-to-bottom/etc/hostslogic. In some versions, Chrome treatslocalhostas a special token and resolves it by looking up the system's hostname first — which on your machine isDT1139, mapped to127.0.1.1. So Chrome's logic becomes roughly: 1.localhost→ what's this machine's hostname? →DT11392. What'sDT1139? →127.0.1.13. Connect to127.0.1.1Rather than the simple: 1.localhost→ check/etc/hosts→127.0.0.1Why does Ubuntu add127.0.1.1in the first place? When your machine doesn't have a static IP address, Debian/Ubuntu needs something to map the hostname to. Rather than leaving it unmapped, the installer adds127.0.1.1as a stable pseudo-address for the hostname. It's mostly harmless — except when software like Chrome conflates hostname resolution with localhost resolution.
It may be mostly harmless but I was about to totally give up on claude code because of this problem
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗