Skip to content

[FAQ] Claude Code login fails in GitHub Codespaces with "localhost refused to connect" #369

Description

@andrew-chung-au

Course

ai-dev-tools-zoomcamp

Question

I'm using Claude Code in GitHub Codespaces for isolation, but login fails with "localhost refused to connect." How do I fix it?

Answer

Claude Code's OAuth login opens a browser tab pointing at http://localhost:PORT/callback. In Codespaces this can fail to load, because the browser reaches that URL through Codespaces' port-forwarding proxy instead of talking to the listener directly.

Workaround:

  1. Run claude and let it open the login link in your browser.
  2. When the page fails to load, copy the full URL from the address bar (e.g. http://localhost:35251/oauth/callback?code=...).
  3. Open a second terminal tab in the Codespace and run: curl "http://localhost:35251/oauth/callback?code=..."
  4. Your original terminal logs in immediately.

This works because the curl runs inside the Codespace, on the same machine as the listener, so it bypasses the forwarding proxy entirely.

If this doesn't resolve your login error, check Anthropic's Troubleshoot installation and login page for other known causes.

Checklist

  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions