fix(wrap): set ANTHROPIC_HOST so wrap goose actually proxies Anthropic (#2619)

## Description

`headroom wrap goose` never proxied Anthropic traffic. Goose's Anthropic
provider reads `ANTHROPIC_HOST`, not `ANTHROPIC_BASE_URL`, so the
wrapper started the proxy, printed the banner, and then sent every
request straight to `api.anthropic.com` — silently, with no error and
zero compression.

`ANTHROPIC_BASE_URL` appears in no `.rs` file in the goose repo. The
provider reads `ANTHROPIC_HOST` at
[`crates/goose/src/providers/anthropic_def.rs#L38-L40`](https://github.com/block/goose/blob/main/crates/goose/src/providers/anthropic_def.rs#L38-L40)
and appends `/v1/messages` itself, so `_claude_proxy_base_url(port)` is
already the correct value.

Note the README currently advertises `headroom wrap goose -- --provider
anthropic` as an example — that is the exact invocation that bypasses
the proxy. The OpenAI path was unaffected: goose does honour
`OPENAI_BASE_URL`.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- Set `ANTHROPIC_HOST` alongside the existing vars in `wrap goose`
(`headroom/cli/wrap.py`), and show it in the launch banner.
- Extend `test_wrap_goose_sets_provider_envs` to assert the value. This
test **fails before** the change with a `KeyError`.
- Update the command docstring.

## Testing

- [ ] Unit tests pass (`pytest`)
- [ ] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
# Test A - the env vars `wrap goose` sets today (ANTHROPIC_HOST explicitly unset)
$ env -u ANTHROPIC_HOST ANTHROPIC_API_KEY=*** \
    OPENAI_BASE_URL=http://127.0.0.1:8787/v1 \
    OPENAI_API_BASE=http://127.0.0.1:8787/v1 \
    ANTHROPIC_BASE_URL=http://127.0.0.1:8787 \
    goose run --no-session -t "Reply with exactly: PONG"

● new session · anthropic claude-haiku-4-5
PONG
===== LISTENER HITS =====
(hit count:        0)

# Test B - same, plus ANTHROPIC_HOST (this change)
(hit count: 7)
2026-07-27T12:13:09.381232 HIT POST /v1/messages host=127.0.0.1:8787
2026-07-27T12:13:09.382744 HIT POST /v1/messages host=127.0.0.1:8787
2026-07-27T12:13:10.245477 HIT POST /v1/messages host=127.0.0.1:8787
...

# Test C - OpenAI path, unchanged env (confirms scope is Anthropic-only)
(hit count: 8)  POST /v1/chat/completions
```

## Real Behavior Proof

- Environment: macOS 15 arm64, goose v1.44.0 built from source, headroom
main @ e530de5, provider anthropic / claude-haiku-4-5, isolated goose
config via GOOSE_PATH_ROOT, stub HTTP listener on 127.0.0.1:8787
standing in for the proxy.
- Exact command / steps: Ran `goose run --no-session -t "Reply with
exactly: PONG"` three times against the stub listener — (A) with the env
vars `wrap goose` sets today and ANTHROPIC_HOST explicitly unset, (B)
identical but with ANTHROPIC_HOST added, (C) OpenAI provider with
unchanged env. Full commands and output in the Test Output block above.
- Observed result: A got 0 requests at the listener and goose returned a
real completion from api.anthropic.com, so the bypass is silent rather
than a failure; B got 7 requests at the listener, proving the fix; C got
8 requests on /v1/chat/completions, confirming the OpenAI path already
worked and the scope is Anthropic-only.
- Not tested: pytest, ruff and mypy were not run locally because my
corporate network blocks files.pythonhosted.org so the dev environment
will not install — those three boxes are deliberately left unchecked and
CI should be the authority on them; the new assertion mirrors the
adjacent ANTHROPIC_BASE_URL one against the same `anthropic_base` value.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md`

## Additional Notes

- Folded the assertion into the existing env-fan-out test rather than
adding a near-duplicate, to match the file's stated organisation.
- On port fallback, `_launch_tool` rewrites the child environment
(including the new var) but not `env_vars_display`, so the printed value
can show the requested port. Pre-existing for the other displayed URLs;
not addressed here.
- Possible follow-ups, happy to file separately: `wrap aider` sets
`OPENAI_API_BASE` but not `OPENAI_BASE_URL`; and `wrap goose` does not
call `with_project_prefix()`, so goose traffic isn't attributed per
project.

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/2619"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

---------

Co-authored-by: Filip Kujawa <fkujawa@squareup.com>
Co-authored-by: JD Davis <jd@jds-macbook-air.tail2a279.ts.net>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
filip
2026-10-05 15:31:00 -05:00
committed by GitHub
co-authored by Filip Kujawa JD Davis JerrettDavis
parent a05717f6ec
commit c07fad0f37
4 changed files with 12 additions and 4 deletions
+1
View File
@@ -7868,6 +7868,7 @@ def continue_dev(
# =============================================================================
# OpenClaw
# =============================================================================
+3 -2
View File
@@ -160,14 +160,15 @@ WRAP_TARGETS: dict[str, WrapTarget] = {
EnvVar("OPENAI_BASE_URL", "openai_v1"),
EnvVar("OPENAI_API_BASE", "openai_v1", display=False),
EnvVar("ANTHROPIC_BASE_URL", "anthropic"),
EnvVar("ANTHROPIC_HOST", "anthropic"),
),
project_prefix=False,
help_text=(
"Launch Goose (Block) CLI through Headroom proxy.\n"
"\n"
"\b\n"
"Sets OPENAI_BASE_URL and ANTHROPIC_BASE_URL to route Goose's API calls\n"
"through Headroom.\n"
"Sets OPENAI_BASE_URL, ANTHROPIC_BASE_URL, and ANTHROPIC_HOST to route\n"
"Goose's API calls through Headroom.\n"
"\n"
"\b\n"
"Uninstall: there is no ``headroom unwrap goose`` subcommand — nothing is\n"
+6 -1
View File
@@ -26,7 +26,11 @@ def test_wrap_goose_sets_provider_envs(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""OPENAI_BASE_URL, OPENAI_API_BASE, ANTHROPIC_BASE_URL are set on launch."""
"""OPENAI_BASE_URL, OPENAI_API_BASE, ANTHROPIC_BASE_URL, ANTHROPIC_HOST are set.
Goose's Anthropic provider reads ANTHROPIC_HOST rather than
ANTHROPIC_BASE_URL, so the value is asserted rather than mere presence.
"""
monkeypatch.chdir(tmp_path)
monkeypatch.delenv("HEADROOM_CONTEXT_TOOL", raising=False)
@@ -45,6 +49,7 @@ def test_wrap_goose_sets_provider_envs(
assert env["OPENAI_BASE_URL"] == "http://127.0.0.1:9000/v1"
assert env["OPENAI_API_BASE"] == "http://127.0.0.1:9000/v1"
assert env["ANTHROPIC_BASE_URL"] == "http://127.0.0.1:9000"
assert env["ANTHROPIC_HOST"] == "http://127.0.0.1:9000"
assert captured["tool_label"] == "GOOSE"
assert captured["agent_type"] == "goose"
assert captured["args"] == ("session",)
+2 -1
View File
@@ -17,10 +17,11 @@ from headroom.providers.wrap_registry import WRAP_TARGETS, build_launch_env
def test_goose_banner_hides_openai_api_base_alias():
_, display = build_launch_env(WRAP_TARGETS["goose"], 8787, environ={}, project="p")
# Legacy goose never encoded the project prefix and showed two vars only.
# Goose has no project prefix; its endpoint override is visible in the banner.
assert display == [
"OPENAI_BASE_URL=http://127.0.0.1:8787/v1",
"ANTHROPIC_BASE_URL=http://127.0.0.1:8787",
"ANTHROPIC_HOST=http://127.0.0.1:8787",
]