When the interceptor dies, it must not take the network with it
A DNS redirect outlives the process that justified it. Kill the interceptor and the hostname still points at a port where nothing is listening — so the domain is dead machine-wide until someone works out why.
Redirecting a hostname to 127.0.0.1 is a two-part arrangement. The hosts entry sends the traffic, and a listener on port 443 answers it. Both have to be true for anything to work.
Only one of them is persistent.
The hosts entry is a line in a file. It survives a crash, a force-quit, a power cut, a kernel panic — anything. The listener is a process. It survives none of those.
So the moment the process dies unexpectedly, you are left with half the arrangement: every redirected hostname still resolves to your own machine, and nothing is there. Reproduced by killing the process outright:
kill -9 <mitm pid>
:443 listener 0
hosts entries left 5
curl daily-cloudcode-pa.googleapis.com -> Couldn't connect to server
curl runtime.us-east-1.kiro.dev -> Couldn't connect to serverFive provider hostnames, dead for every program on the computer.
And note what it is not. It does not fall back to the real vendor. DNS does not work that way — the name resolved successfully, to 127.0.0.1, and the connection to that address was refused. There is no second candidate to try. The request simply fails, and it fails identically for the IDE you were capturing, for curl, and for anything else on the machine that happens to use that hostname.
From the user's side this presents as "my provider is down," with no obvious connection to a gateway that is no longer running.
A clean stop was already handled
None of this applies when the server exits normally. Shutdown calls the routine that removes every DNS entry, and it can write /etc/hosts directly because the interception server runs as root. Quit properly and the machine is left exactly as it was found.
That is the trap. The path everyone tests is the path that works, and the path that strands the machine is the one nobody exercises on purpose — you have to go out of your way to kill -9 your own process to see it.
Two reasons the repair never ran
There was already a repair routine for this. It did not help, for two independent reasons, and the second is the more instructive.
It only ran at application startup. So recovery required the user to notice the problem, correctly diagnose it as a stale hosts entry, and restart kRouter. Everything up to the restart is the hard part, and the user attempting it is, by construction, someone whose provider hostnames do not currently resolve.
It was called with no argument. The removal needs root. Called without the stored sudo password it fell back to needing passwordless sudo — which most machines do not have configured. On exactly the machines that get stuck, the repair ran, silently did nothing, and reported no failure. The documented remedy at that point was a sed command the user ran by hand on their own hosts file.
A repair that quietly no-ops is worse than no repair, because its existence is why nobody looked further.
What it does now
Four changes, each closing one of the ways the old version failed:
- It runs on the 60-second watchdog tick, not only at startup. A crash now heals itself within a minute, with no user involvement and no diagnosis required.
- It supplies the stored sudo password — the same one that started the server — so it works on machines without passwordless sudo, which is to say most of them.
- It refuses to act while the server is running. A repair that fires during normal operation would tear down the redirects that make capture work, turning a recovery mechanism into an outage.
- It verifies the removal by re-reading the status, rather than trusting that the call did what it said. This is the same lesson as the lying status: the return value of a privileged shell command is weak evidence that the file changed.
The design point
There is a general principle here, and it is not really about hosts files.
If a mechanism needs two things to be true and only one of them is persistent, the persistent one is a liability the moment the other disappears. A hosts entry without a listener. A certificate trusted for a CA whose key is gone. An environment variable naming a file that was deleted. In every case the durable half keeps asserting an arrangement that no longer exists.
The options are to make the persistent part expire on its own, or to have something watching that can clean up. Hosts entries cannot expire, so this one needed a watchdog.
It also explains why proxy capture mode was worth building as an alternative transport. A CONNECT proxy has no persistent half at all. When the process dies, the port stops accepting, the client gets a refused connection it can report accurately, and there is no file anywhere holding a stale claim about where a hostname lives. Nothing to heal, because nothing was left behind.
One related thing worth knowing: the interception server is spawned as a child of the kRouter app rather than detached, so it stops when the app stops. That is deliberate — it is what makes a clean quit clean — and it is also why restarting kRouter leaves capture off until you turn it back on.
Published by Kodelyth, the team that builds kRouter. Posts are drafted with AI assistance and reviewed by a person before they go out. kRouter is free and MIT licensed.
Install kRouterRelated posts
- How kRouter worksRedact PII before it reaches the model, not afterkRouter can strip names, emails and keys from a request before it leaves your machine, and rejects the request if redaction fails instead of sending it.
- How kRouter worksIntercepting an IDE without sudo, and without blackholing a domainDNS capture needs your password every time and redirects a hostname for the whole machine. Proxy capture mode does neither: one app, no password, and nothing left behind if it dies.
- How kRouter worksx509: certificate signed by unknown authority, and the Go trust-store trapAntigravity's Go agent rejected our root CA while three Node apps accepted it. The cause was one environment variable from an unrelated Python install. For months it looked exactly like certificate pinning.
Relevant docs
- Core conceptsProviders, combos, account routing, token savers, MITM mode, quota tracking, the response cache and remote access: the eight ideas behind kRouter.
- The Zenith Routing EngineHow kRouter picks which of your accounts serves a request: Zenith scoring, conversation stickiness, cooldowns, and the round-robin, P2C and random options.
- Token savers: RTK, Caveman, Ponytail, Headroom, PXPIPEFive ways kRouter can shrink a request before it reaches the provider. Only RTK is on by default. What each saver does, what it needs, and its limits.