Documentation
¶
Overview ¶
Package egress finds where this computer's way out to the internet is, through each proxy a Claude subscription's requests go through, and says when it is in a region Anthropic doesn't list as supported (Supported): a proxy that dropped, a VPN turned off, a node in the wrong country (@alterxyz4 on X asked for this "canary"). The user can name the ways out they allow instead, regions and addresses (settings ClaudeWaysOut, mamba on Discord).
The lookup asks Cloudflare's trace page (TraceURL) through the same proxy, and reads its ip= and loc= lines. It never touches Anthropic or the user's account. It runs when magpie starts, when the network or a proxy setting changes, and every Every (Keep); while the hold is on, a request also looks again once the last lookup is older than Fresh (Hold), as a node switched inside a proxy app changes nothing magpie can watch. A lookup that fails says nothing: its state is Unknown, which neither warns nor holds.
Index ¶
Constants ¶
const ( OK = "ok" // in a supported region Unsupported = "unsupported" // in a region the policy doesn't list Unknown = "unknown" // not looked up, or the lookup failed )
The states a way out can be in.
const HeldWords = "magpie held this Claude request"
HeldWords begin every HeldError's text; the gateway reads them as a request that never left (nobody rests for it).
Variables ¶
var ( // Every is how often each choice is looked up again with nothing // changed; Poll how often Keep looks for a change of network or // proxy; Fresh how old a lookup may be before Hold looks again, and // HoldTimeout how long that lookup, which a request waits on, may // take. Every = 15 * time.Minute Poll = 20 * time.Second Fresh = 30 * time.Second HoldTimeout = 5 * time.Second )
var Client = http.DefaultClient
Client sends the lookup. http.DefaultClient goes through netproxy (netproxy.Install), so the choice With names is the proxy it takes.
var Supported = map[string]string{}/* 185 elements not displayed */
Supported is Anthropic's Supported Regions Policy (https://www.anthropic.com/supported-countries, effective 2026-11-12, read 2026-11-21): every country and region it lists, by ISO 3166-1 code, with the name the page gives. testdata/supported-regions.txt is the page's list as it was read, and a test holds this map to it.
var Timeout = 10 * time.Second
Timeout is how long one lookup may take.
var TraceURL = "https://www.cloudflare.com/cdn-cgi/trace"
TraceURL is the page asked; a test points it at its own server.
Functions ¶
func Hold ¶
Hold is the error a Claude subscription's request through choice is held with: when the user turned the hold on (settings ClaudeRegionHold) and the way out through choice is outside the supported regions, or the ways out the user allowed. A lookup older than Fresh is made again first, within HoldTimeout and shared by the requests that come meanwhile: a proxy turned back on lets the next request go, and a node switched to another country inside a proxy app holds it. Unknown holds nothing.
func Keep ¶
Keep looks up the way out through each of choices() when it starts, when the network or a proxy changes, every Every, and when Again asks, until ctx ends. choices is asked each Poll: the distinct proxy choices the Claude accounts' requests take; none, nothing is looked up.
One Keep looks up at a time in a process (keeping): the gateway starts one, and so does the window, whose page shows the lookups of its own process; a window that serves no gateway (another magpie does: the service, magpie serve) had none, and its Claude editor read "Not looked up yet" until Check (mamba on Discord). A second waits, and takes over when the first ends.
Types ¶
type HeldError ¶
type HeldError struct{ Result Result }
HeldError is a request Hold kept from going out.
type Result ¶
type Result struct {
State string `json:"state"`
Loc string `json:"loc,omitempty"` // ISO 3166-1 code, as Cloudflare names it
IP string `json:"ip,omitempty"` // the address the lookup came from
// Mine says the state was judged by the user's own ways out
// (ClaudeWaysOut), not by Anthropic's list.
Mine bool `json:"mine,omitempty"`
At time.Time `json:"at,omitempty"`
Error string `json:"error,omitempty"`
// Via is the proxy it went through, as magpie may show it
// (netproxy.Redact): "" for the global one, "direct" for none.
Via string `json:"via,omitempty"`
}
Result is what the last lookup through one proxy choice found.