[BUG]Cannot authenticate Claude Code on headless remote server (VPS)

Resolved 💬 3 comments Opened Jun 4, 2026 by Gaizka-Hub Closed Jul 11, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Title: Cannot authenticate Claude Code on headless remote server via SSH (OAuth broken, ANTHROPIC_API_KEY ignored)

Environment

  • Claude Code version: 2.1.162
  • OS: Ubuntu 24.04.4 LTS (headless VPS, Hetzner CX32)
  • Installation method: curl -fsSL https://claude.ai/install.sh | bash
  • Access method: SSH from macOS

Problem

It is impossible to authenticate Claude Code on a remote headless server.

Every time Claude Code starts, it shows the login wizard regardless of any
configuration. The following approaches have all failed:

  1. ANTHROPIC_API_KEY environment variable is ignored

Setting ANTHROPIC_API_KEY=sk-ant-... before the command is ignored —
the login wizard still appears.

  1. OAuth flow fails with Redirect URI error

Selecting option 1 (Claude Pro subscription) or option 2 (Console account)
generates a URL that fails with:
"Redirect URI https://platform.claude.com/oauth/code%2Fcallback is not
supported by client"
or
"OAuth request invalid: missing response_type"

  1. Copying credentials from Mac does not work

Extracting credentials from macOS Keychain
(security find-generic-password -s "Claude Code-credentials") and placing
them in ~/.claude/.credentials.json on the VPS is ignored.

  1. claude config set apiKey not supported

The -g flag is not recognized and the command without it does not persist
authentication.

Expected behavior

Either:

  • ANTHROPIC_API_KEY environment variable should bypass the login wizard, or
  • OAuth flow should work on headless servers, or
  • There should be a documented way to authenticate on remote servers

Workaround (partial)

The only working solution found is embedding the API key directly in a wrapper
script, but this is not a clean solution and does not persist across the login
wizard which still appears on startup.

Steps to reproduce

  1. Install Claude Code on Ubuntu 24.04 via install script
  2. Connect via SSH from macOS
  3. Run claude — login wizard appears
  4. Set ANTHROPIC_API_KEY and run again — login wizard still appears
  5. Attempt OAuth — fails with Redirect URI error

What Should Happen?

When ANTHROPIC_API_KEY environment variable is set, Claude Code should use it
directly to authenticate without showing the login wizard. This would allow
Claude Code to work on headless remote servers (VPS, CI/CD environments) where
OAuth browser-based authentication is not possible.

Alternatively, there should be a documented CLI flag or configuration option
to authenticate using an API key without requiring interactive OAuth login.

Error Messages/Logs

SSH session output when running claude with ANTHROPIC_API_KEY set:

$ ANTHROPIC_API_KEY="sk-ant-api03-..." ~/.local/bin/claude

Welcome to Claude Code v2.1.162
[theme selection appears]
[after selecting theme]
"Claude Code can be used with your Claude subscription or billed based on 
API usage through your Console account."
Select login method:
1. Claude account with subscription · Pro, Max, Team, or Enterprise
2. Anthropic Console account · API usage billing
3. 3rd-party platform · Amazon Bedrock, Microsoft Foundry, or Vertex AI

After selecting option 2 (Console account):
"Browser didn't open? Use the url below to sign in"
[OAuth URL displayed]

Opening URL in browser returns:
"Redirect URI https://platform.claude.com/oauth/code%2Fcallback is not 
supported by client"

The ANTHROPIC_API_KEY environment variable is completely ignored and the 
login wizard always appears regardless.

System: Ubuntu 24.04.4 LTS, Claude Code 2.1.162, accessed via SSH from macOS

Steps to Reproduce

  1. Install Claude Code on Ubuntu 24.04 headless server:

curl -fsSL https://claude.ai/install.sh | bash

  1. Connect to the server via SSH from macOS:

ssh user@server

  1. Set ANTHROPIC_API_KEY and run Claude Code:

ANTHROPIC_API_KEY="sk-ant-api03-..." ~/.local/bin/claude

  1. Observe: login wizard appears despite API key being set
  1. Select theme (step cannot be skipped)
  1. Select login method 2 (Anthropic Console account)
  1. Copy the OAuth URL shown in terminal and open in browser on local machine
  1. Observe: browser returns error:

"Redirect URI https://platform.claude.com/oauth/code%2Fcallback
is not supported by client"

  1. Try option 1 (Claude Pro subscription) — same OAuth error

Result: No way to authenticate Claude Code on a headless remote server.
ANTHROPIC_API_KEY is ignored, OAuth is broken for remote servers.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

v2.1.162

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

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