Environment
- Platform (select one):
- 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
- 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"]
- Run the container in non-interactive mode with the command:
docker run -it <image_id> -p "hello"
- Observe the error message:
Invalid API key · Please run /login
- Confirm that the
ANTHROPIC_API_KEY is set by running:
docker run -it --entrypoint sh <image_id> -c 'echo $ANTHROPIC_API_KEY'
which outputs:
Expected Behavior
Is there a known workaround or a fix planned to support non-interactive authentication?
Environment
Bug Description
In a non-interactive environment, the CLI still requires executing
/logineven 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
ANTHROPIC_API_KEYis set by running:Expected Behavior
Is there a known workaround or a fix planned to support non-interactive authentication?