Claude Code ignores ANTHROPIC_API_KEY when OAuth redirect fails in Docker Compose devcontainer

Resolved 💬 4 comments Opened Mar 13, 2026 by DreamalizeBjorn Closed Apr 10, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

When running Claude Code inside a Docker Compose-based devcontainer,
selecting a login method triggers an OAuth browser flow. If the redirect
fails (e.g. malformed URI https:/platform.claude.com/oauth/code/callback
— note single slash), there is no way to proceed.

The critical problem: ANTHROPIC_API_KEY is set and verified in the
environment (echo $ANTHROPIC_API_KEY prints the key), but Claude Code
does not detect it or offer to use it. The user is stuck at the login
menu.

Ironically, once the OAuth login eventually succeeds (after fixing the
redirect issue), Claude Code immediately detects the API key that was
in the environment all along and displays: "Auth conflict: Using
ANTHROPIC_API_KEY instead of Anthropic Console key." This proves the
key was available the entire time — it just isn't checked until after
the OAuth step succeeds.

Expected Behavior

If ANTHROPIC_API_KEY is present in the environment, Claude Code should:

  1. Skip the login menu entirely and use the API key directly, OR
  2. At minimum, offer "Use existing API key" as a fallback when OAuth fails

Steps to Reproduce

  1. Create a devcontainer using dockerComposeFile in devcontainer.json
  2. Add "remoteEnv": {"ANTHROPIC_API_KEY": "${localEnv:ANTHROPIC_API_KEY}"}
  3. Rebuild container, open terminal
  4. Verify echo $ANTHROPIC_API_KEY prints a valid key
  5. Run claude — login menu appears despite valid API key
  6. Select any login option — OAuth redirect fails with malformed URI
  7. No way to proceed

Workaround

Adding a named Docker volume for ~/.claude allows OAuth to eventually
succeed after manually copying the redirect URL to a browser:

"mounts": ["source=claude-config,target=/home/node/.claude,type=volume"]

A Dockerfile-based devcontainer on the same machine works without issues.

Environment

  • Claude Code version: 2.1.72
  • Container: Docker Compose-based devcontainer (node:20-alpine)
  • Host: WSL2 (Ubuntu 24.04) on Windows, accessed via SSH from another machine
  • VS Code Remote-SSH + Dev Containers

View original on GitHub ↗

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