Skip to content

Comments

fix: respect HTTP_PROXY/HTTPS_PROXY environment variables#363

Open
kerrypotter wants to merge 2 commits intoopenclaw:mainfrom
kerrypotter:fix/http-proxy-support
Open

fix: respect HTTP_PROXY/HTTPS_PROXY environment variables#363
kerrypotter wants to merge 2 commits intoopenclaw:mainfrom
kerrypotter:fix/http-proxy-support

Conversation

@kerrypotter
Copy link

@kerrypotter kerrypotter commented Feb 16, 2026

Problem

The ClawHub CLI fails with fetch failed on any system that requires an HTTP/HTTPS proxy for outbound connections.

$ clawhub search "test"
- Searching
✖ fetch failed
Error: fetch failed

Root Cause

In packages/clawdhub/src/http.ts, the CLI creates a custom undici.Agent and sets it as the global dispatcher:

setGlobalDispatcher(new Agent({ connect: { timeout: REQUEST_TIMEOUT_MS } }))

This overrides any proxy configuration. Node.js's native fetch() (backed by undici) does not automatically respect HTTP_PROXY/HTTPS_PROXY environment variables, and the custom Agent explicitly bypasses any proxy setup.

Affected Environments

  • Docker containers with proxy-only internet access
  • Hetzner VPS (and similar) with IPv4 proxy configurations
  • Corporate networks behind forward proxies
  • Any system where curl works but Node fetch() doesn't

Fix

Import ProxyAgent from undici alongside Agent, and use it when a standard proxy environment variable is detected:

  • HTTPS_PROXY / https_proxy
  • HTTP_PROXY / http_proxy

Non-breaking: When no proxy env var is set, behavior is identical to before.

Changes

  • packages/clawdhub/src/http.ts: Use ProxyAgent when proxy env vars are set
  • docs/cli.md: Document proxy environment variables
  • docs/troubleshooting.md: Add troubleshooting entry for fetch failed behind proxies

Greptile Summary

Adds HTTP/HTTPS proxy support to ClawHub CLI by using EnvHttpProxyAgent from undici when standard proxy environment variables (HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy) are detected. When no proxy variables are set, behavior remains unchanged with direct connections via the regular Agent.

  • packages/clawdhub/src/http.ts: Conditionally uses EnvHttpProxyAgent when proxy env vars are set, falling back to Agent otherwise
  • Documentation updated to explain proxy configuration and troubleshooting for systems behind corporate firewalls or restricted networks

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is minimal, well-scoped, and non-breaking. Uses a standard undici feature (EnvHttpProxyAgent) for proxy support, with fallback to existing Agent behavior when no proxy variables are set. The implementation correctly checks for all standard proxy environment variables. Documentation is thorough and accurate.
  • No files require special attention

Last reviewed commit: dc2b902

The CLI creates a custom undici Agent via setGlobalDispatcher() which
overrides any proxy configuration. Since Node.js native fetch (backed
by undici) does not automatically respect HTTP_PROXY/HTTPS_PROXY env
vars, the CLI fails with 'fetch failed' on systems that require a
proxy for outbound connections.

Import ProxyAgent from undici and use it when any of the standard proxy
environment variables (HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy)
is set. When no proxy variable is present, behavior is unchanged.

Also adds proxy documentation to cli.md and a troubleshooting entry.
@vercel
Copy link
Contributor

vercel bot commented Feb 16, 2026

Someone is attempting to deploy a commit to the Amantus Machina Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

_httpProxy
? new ProxyAgent({
uri: _httpProxy,
requestTls: { timeout: REQUEST_TIMEOUT_MS },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestTls is for configuring TLS options to the target server. For timeout on ProxyAgent, use connect: { timeout } like the Agent config.

Suggested change
requestTls: { timeout: REQUEST_TIMEOUT_MS },
connect: { timeout: REQUEST_TIMEOUT_MS },
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/clawdhub/src/http.ts
Line: 25:25

Comment:
`requestTls` is for configuring TLS options to the target server. For timeout on ProxyAgent, use `connect: { timeout }` like the Agent config.

```suggestion
            connect: { timeout: REQUEST_TIMEOUT_MS },
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1be9ab00d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 16 to 20
const _httpProxy =
process.env.HTTPS_PROXY ||
process.env.HTTP_PROXY ||
process.env.https_proxy ||
process.env.http_proxy

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor NO_PROXY when selecting proxy dispatcher

Installing ProxyAgent whenever any proxy variable is present ignores NO_PROXY/no_proxy, so hosts that should bypass the proxy (for example localhost or internal registries) will still be sent through the proxy and can fail in common corporate setups that export proxy variables globally. This is a behavioral regression introduced by the new global dispatcher path because the previous direct Agent did not force proxying for excluded hosts.

Useful? React with 👍 / 👎.

Address review feedback:
- Use undici's EnvHttpProxyAgent instead of ProxyAgent. This properly
  handles HTTPS_PROXY vs HTTP_PROXY per-scheme, respects NO_PROXY,
  and uses connect.timeout instead of requestTls.
- Update docs to mention NO_PROXY support.
@kerrypotter
Copy link
Author

@greptileai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant