Debugging Claude Code OAuth in Devcontainers: An IPv4/IPv6 Mismatch

  • engineering
  • ai

When running Claude Code CLI inside a VSCode devcontainer, the OAuth authentication flow failed silently. The browser would complete authentication and redirect to localhost:43149, but the CLI never received the callback—it just hung.

After debugging with curl -v, I discovered the request was accepted on IPv4 but received no response. Running ss -tlnp inside the container revealed the culprit: Claude Code's callback server binds exclusively to ::1 (IPv6 localhost), while VSCode's port forwarding sends traffic to 127.0.0.1 (IPv4).

The fix: add this to your devcontainer.json:

{
  "containerEnv": {
    "NODE_OPTIONS": "--dns-result-order=ipv4first"
  }
}

This forces Node.js to prefer IPv4, making the callback server bind to 127.0.0.1 where VSCode's port forwarding can reach it.