Claude Code fails silently when ANTHROPIC_API_KEY is set in cloud environments

Claude Code (CC) has a known issue: if you set the ANTHROPIC_API_KEY environment variable in a cloud environment, Claude Code will fail to execute any commands. The variable overrides CLI billing and routes all calls through the Anthropic API, leading to unexpected charges and a dead tool. This was reported on Hacker News with a reference to the GitHub issue #54497.
Key details from the discussion
- Environment variable triggers failure: Setting
ANTHROPIC_API_KEYin cloud environments (e.g., CI/CD, containers) causes Claude Code to stop working. The tool attempts to use the API key for billing, effectively disabling its free tier or local billing mechanism. - Extra usage charges: One user reported seeing a lot of "Extra usage" in their Anthropic billing — likely because every Claude Code call was being proxied through the API key, incurring per-request costs.
- Misguided documentation: Another commenter noted that Anthropic's own documentation previously (and incorrectly) advised adding
ANTHROPIC_API_KEYfor Claude Code Web usage. This led to accidental charges. Anthropic later updated the docs but refused to refund the incurred costs. - Workaround: Do not set
ANTHROPIC_API_KEYin cloud environments where Claude Code runs. Use alternative authentication methods (e.g., CLI‑based credentials or separate billing tokens) if needed.
Who this affects
Developers using Claude Code in CI/CD pipelines, containerized environments, or any cloud‑based infrastructure where environment variables are injected globally.
📖 Read the full source: HN AI Agents
👀 See Also

Log Reducer MCP Server Cuts Token Usage When Claude Code Reads Logs
Log Reducer is an MCP server that processes log files server-side before sending reduced output to Claude Code, avoiding raw logs in the context window. It applies 19 deterministic transforms that compress logs by 50-90%, with a 2000-line log representing 20,000+ tokens removed from sessions.

T9OS: An AI Orchestration System Built Entirely with Claude Code
An economics student built T9OS, a complete AI orchestration layer using Claude Code as the only programming tool. The system includes 18 production pipelines, a 12-state lifecycle engine, and 7 AI 'Guardians' that review every output.

Open-Sourced Claude Code Skills: A /do Pipeline That Cut Follow-Ups by 80%
A developer open-sourced 15 Claude Code skills built over 100+ freelance projects. The /do command runs a 5-step pipeline (/todo → /dev → /verify-dev → /build → /test → push) with auto-fix loops, resulting in 80% fewer follow-ups and 60-65% better code quality across 2000+ commits.

Building a Coding Agent for 8k Context: Planner/Executor Split, Token Budgeting, and Parallel Execution
A detailed breakdown of building a CLI coding agent designed around 8k token limits, using a planner/executor architecture, strict token budgeting, and parallel task execution.