Skip to content

Support device-code authentication flow (RFC 8628) for Pro/Max subscription users in headless environments #22992

Description

@rajasuryars

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

Claude Code's OAuth flow requires a browser redirect back to the machine running Claude Code. This makes it impossible to authenticate on headless environments (VMs, SSH sessions, containers, cloud instances) when using a Pro/Max subscription.

API key users can simply set ANTHROPIC_API_KEY — but subscription users have no equivalent workaround.

Proposed Solution

A device-code auth flow (RFC 8628), where authentication happens entirely on a separate device:

$ claude

/login
No browser detected. Use this code to authenticate from another device:
Open: https://claude.ai/device
Code: XXXX-XXXX
Waiting for authentication...
✓ Authentication complete.

This pattern is well-established in major CLI tools:

  • GitHub CLI (gh auth login): device code flow with one-time code at github.com/login/device
  • Azure CLI (az login --use-device-code): device code flow
  • AWS CLI (aws sso login --use-device-code): device code flow

The key difference from the current OAuth flow is that a device-code flow requires no redirect back to the headless machine — the CLI simply polls for a token after the user completes auth on any browser, anywhere.

Alternative Solutions

Currently I work around this by temporarily installing a minimal GUI + browser on the headless VM, completing OAuth in the browser, then purging the GUI packages. Auth persists after removal.

Steps:

  1. sudo apt install -y xfce4 xfce4-session firefox dbus-x11 sddm
  2. Reboot, log into desktop, run claude, complete OAuth in Firefox
  3. sudo apt purge -y xfce4 xfce4-* sddm firefox dbus-x11 && sudo apt autoremove -y
  4. Reboot, SSH back in — Claude Code works headless

This works but takes 15+ minutes, downloads ~2-3GB of packages, and shouldn't be necessary.

Other approaches I tried that did NOT work:

  • SSH port forwarding (ssh -L 8765:localhost:8765) — redirect still fails
  • Copying ~/.claude/ credentials from host via scp — VM still prompts for login

Priority

Critical - Blocking my work

Feature Category

CLI commands and flags

Use Case Example

  1. I run Claude Code inside a headless Ubuntu Server VM for security isolation
  2. The VM has no GUI or browser — I access it only via SSH
  3. I have a Max subscription, not an API key
  4. Running claude shows the OAuth URL but the redirect fails because there's no browser
  5. With a device-code flow, I could run /login, get a one-time code, paste the URL in my host browser, and authenticate without needing a GUI on the VM
  6. This saves time because the current workaround (installing/removing a full desktop environment) takes 15+ minutes and ~2-3GB of downloads

Additional Context

  • Environment: Ubuntu Server 24.04 ARM64 in UTM (macOS, M1 Pro)
  • Claude Code (latest at time of testing: v2.1.31), Max subscription
  • Affects all headless use cases: VMs, Docker containers, SSH remote dev, cloud instances
  • API key users are unaffected since they can set ANTHROPIC_API_KEY

Related issues:

RFC 8628 (OAuth 2.0 Device Authorization Grant): https://datatracker.ietf.org/doc/html/rfc8628

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:authenhancementNew feature or requesthas reproHas detailed reproduction stepsplatform:linuxIssue specifically occurs on Linux

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions