[BUG] Design flaw? Run from a directory containing a `.env`

Resolved 💬 3 comments Opened Mar 18, 2025 by childeroland19 Closed Mar 21, 2025

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [x] Other: Claude Code CLI
  • Claude CLI version: 0.2.48
  • Operating System: Ubuntu (running in WSL2 on Windows)
  • Terminal: WSL Ubuntu terminal

Bug Description

Claude Code CLI fails with "404 Invalid response body while trying to fetch https://api.anthropic.com/v1/messages?beta=true: Premature close" when run from a directory containing a .env file with HTTP_PROXY settings.

Steps to Reproduce

  1. Create or navigate to a directory containing a .env file with HTTP_PROXY=some-proxy-server:port
  2. Attempt to run Claude Code CLI from this directory
  3. Observe failure with 404 error or indefinite "Calculating..." state

Expected Behavior

Claude Code should either:

  1. Not automatically pick up HTTP_PROXY settings from local .env files, or
  2. Document this behavior clearly, or
  3. Provide a way to override these settings without modifying the .env file

Actual Behavior

When run from a directory with HTTP_PROXY defined in .env ((PHP/Symfony project in my case), Claude Code attempts to route all API traffic through that proxy server, resulting in connection failures. The error appears as either "API Error: 404 Invalid response body" or an endless "Calculating..." state.

Additional Context

  • The issue only occurs in directories with .env files containing proxy settings
  • Temporarily fixing by running HTTP_PROXY= HTTPS_PROXY= claude-code -v works as a workaround
  • This creates confusion as the error doesn't clearly indicate the proxy connection is the issue
  • The problem persists even after Docker is stopped (which was initially suspected as the cause)

View original on GitHub ↗

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