Preflight Checklist
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:
- sudo apt install -y xfce4 xfce4-session firefox dbus-x11 sddm
- Reboot, log into desktop, run
claude, complete OAuth in Firefox
- sudo apt purge -y xfce4 xfce4-* sddm firefox dbus-x11 && sudo apt autoremove -y
- 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
- I run Claude Code inside a headless Ubuntu Server VM for security isolation
- The VM has no GUI or browser — I access it only via SSH
- I have a Max subscription, not an API key
- Running
claude shows the OAuth URL but the redirect fails because there's no browser
- 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
- 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
Preflight Checklist
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
This pattern is well-established in major CLI tools:
gh auth login): device code flow with one-time code at github.com/login/deviceaz login --use-device-code): device code flowaws sso login --use-device-code): device code flowThe 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:
claude, complete OAuth in FirefoxThis works but takes 15+ minutes, downloads ~2-3GB of packages, and shouldn't be necessary.
Other approaches I tried that did NOT work:
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
claudeshows the OAuth URL but the redirect fails because there's no browser/login, get a one-time code, paste the URL in my host browser, and authenticate without needing a GUI on the VMAdditional Context
Related issues:
RFC 8628 (OAuth 2.0 Device Authorization Grant): https://datatracker.ietf.org/doc/html/rfc8628