Skip to content

Non-Interactive Mode Fails to Authenticate Using Provided API Key #551

Description

@potproject

Environment

  • Platform (select one):
    • Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other:
  • Claude CLI version: 0.2.48
  • Operating System: Ubuntu (via Docker)
  • Terminal: Docker container

Bug Description

In a non-interactive environment, the CLI still requires executing /login even though an API key is provided. The documentation states that CI automation should work, but in my setup, running claude non-interactively results in the error "Invalid API key · Please run /login." While interactive sessions work fine after manually logging in with /login, this behavior prevents the tool from being used in automated CI workflows (such as GitHub Actions).

Steps to Reproduce

  1. Build a Docker image with the following Dockerfile:
    FROM ubuntu:latest
    USER root
    WORKDIR /home/app
    RUN apt-get update
    RUN apt-get -y install curl git
    RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
    RUN apt-get -y install nodejs
    RUN npm install -g @anthropic-ai/claude-code
    # Set environment variables for authentication (replace sk-xxx with your API key)
    ENV ANTHROPIC_API_KEY=sk-xxx  
    ENTRYPOINT ["sh", "-c", "claude"]
  2. Run the container in non-interactive mode with the command:
    docker run -it <image_id> -p "hello"
  3. Observe the error message:
    Invalid API key · Please run /login
    
  4. Confirm that the ANTHROPIC_API_KEY is set by running:
    docker run -it --entrypoint sh <image_id> -c 'echo $ANTHROPIC_API_KEY'
    which outputs:
    sk-xxx
    

Expected Behavior

Is there a known workaround or a fix planned to support non-interactive authentication?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions