Unable to use API key for non-interactive automation in Claude Code 2.0.37+ (regression from 2.0.30)
Description
I'm building an automated testing system that needs to run Claude Code non-interactively in Docker containers. I've discovered that Claude Code 2.0.30 works with the .claude.json workaround from issue #441, but versions 2.0.37 and later fail to use this configuration and still prompt for OAuth browser authentication.
Versions Tested
- 2.0.30: ✅ Works with
.claude.jsonworkaround - 2.0.37: ❌ Ignores
.claude.json, prompts for OAuth - 2.0.41: ❌ Ignores
.claude.json, prompts for OAuth
Current Workaround (2.0.30 only)
Following the workaround from #441, I create ~/.claude.json:
{
"changelogLastFetched": 1000000000000,
"primaryApiKey": "$ANTHROPIC_API_KEY",
"hasCompletedOnboarding": true,
"lastOnboardingVersion": "2.0.30"
}
This works perfectly in 2.0.30 - Claude Code starts without prompting and uses the API key directly.
Problem in 2.0.37+
In versions 2.0.37 and later, the same .claude.json file is ignored. Instead, Claude Code:
- Detects the
ANTHROPIC_API_KEYenvironment variable - Shows a yellow box with the masked key
- Prompts "Do you want to use this API key?" with Yes/No options
- Requires interactive terminal input to proceed
For non-interactive automation (Docker containers, CI/CD, testing), this makes 2.0.37+ unusable.
Attempted Solutions
I've tried:
- ✅
.claude.jsonwithprimaryApiKey(works in 2.0.30, ignored in 2.0.37+) - ❌
.claude/settings.jsonwithapiKeyHelper: "disabled"(doesn't work) - ❌
.config/claude-code/settings.jsonwithapiKeyHelper: "disabled"(doesn't work) - ❌
--dangerously-skip-permissionsflag (only skips tool permissions, not auth)
Expected Behavior
When .claude.json contains a valid primaryApiKey, Claude Code should:
- Use that key without prompting
- Not show the API key confirmation dialog
- Allow completely non-interactive operation
This worked in 2.0.30 and appears to be a regression in 2.0.37+.
Request
Could you either:
- Restore the 2.0.30 behavior where
.claude.jsonbypasses the API key prompt, or - Provide an official method for non-interactive API key configuration
For automated testing and CI/CD use cases, it's critical to be able to configure authentication without interactive prompts.
Environment
- Docker containers (Ubuntu 24.04 Noble)
- Non-interactive terminal
- API key provided via environment variable
- Configuration files created before Claude Code starts
Thank you for considering this issue!
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗