Skip to content

Commit fcc2eb0

Browse files
authored
Merge pull request #4778 from Aschenbath/fix/hook-respect-occupied-proxy-port
fix(hook): skip proxy autostart on occupied loopback ports
2 parents 22812af + 49087db commit fcc2eb0

3 files changed

Lines changed: 278 additions & 26 deletions

File tree

‎docs/guide/proxy/overview.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ The question is only asked when the daemon can actually run: the `rtk-proxy` bin
8080

8181
#### What the SessionStart hook actually does
8282

83-
It does **not** do the redirection — that is the `settings.json` entry above. The hook is a *keep-alive*: when a session whose `ANTHROPIC_BASE_URL` points at a loopback address finds nothing listening there, it runs `rtk llm-proxy start`.
83+
It does **not** do the redirection — that is the `settings.json` entry above. The hook is a *keep-alive*: when a session whose `ANTHROPIC_BASE_URL` points at a loopback address finds nothing listening there, it runs `rtk llm-proxy start`. For a `localhost` URL it checks both `127.0.0.1` and `[::1]`.
8484

85-
It reports through `systemMessage`, which is user-visible and never enters model context — RTK spends no tokens configuring itself. Every failure path stays silent rather than disrupting the session.
85+
If a listener at that address does not identify as RTK at `/health`, the hook never starts a daemon over it. It warns when `env.ANTHROPIC_BASE_URL` in `settings.json` or `RTK_PROXY_BIND` names that address, because the listener could be another service taking the requests or a hung RTK daemon, and the hook cannot tell which. With neither set, the hook treats the listener as your own gateway and stays silent. After starting a daemon, the hook still verifies the RTK identity before reporting that it started successfully.
86+
87+
It reports through `systemMessage`, which is user-visible and never enters model context — RTK spends no tokens configuring itself. A problem is at most a warning; the hook never disrupts the session.
8688

8789
This route only exists on harnesses that *have* a SessionStart hook, which is why the next one matters.
8890

‎src/hooks/init/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ fn report_pipeline_health() {
897897
/// config channel (settings.json `env`); everyone else keeps the manual
898898
/// export line from `rtk llm-proxy start --env`.
899899
/// The base URL the global settings point Claude Code at, if any.
900-
fn proxy_env_target() -> Option<String> {
900+
pub(super) fn proxy_env_target() -> Option<String> {
901901
let dir = resolve_claude_dir().ok()?;
902902
let content = fs::read_to_string(dir.join(SETTINGS_JSON)).ok()?;
903903
let root: serde_json::Value = from_json_str(strip_leading_bom(&content)).ok()?;

0 commit comments

Comments
 (0)