[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
- Create or navigate to a directory containing a
.envfile withHTTP_PROXY=some-proxy-server:port - Attempt to run Claude Code CLI from this directory
- Observe failure with 404 error or indefinite "Calculating..." state
Expected Behavior
Claude Code should either:
- Not automatically pick up HTTP_PROXY settings from local
.envfiles, or - Document this behavior clearly, or
- Provide a way to override these settings without modifying the
.envfile
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
.envfiles containing proxy settings - Temporarily fixing by running
HTTP_PROXY= HTTPS_PROXY= claude-code -vworks 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)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗