OAuth login fails in devcontainers - callback port not forwarded

Resolved 💬 3 comments Opened Jan 25, 2026 by sledorze Closed Jan 29, 2026

Problem

claude login starts a localhost callback server on a random ephemeral port. In devcontainers, this port isn't forwarded to the host, so the OAuth callback from the host browser never reaches Claude Code.

HOST                                    DEVCONTAINER
┌──────────────┐                       ┌──────────────────────┐
│   Browser    │──OAuth callback──X───▶│ claude login         │
│              │   localhost:RANDOM    │ (listening on RANDOM)│
└──────────────┘   Port not forwarded! └──────────────────────┘

Behavior: Login appears to hang or times out. Sometimes works on 2nd attempt if VS Code auto-detects and forwards the port in time (timing-dependent, unreliable).

Environment

  • VS Code devcontainers (Dev Containers extension)
  • GitHub Codespaces
  • Any containerized development environment

Suggested Solutions

  1. Fixed callback port - Allow configuring a known port (e.g., --callback-port 19999) that can be pre-forwarded in devcontainer.json
  1. Device code flow - Like gh auth login, display a code the user enters at a URL. No callback needed.
  1. Polling-based completion - Instead of callback, poll an endpoint to check if auth completed.
  1. Devcontainer detection - Detect REMOTE_CONTAINERS or CODESPACES env vars and suggest appropriate auth method.

Option 2 (device code flow) would be most robust since it works in any environment without port forwarding.

Related

GitHub CLI uses device code flow successfully: https://cli.github.com/manual/gh_auth_login

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗