“curl: (7) Failed to connect” on Mac

curl exit code 7 reports a failed step. The curl documentation says: “Failed to connect() to host or proxy.”

Fix this with your agentCopies a prompt for Claude Code, Codex or any agent that can use Terminal.

My Mac has this problem: “curl: (7) Failed to connect” on Mac. Read https://kilobat.app/guides/curl-7-failed-to-connect.md and work through it with me. Install the Kilobat CLI if it’s missing: brew install seifip/kilobat/kilobat. Run the guide’s Terminal and kilobat checks yourself and tell me what you find. List the steps only I can do. Ask before you change any setting.

Applies to: The curl that comes with macOS and the Homebrew curl, on all current macOS versions.Checked: 29 October 2026

Symptoms

  • Terminal shows curl: (7) Failed to connect to host port 443.
  • The text often adds “Couldn't connect to server” or “Connection refused”.
  • Scripts and installers stop with exit code 7.

Likely causes

  • Nothing listens on the port. The service is down, or it uses another port.
  • A firewall or proxy. A firewall can refuse the connection. curl also fails when a proxy is set and unreachable.
  • A wrong address. The host or port in the URL is wrong. A variable in a script can be empty.
  • An IPv6 or VPN route. curl may try an address that the network cannot reach.

How to check

  1. Print the exact URL. Check the host and the port.

  2. Run curl with details. The first lines show the address that failed.

    curl -v https://example.com
  3. Test the port.

    nc -vz example.com 443
  4. Show the proxy variables.

    env | grep -i proxy

How to fix it

  1. Start the service if it is yours. Use the port it prints.

  2. Force IPv4 to test an IPv6 fault.

    curl -4 -v https://example.com
  3. Unset a wrong proxy.

    unset https_proxy http_proxy
  4. Turn off the VPN for a short test. Turn it on again after.

With Kilobat

  1. Kilobat's connection doctor tests the address layer by layer: network, proxy, DNS, rules, IPv4, IPv6, TLS and the server. It names the layer that failed.

    kilobat why https://example.com
  2. These Kilobat checks are free. AI agents run them through MCP with diagnose_connection and diagnose_network. See Find why one site or API won't connect.

Questions

Does exit code 7 mean the host is down?

Not always. curl could not connect to the host or the proxy. Find which with curl -v.

What is the difference from (6)?

Exit code 6 means the host name did not resolve. Code 7 means the connection failed. See “curl: (6) Could not resolve host” on Mac.

Sources

Checked on 29 October 2026.