Go-based CLI tools (gh, terraform, etc.) fail with TLS error due to built-in HTTPS proxy
Bug Description
Claude Code runs a local HTTPS proxy (on a random port, e.g. localhost:62532) and sets HTTPS_PROXY/HTTP_PROXY environment variables to route subprocess network traffic through it. This proxy is active even when sandbox mode is disabled.
Go-based CLI tools like gh (GitHub CLI) fail with a TLS certificate verification error because Go's crypto/x509 package on macOS delegates to the native Security framework (SecTrustEvaluateWithError), which cannot verify the proxy's MITM certificate.
curl works fine because it uses LibreSSL/OpenSSL, which handles the proxy's certificate differently.
Steps to Reproduce
- Open Claude Code on macOS
- Run any
ghcommand that hits the network:
``bash``
gh pr list
- Observe the error:
````
Post "https://api.github.com/graphql": tls: failed to verify certificate: x509: OSStatus -26276
Expected Behavior
gh (and other Go-based CLIs) should work through Claude Code's proxy, just as curl does.
Investigation Details
- The proxy process is Claude Code itself:
```
COMMAND PID USER FD TYPE DEVICE NODE NAME
2.1.45 78322 user 12u IPv4 ... TCP localhost:62532 (LISTEN)
~/.local/share/claude/versions/2.1.45`
Binary:
- Environment variables set by Claude Code:
````
HTTP_PROXY=http://localhost:62532
HTTPS_PROXY=http://localhost:62532
- Unsetting the proxy vars causes complete network failure (no connectivity at all), confirming the proxy is required for network access.
enableWeakerNetworkIsolationsetting does not fix this.
- The error
OSStatus -26276is a macOS Security framework error indicating the certificate chain is untrusted.
Workaround
Use curl with the GitHub REST API instead of gh:
curl -s -X POST https://api.github.com/repos/owner/repo/pulls \
-H "Authorization: token $(gh auth token)" \
-H "Accept: application/vnd.github+json" \
-d '{ ... }'
Impact
This affects all Go-based CLI tools run from within Claude Code, including:
gh(GitHub CLI)terraformkubectl- Any other Go binary that makes HTTPS requests
Environment
- Claude Code version: 2.1.45
- OS: macOS 26.2 (Build 25C56)
- Architecture: arm64 (Apple Silicon)
- gh version: 2.83.1
- Sandbox mode: Disabled (issue persists regardless)
Possible Fix
The proxy could:
- Generate a CA cert and add it to a temp cert bundle that Go can read via
SSL_CERT_FILE(Go respects this on Linux but not always on macOS with cgo) - Inject the CA cert into the macOS login keychain temporarily
- Provide a mechanism to bypass the proxy for specific trusted hosts/tools
11 Comments
Could be related to https://github.com/anthropics/claude-code/issues/23416
+1 for fixing gh usage
+1
+1 please!
+1
+1
This is fixable with a setting more surgical than
enableWeakerNetworkIsolation— and the root cause, at least when the sandbox is enabled, is a bit different from the MITM-cert framing in the issue.On macOS, Go's
crypto/x509doesn't verify certificates in-process — it delegates to the systemtrustddaemon via a Mach-service lookup (SecTrustEvaluateWithError→com.apple.trustd.agent). When Claude Code's Seatbelt sandbox is active, that Mach lookup is denied, so Go can't get a trust verdict and surfaces it asx509: OSStatus -26276even though the certificate is valid.curl/git/Python/Node verify in-process against a CA bundle and never calltrustd, which is why they're unaffected. (Go also ignoresSSL_CERT_FILEon macOS, so that knob doesn't help.)Whitelisting just that one Mach service fixes it without loosening anything else:
In my testing, network isolation stayed fully intact (a non-allowlisted host the Go CLI tried to reach was still blocked), and it did not reintroduce permission prompts for network commands.
enableWeakerNetworkIsolationtargets the sametrustdpath but loosens network isolation broadly — and in some versions it's a no-op that the settings validator strips (see #28954), which may be why it "does not fix this" as noted above — soallowMachLookupis the tighter, more reliable fix. Requires a Claude Code restart to take effect.A working fix:
sandbox.excludedCommands— with three gotchas that make it look brokenOn macOS the
OSStatus -26276error is Seatbelt blocking the Go binary from reaching the system trust daemon (trustd); the proxy env vars (HTTPS_PROXY,ALL_PROXY, etc.) are injected into every command regardless, so the tool can't validate the cert. The documented fix — adding the tool tosandbox.excludedCommandsso it runs outside Seatbelt — does work (confirmed on 2.1.170), but three things made it appear ineffective for us:**1. Patterns match the command as executed, and need a wildcard.**
"gh"only matches the bare commandgh— it does not matchgh api user. You need:**2. The command must start with the excluded binary.** A compound or looped command like
for x in ...; do gh ...; doneorecho foo; gh ...starts withfor/echo, so the whole thing runs sandboxed and theghcalls inside inherit Seatbelt. Run excluded tools as standalone commands.3. Watch out for command-rewriting
PreToolUsehooks — e.g. rtk (Rust Token Killer). rtk's hook auto-rewritesgh …→rtk gh …before the command executes, so the sandbox matches againstrtk gh api user, notgh api user. The plaingh *exclusion silently never matches and the tool keeps running sandboxed. Exclude the rtk-wrapped form too:This was the final missing piece for us — two restarts looked like failures purely because the executed command was
rtk gh …rather thangh ….Verified working afterwards:
gh auth statusshows ✓ andgh apicalls succeed. NoteexcludedCommandsonly takes effect after restarting Claude Code, since sandbox config is read at session start.Adding a version boundary that I haven't seen pinned down yet: this regressed in Claude Code 2.1.172.
ghworked fine inside the sandbox for me for weeks, then broke the instant 2.1.172 installed. Evidence from my local session transcripts (macOS 26 / arm64):ghcommands in-sandbox with zero TLS errors. NoOSStatus -26276appears in any session before today.OSStatus -26276anywhere is timestamped17:19:24; the2.1.172binary was installed at17:19:25— one second apart.2.1.170→2.1.172(no2.1.171changelog entry exists), and the2.1.172notes mention nothing about sandbox, network isolation, ortrustd. So this looks like an undocumented change to the macOS Seatbelt profile.Mechanism (consistent with @pradeep-mj's analysis above): on macOS, Go's
crypto/x509delegates verification totrustdvia a Mach-service lookup (SecTrustEvaluateWithError→com.apple.trustd.agent). 2.1.172 stopped granting that lookup, so Go can't get a trust verdict and surfacesx509: OSStatus -26276even though the cert is valid.curl/git/Python/Node verify in-process and are unaffected. The local proxy is a transparent CONNECT tunnel here (not a MITM) —curlto the same host returns 200 — so the proxy/MITM framing isn't the cause in the sandbox-enabled case.Fix that works on 2.1.172, re-granting just that one Mach service (restart required):
After this, the stock Homebrew
ghworks in-sandbox again using real system trust, and network isolation stays intact (a non-allowlisted host the Go tool tried was still blocked). This also fixesterraform/kubectl/go. Would be good to either restore the prior default or document this in the 2.1.172 notes, since it silently broke every Go CLI in the sandbox.this continues to be a problem for me as well
+1