mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(wrap): route Claude Code's Bedrock mode through Headroom (#4316)
## Why
`headroom wrap claude` silently bypassed Headroom for every Claude Code
user on Bedrock.
With `CLAUDE_CODE_USE_BEDROCK=1`, Claude Code ignores
`ANTHROPIC_BASE_URL` and calls AWS itself. wrap only sets
`ANTHROPIC_BASE_URL`, so it started a proxy that saw no traffic: no
error, no savings.
The flag usually lives in `~/.claude/settings.json`, which Claude Code
obeys over the shell, so exporting `CLAUDE_CODE_USE_BEDROCK=0` didn't
help either. A customer hit exactly this and needed a call to find it.
## What
When Bedrock mode is on, wrap routes it through Headroom using the path
that already works with the proxy's Bedrock backend:
- **Read the flag the way Claude Code does:** shell → user → project →
project-local settings → managed settings.
- **Proxy:** started with `--backend bedrock`, in the region Claude Code
would use, with the AWS settings it would read. Settings-file values are
copied in, and keys a settings file clears are cleared.
- **Claude Code:** launched in Anthropic mode against the proxy, with
`--settings '{"env":{"CLAUDE_CODE_USE_BEDROCK":"0"}}'`, which outranks
the settings files. A placeholder credential is added only if none is
configured. The proxy calls Bedrock with the user's AWS credentials.
- **Bedrock wins over Vertex and Foundry,** as it does in Claude Code
(checked: with both flags set, Claude Code calls the Bedrock endpoint).
- **Project-local settings aren't written in Bedrock mode,** since
daemon workers read them without the override.
Where routing isn't safe, wrap leaves the session alone and **says
Headroom is bypassed, and why**:
- the flag is in managed settings (they outrank `--settings`);
- a Bedrock gateway (`ANTHROPIC_BEDROCK_BASE_URL` /
`CLAUDE_CODE_SKIP_BEDROCK_AUTH`);
- `--no-proxy`;
- a non-Bedrock `--backend` / `HEADROOM_BACKEND`;
- the user's own `--settings`.
Also:
- **Managed settings are read tolerantly.** An unreadable file is
reported and skipped instead of stopping every `wrap claude`.
- **The env overlay moves to `providers/claude/runtime.py`**
(`claude_effective_env`) and is shared with the auth-conflict check.
That check now uses the same shell-first order, so settings files
outrank the shell as they do in Claude Code.
## Testing
- **Verified against Claude Code 2.1.304** with a loopback recorder:
- `settings.json` `env` beats the shell;
- `--settings` beats `settings.json`;
- Bedrock beats Vertex.
- **Unit:** 44 tests in `test_wrap_claude_vertex_proxy_env.py`, one per
case above, including the bypass reasons, the unreadable managed file,
region precedence, and the AWS profile reaching the proxy. A conftest
fixture keeps the host's managed-settings file out of CLI tests.
- **Wider suites:** `tests/test_cli`, the Claude provider and doctor
suites pass, except 5 tests that already fail on `main` on macOS:
- 4 in `test_wrap_persistent.py`: the fake `_Manifest` lacks
`runtime_kind`, which the darwin-only branch reads;
- `test_mcp_reconcile::test_ordinary_install_does_not_adopt_serena`,
which depends on whether `headroom` is on PATH.
- **Live, real Bedrock** (Sonnet 4.6, us-east-1), with this change on
core 0.41.0. Customer setup: `CLAUDE_CODE_USE_BEDROCK=1` only in
`~/.claude/settings.json`, plain `headroom wrap claude`:
- routed through Headroom: 13 requests, 0 failed;
- first request 18,312 tokens vs 22,648 sent straight to Bedrock (−19%,
with the tool-search and skill-search plugins).
## Related
- **#1220** routes Bedrock differently: it points
`ANTHROPIC_BEDROCK_BASE_URL` at the proxy and re-signs requests with
SigV4. In a live test it compressed nothing (Bedrock-mode bodies reach a
handler that runs no compression or hooks), and one stream hung for over
5 minutes. This PR uses the Anthropic-mode path the Bedrock backend
already serves.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4316"
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 -->
## Maintainer post-merge qualification
Published `f1f11da91d481e48e57526a784187810f762c209` incorporates
upstream main `e4a60ed72f6ef5b28569f8bfbe2163cfda32c948`. 44 existing
handoff tests pass; both existing effective-client probes fail:
competing Vertex flag remains enabled and user-settings remote base URL
wins over launched proxy URL. Ruff/format/diff pass; clean main sync, no
routing rewrite. Existing Changes Requested decision remains applicable;
unchanged findings are not reposted. Scoped Windows probes use the real
CLI configuration harness or actual metrics object, not live
cloud-provider traffic. Contributor correctness logic was not rewritten;
hosted checks are handled by maintainers. Nothing merged.
### Maintainer current-main requalification
Exact head `79b861ef2351bd321900b221f6cf99ad5cbedf27`, upstream main
`ecbaf86d78cf52d185fbffa306157b9a4cc1b906`.
Mechanically updated from upstream/main
ecbaf86d78 with a clean merge and no
contributor routing-policy rewrite. Reviewed existing discussion and
integration delta. All 54 existing Bedrock handoff/Gemini tests pass;
Ruff0.17.3 lint/format and whitespace checks pass.
Both prior effective-client probes still fail on this combined tree:
user-settings Bedrock plus shell Vertex leaves effective
CLAUDE_CODE_USE_VERTEX=1; user-settings Bedrock plus remote
ANTHROPIC_BASE_URL retains https://example.invalid instead of the
launched http://127.0.0.1:8787 proxy. These probes combine the real CLI
harness's captured launch environment and settings overlay; child/proxy
processes are stubbed and no live-provider request is claimed. Retain
the existing requested complete session overrides for competing provider
flags and proxy base URL while respecting managed-policy precedence,
with assertions on effective launched-client configuration. This is not
an inherited-main CI hold. Maintainers handle hosted checks; nothing
merged.
Exact-head hosted checks are being handled by maintainers. Existing
correctness/qualification holds remain; nothing merged.
### Maintainer current-main requalification
Exact head `4187711078787567dff800087f4e68e814c0aaa9`, upstream main
`8d3e9e5ca7cd645eb73084b848edbea5fc796e1a`.
Clean mechanical sync with upstream
main8d3e9e5ca7cd645eb73084b848edbea5fc796e1a, with no contributor
routing policy rewrite. Existing discussion/source
re-reviewed.54existing Bedrock handoff/Gemini tests pass;5changed Python
files Ruff0.17.3check/format and whitespace pass.
Both prior effective-client probes freshly fail on this combined tree:
user-settings Bedrock plus shell Vertex leaves effective
CLAUDE_CODE_USE_VERTEX=1; user-settings Bedrock plus remote
ANTHROPIC_BASE_URL retains https://example.invalid rather than launched
loopback proxy. Probes combine the real CLI harness launch environment
and settings overlay with stubbed child/proxy, not a live provider.
Supply complete session overrides for competing provider flags and proxy
base URL while preserving managed-policy precedence; assert effective
launched configuration. This is not inherited-main CI. Maintainers
handle hosted checks; copied extension is not fresh-native-build proof.
Nothing merged.
Exact-head hosted checks are being handled by maintainers. Existing
correctness/qualification holds remain; nothing merged.
### Maintainer current-main requalification
Exact head `2c94a2f3dacaeba93c2ff846b3c7ea9614f8165d`, upstream main
`2d3ee51846435ef5b320eea4806af14e602b0d8c`.
Clean integration with upstream/main
2d3ee51846. Re-reviewed current discussion
and the composed tree. Exact comparison of CLI launch and Claude
provider implementation plus the Bedrock handoff test file against prior
reviewed 418771107 shows no changes. All 131 Bedrock
handoff/release/version/MCP/memory/Gemini tests pass; whitespace passes.
Prior changed-file lint/format applies to identical contributor inputs.
The existing effective-client configuration finding remains:
user-settings Bedrock combined with shell Vertex or settings
ANTHROPIC_BASE_URL can preserve the competing provider flag or remote
URL. Earlier harness probes remain evidence for the unchanged launch
paths; they were not rerun or claimed as live-provider proof after these
unrelated main merges. Preserve the requested complete per-session
overrides and launched-configuration regressions while respecting
managed policy precedence. No routing-policy winner selected between
overlapping PRs. No contributor correctness logic rewritten, no fresh
native build claimed. Maintainers handle checks; nothing merged.
Exact-head hosted checks are being handled by maintainers. Existing
correctness/qualification holds remain; nothing merged.
### Maintainer current-main requalification
Exact head `26ad500eadcd958cbea4d433333958e0e36a766c`, upstream main
`c01cf07d943d816cfd9d97e6838ed4e38f1ff9a4`.
Clean integration with upstream/main
c01cf07d94 after the
release/runtime/dependency merges. Resolved the test-fixture-only
conflict by retaining both the author's proxy environment capture and
main's actual-port override; original UTF-8 banner assertions and
contributor production logic are preserved.107 Bedrock
handoff/region/Hermes tests pass with actual Click8.5.0 and the fresh
native binding; changed-source Ruff and whitespace pass.
The two existing effective-client routing blockers freshly reproduce on
this composed tree. With Bedrock selected in user settings and Vertex
enabled in the shell, the launched effective configuration still has
CLAUDE_CODE_USE_VERTEX=1. With user-settings
ANTHROPIC_BASE_URL=https://example.invalid, the launched settings retain
that gateway while the shell points to the proxy. The proxy backend is
Bedrock in both cases, so the client route disagrees with the announced
route. Please provide complete per-session overrides, or explicitly
refuse incompatible effective configurations, with
launched-configuration regressions while respecting managed-policy
precedence. Current author discussion and Devin findings considered; no
policy winner or new unsupported cloud-runtime claim introduced. No real
AWS call was made. Maintainers handle exact-head hosted checks; nothing
merged.
Exact-head hosted checks are being handled by maintainers. Existing
correctness/qualification holds remain; nothing merged.
### Maintainer current-main requalification
Exact head `3fa44885c12e14e95ac55e8352d30542328a90d2`, upstream main
`da6d9736cd82074988c7d0a2360b49d9d8b6c0a0`.
Current-main requalification against
da6d9736cd. All69 integration patches
exactly match c01cf07-to-current-main delta after diff-location
normalization; contributor handoff/ownership policy unchanged.107
Bedrock handoff/region/Hermes tests pass.31 changed Python files pass
Ruff lint/format; offline lock and whitespace pass. Existing pr3982
native DLL verified complete native input hashes/artifact checksum; no
fresh build claimed. Author and Devin discussions considered. Both
effective-client routing blockers freshly reproduce with captured launch
configuration: user-settings Bedrock plus shell CLAUDE_CODE_USE_VERTEX=1
leaves Vertex enabled; user-settings
ANTHROPIC_BASE_URL=https://example.invalid survives while shell proxy
base URL points locally. Announced Bedrock backend and effective client
route disagree. Provide complete per-session overrides or explicitly
reject incompatible effective configuration, respecting managed-policy
precedence, with launched-configuration regressions. No real AWS request
or live cloud claim. Maintainers handle hosted checks; no contributor
semantics rewritten or merge.
Exact-head hosted checks are being handled by maintainers. Existing
correctness/qualification holds remain; nothing merged.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
JerrettDavis
parent
cbcf8d8d9b
commit
aa2093b4a0
+200
-21
@@ -85,6 +85,7 @@ from headroom.providers.antigravity import (
|
||||
render_setup_lines as _render_antigravity_setup_lines,
|
||||
)
|
||||
from headroom.providers.claude import (
|
||||
CLAUDE_AUTH_KEYS,
|
||||
DEFAULT_1M_MODEL,
|
||||
HEADROOM_1M_MODEL_ENV,
|
||||
REMOTE_CONTROL_BASE_URL_ENV,
|
||||
@@ -92,6 +93,7 @@ from headroom.providers.claude import (
|
||||
TOOL_SEARCH_ENV,
|
||||
claude_auth_conflict_message,
|
||||
claude_auth_conflict_sources,
|
||||
claude_effective_env,
|
||||
claude_user_settings_path,
|
||||
configure_vscode_claude_settings,
|
||||
detect_claude_code_version,
|
||||
@@ -316,24 +318,119 @@ def _claude_settings_env(path: Path) -> dict[str, object]:
|
||||
return dict(env) if isinstance(env, dict) else {}
|
||||
|
||||
|
||||
def _raise_on_claude_auth_conflict(
|
||||
*,
|
||||
user_settings_path: Path,
|
||||
project_settings_path: Path,
|
||||
def _claude_managed_settings_path() -> Path:
|
||||
"""Where Claude Code reads its admin-managed settings file.
|
||||
|
||||
Managed policy delivered another way (a macOS MDM profile, the Windows
|
||||
registry) is not read here.
|
||||
"""
|
||||
if sys.platform == "darwin":
|
||||
return Path("/Library/Application Support/ClaudeCode/managed-settings.json")
|
||||
if sys.platform == "win32":
|
||||
return Path(r"C:\Program Files\ClaudeCode\managed-settings.json")
|
||||
return Path("/etc/claude-code/managed-settings.json")
|
||||
|
||||
|
||||
def _claude_managed_settings_env(path: Path) -> dict[str, object]:
|
||||
"""The env block of the managed settings; ``{}`` if absent or unreadable.
|
||||
|
||||
The file belongs to an admin and wrap never writes it, so a broken one is
|
||||
reported and skipped rather than stopping the launch.
|
||||
"""
|
||||
try:
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
click.echo(f" Warning: could not read {path} ({exc}); ignoring it.")
|
||||
return {}
|
||||
env = payload.get("env") if isinstance(payload, dict) else None
|
||||
return dict(env) if isinstance(env, dict) else {}
|
||||
|
||||
|
||||
def _claude_env_layers(
|
||||
project_local_settings_path: Path,
|
||||
environ: dict[str, str],
|
||||
) -> None:
|
||||
"""Refuse an auth state Claude Code rejects before mutating wrap state."""
|
||||
conflict = claude_auth_conflict_sources(
|
||||
(str(user_settings_path), _claude_settings_env(user_settings_path)),
|
||||
(str(project_settings_path), _claude_settings_env(project_settings_path)),
|
||||
) -> list[tuple[str, Mapping[str, object]]]:
|
||||
"""Claude Code's env sources, lowest precedence first.
|
||||
|
||||
Its settings files outrank the shell, and managed settings outrank
|
||||
everything, ``--settings`` included.
|
||||
"""
|
||||
user = claude_user_settings_path()
|
||||
project = Path.cwd() / ".claude" / "settings.json"
|
||||
managed = _claude_managed_settings_path()
|
||||
return [
|
||||
("shell environment", os.environ),
|
||||
(str(user), _claude_settings_env(user)),
|
||||
(str(project), _claude_settings_env(project)),
|
||||
(str(project_local_settings_path), _claude_settings_env(project_local_settings_path)),
|
||||
("shell environment", environ),
|
||||
)
|
||||
(str(managed), _claude_managed_settings_env(managed)),
|
||||
]
|
||||
|
||||
|
||||
def _raise_on_claude_auth_conflict(layers: list[tuple[str, Mapping[str, object]]]) -> None:
|
||||
"""Refuse an auth state Claude Code rejects before mutating wrap state."""
|
||||
conflict = claude_auth_conflict_sources(*layers)
|
||||
if conflict is not None:
|
||||
raise click.ClickException(claude_auth_conflict_message(conflict))
|
||||
|
||||
|
||||
_CLAUDE_BEDROCK_ENV = "CLAUDE_CODE_USE_BEDROCK"
|
||||
# Every cloud mode Claude Code can be in. A routed Bedrock session turns all of
|
||||
# them off: with any one left on, Claude Code calls that cloud directly.
|
||||
_CLAUDE_CLOUD_MODE_ENVS = (
|
||||
_CLAUDE_BEDROCK_ENV,
|
||||
"CLAUDE_CODE_USE_VERTEX",
|
||||
"CLAUDE_CODE_USE_FOUNDRY",
|
||||
)
|
||||
# AWS settings a Bedrock user may keep only in a Claude settings env block. The
|
||||
# proxy calls Bedrock itself, so it needs them in its own environment.
|
||||
_CLAUDE_BEDROCK_AWS_KEYS = (
|
||||
"AWS_PROFILE",
|
||||
"AWS_REGION",
|
||||
"AWS_DEFAULT_REGION",
|
||||
"AWS_ACCESS_KEY_ID",
|
||||
"AWS_SECRET_ACCESS_KEY",
|
||||
"AWS_SESSION_TOKEN",
|
||||
"AWS_BEARER_TOKEN_BEDROCK",
|
||||
)
|
||||
|
||||
|
||||
def _is_env_truthy(value: str) -> bool:
|
||||
"""Claude Code's reading of a flag env var such as CLAUDE_CODE_USE_BEDROCK."""
|
||||
return value.strip().lower() in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
def _claude_bedrock_bypass_reason(
|
||||
claude_env: Mapping[str, tuple[str, str]],
|
||||
*,
|
||||
managed_source: str,
|
||||
backend: str | None,
|
||||
no_proxy: bool,
|
||||
claude_args: tuple[str, ...],
|
||||
) -> str | None:
|
||||
"""Why wrap cannot route this Bedrock-mode session through Headroom, or None."""
|
||||
if claude_env[_CLAUDE_BEDROCK_ENV][1] == managed_source:
|
||||
return f"it is set in {managed_source}, which outranks wrap; ask your admin to remove it"
|
||||
for key in (*_CLAUDE_CLOUD_MODE_ENVS[1:], "ANTHROPIC_BASE_URL"):
|
||||
if claude_env.get(key, ("", ""))[1] == managed_source:
|
||||
return (
|
||||
f"{key} is set in {managed_source}, which outranks wrap; "
|
||||
"ask your admin to remove it"
|
||||
)
|
||||
if "ANTHROPIC_BEDROCK_BASE_URL" in claude_env or _is_env_truthy(
|
||||
claude_env.get("CLAUDE_CODE_SKIP_BEDROCK_AUTH", ("", ""))[0]
|
||||
):
|
||||
return "it goes through your own Bedrock gateway, which the proxy would skip"
|
||||
if no_proxy:
|
||||
return "--no-proxy reuses a proxy whose backend wrap does not set"
|
||||
if backend not in (None, "bedrock"):
|
||||
return f"the proxy backend is '{backend}', not 'bedrock'"
|
||||
if any(arg == "--settings" or arg.startswith("--settings=") for arg in claude_args):
|
||||
return "your own --settings would replace the override wrap passes to Claude Code"
|
||||
return None
|
||||
|
||||
|
||||
def _append_text(path: Path, content: str) -> None:
|
||||
"""Append to a text file as UTF-8 without translating line endings."""
|
||||
fsutil.append_text(path, content)
|
||||
@@ -6222,12 +6319,13 @@ def claude(
|
||||
# early proxy-start failure would make the finally raise UnboundLocalError,
|
||||
# masking the real error and skipping cleanup(). Mirrors the holders above.
|
||||
_wrap_settings_path = Path.cwd() / ".claude" / "settings.local.json"
|
||||
_raise_on_claude_auth_conflict(
|
||||
user_settings_path=claude_user_settings_path(),
|
||||
project_settings_path=Path.cwd() / ".claude" / "settings.json",
|
||||
project_local_settings_path=_wrap_settings_path,
|
||||
environ=dict(os.environ),
|
||||
)
|
||||
_claude_env_sources = _claude_env_layers(_wrap_settings_path)
|
||||
_raise_on_claude_auth_conflict(_claude_env_sources)
|
||||
# What Claude Code will see, with the source of each value.
|
||||
_claude_env = claude_effective_env(*_claude_env_sources)
|
||||
_bedrock_value, _bedrock_source = _claude_env.get(_CLAUDE_BEDROCK_ENV, ("", ""))
|
||||
# Claude Code picks Bedrock over Vertex and Foundry when the flags overlap.
|
||||
bedrock_on = _is_env_truthy(_bedrock_value)
|
||||
cleanup = _make_cleanup(proxy_holder, port_holder)
|
||||
signal.signal(signal.SIGINT, _ignore_child_sigint)
|
||||
signal.signal(signal.SIGTERM, _exit_on_signal)
|
||||
@@ -6289,7 +6387,7 @@ def claude(
|
||||
# than the full ANTHROPIC_FOUNDRY_BASE_URL. When the URL is absent we derive
|
||||
# it from the resource name so the proxy has an upstream to forward to.
|
||||
foundry_upstream = None
|
||||
if os.environ.get("CLAUDE_CODE_USE_FOUNDRY"):
|
||||
if os.environ.get("CLAUDE_CODE_USE_FOUNDRY") and not bedrock_on:
|
||||
foundry_upstream = os.environ.get("ANTHROPIC_FOUNDRY_BASE_URL")
|
||||
if not foundry_upstream:
|
||||
resource = os.environ.get("ANTHROPIC_FOUNDRY_RESOURCE", "").strip()
|
||||
@@ -6304,10 +6402,47 @@ def claude(
|
||||
# real regional Vertex host (derived per-request from the path's
|
||||
# location) using Claude Code's own ADC token — no API key, no creds held
|
||||
# by Headroom. This is the turnkey Vertex compression path.
|
||||
use_vertex = bool(os.environ.get("CLAUDE_CODE_USE_VERTEX"))
|
||||
use_vertex = bool(os.environ.get("CLAUDE_CODE_USE_VERTEX")) and not bedrock_on
|
||||
proxy_url = _claude_proxy_base_url(port)
|
||||
vertex_upstream = _vertex_target_api_url_from_claude_env(proxy_url) if use_vertex else None
|
||||
|
||||
# Bedrock mode: with CLAUDE_CODE_USE_BEDROCK=1, Claude Code ignores
|
||||
# ANTHROPIC_BASE_URL and calls AWS itself, so Headroom saw nothing. Run
|
||||
# it in Anthropic mode against a proxy on the Bedrock backend instead;
|
||||
# the proxy calls Bedrock with the user's AWS credentials. The flag
|
||||
# often lives in a settings file, which outranks the shell, so it is
|
||||
# overridden with --settings below.
|
||||
# When that cannot be done safely, say Headroom is bypassed instead.
|
||||
bedrock_bypass = (
|
||||
_claude_bedrock_bypass_reason(
|
||||
_claude_env,
|
||||
managed_source=str(_claude_managed_settings_path()),
|
||||
backend=backend or os.environ.get("HEADROOM_BACKEND"),
|
||||
no_proxy=no_proxy,
|
||||
claude_args=claude_args,
|
||||
)
|
||||
if bedrock_on
|
||||
else None
|
||||
)
|
||||
use_bedrock = bedrock_on and bedrock_bypass is None
|
||||
if use_bedrock:
|
||||
# The proxy runs on the shell environment; give it the AWS settings
|
||||
# Claude Code would have used, including ones a settings file cleared.
|
||||
for key in _CLAUDE_BEDROCK_AWS_KEYS:
|
||||
if key in _claude_env:
|
||||
os.environ[key] = _claude_env[key][0]
|
||||
else:
|
||||
os.environ.pop(key, None)
|
||||
backend = backend or os.environ.get("HEADROOM_BACKEND") or "bedrock"
|
||||
# _start_proxy falls back to HEADROOM_REGION itself; it is repeated
|
||||
# here so AWS_REGION only applies when neither is set.
|
||||
region = (
|
||||
region
|
||||
or os.environ.get("HEADROOM_REGION")
|
||||
or os.environ.get("AWS_REGION")
|
||||
or os.environ.get("AWS_DEFAULT_REGION")
|
||||
)
|
||||
|
||||
# Issue #1353: when none of the explicit override channels (Foundry,
|
||||
# Vertex, ANTHROPIC_TARGET_API_URL) apply, inherit a pre-existing
|
||||
# ANTHROPIC_BASE_URL as the upstream so wrap doesn't silently revert
|
||||
@@ -6316,6 +6451,7 @@ def claude(
|
||||
if (
|
||||
not foundry_upstream
|
||||
and not use_vertex
|
||||
and not use_bedrock
|
||||
and not os.environ.get("ANTHROPIC_TARGET_API_URL")
|
||||
):
|
||||
custom_upstream = _detect_inbound_anthropic_upstream(port)
|
||||
@@ -6381,6 +6517,15 @@ def claude(
|
||||
click.echo(
|
||||
f" Foundry mode: ANTHROPIC_FOUNDRY_BASE_URL={_foundry_proxy_url(proxy_url)} → upstream {foundry_upstream}"
|
||||
)
|
||||
elif use_bedrock:
|
||||
click.echo(
|
||||
f" Bedrock mode: ANTHROPIC_BASE_URL={proxy_url} → Bedrock "
|
||||
f"[{region or 'proxy default region'}] with your AWS credentials"
|
||||
)
|
||||
click.echo(
|
||||
f" ({_CLAUDE_BEDROCK_ENV}={_bedrock_value} from {_bedrock_source}; "
|
||||
"set to 0 for this session so requests go through Headroom)"
|
||||
)
|
||||
elif custom_upstream:
|
||||
click.echo(f" ANTHROPIC_BASE_URL={proxy_url} → upstream {custom_upstream}")
|
||||
else:
|
||||
@@ -6423,6 +6568,12 @@ def claude(
|
||||
context_1m_enabled=context_1m,
|
||||
)
|
||||
)
|
||||
if bedrock_bypass:
|
||||
click.echo(
|
||||
f" Warning: Claude Code is in Bedrock mode ({_CLAUDE_BEDROCK_ENV} from "
|
||||
f"{_bedrock_source}) and will call Bedrock directly, so Headroom will see "
|
||||
f"none of its traffic: {bedrock_bypass}."
|
||||
)
|
||||
if claude_args:
|
||||
click.echo(f" Extra args: {' '.join(claude_args)}")
|
||||
_print_telemetry_notice()
|
||||
@@ -6442,6 +6593,27 @@ def claude(
|
||||
env["ANTHROPIC_FOUNDRY_BASE_URL"] = _foundry_proxy_url(proxy_url)
|
||||
else:
|
||||
env["ANTHROPIC_BASE_URL"] = proxy_url
|
||||
if use_bedrock:
|
||||
# Settings files outrank the shell, so the session's route goes in a
|
||||
# --settings override (only managed settings outrank it, and those
|
||||
# were checked above): every cloud mode off, base URL on the proxy.
|
||||
session_env = dict.fromkeys(_CLAUDE_CLOUD_MODE_ENVS, "0")
|
||||
session_env["ANTHROPIC_BASE_URL"] = proxy_url
|
||||
# Anthropic mode needs a credential to start; the proxy ignores it
|
||||
# and signs its Bedrock calls with the AWS credentials. The
|
||||
# placeholder goes in the override too, or a settings file that
|
||||
# cleared the credential would clear it as well; a shell key that
|
||||
# file cleared must not reach Claude Code next to it.
|
||||
if not any(key in _claude_env for key in CLAUDE_AUTH_KEYS):
|
||||
for key in CLAUDE_AUTH_KEYS:
|
||||
env.pop(key, None)
|
||||
session_env["ANTHROPIC_AUTH_TOKEN"] = "headroom-bedrock"
|
||||
env.update(session_env)
|
||||
claude_args = (
|
||||
"--settings",
|
||||
json.dumps({"env": session_env}),
|
||||
*claude_args,
|
||||
)
|
||||
|
||||
# Recover an older crashed wrap even when new project settings writes
|
||||
# are disabled. The marker records the prior value to restore; without
|
||||
@@ -6454,7 +6626,14 @@ def claude(
|
||||
foundry_mode=_settings_foundry[0], vertex_mode=_settings_vertex[0]
|
||||
),
|
||||
)
|
||||
if _claude_project_settings_enabled(project_settings):
|
||||
if use_bedrock and _claude_project_settings_enabled(project_settings):
|
||||
# Workers started outside this launch read only the settings files,
|
||||
# where Bedrock mode stays on, so a persisted base URL would do nothing.
|
||||
click.echo(
|
||||
" Skipping project-local Claude settings in Bedrock mode; "
|
||||
"daemon-spawned workers will call Bedrock directly."
|
||||
)
|
||||
elif _claude_project_settings_enabled(project_settings):
|
||||
_saved_base_url[0] = _write_claude_wrap_base_url(
|
||||
(
|
||||
_foundry_proxy_url(proxy_url)
|
||||
|
||||
@@ -14,6 +14,7 @@ from .runtime import (
|
||||
TOOL_SEARCH_ENV,
|
||||
claude_auth_conflict_message,
|
||||
claude_auth_conflict_sources,
|
||||
claude_effective_env,
|
||||
detect_claude_code_version,
|
||||
is_custom_anthropic_base_url,
|
||||
parse_claude_code_version,
|
||||
@@ -54,6 +55,7 @@ __all__ = [
|
||||
"TOOL_SEARCH_ENV",
|
||||
"claude_auth_conflict_message",
|
||||
"claude_auth_conflict_sources",
|
||||
"claude_effective_env",
|
||||
"detect_claude_code_version",
|
||||
"is_custom_anthropic_base_url",
|
||||
"parse_claude_code_version",
|
||||
|
||||
@@ -227,6 +227,24 @@ def remote_control_applies_to_auth(environ: Mapping[str, object]) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def claude_effective_env(
|
||||
*layers: tuple[str, Mapping[str, object]],
|
||||
) -> dict[str, tuple[str, str]]:
|
||||
"""``{key: (value, source)}`` after overlaying ``layers``, lowest precedence first.
|
||||
|
||||
An empty value clears an inherited one, as in Claude Code's own overlay.
|
||||
"""
|
||||
effective: dict[str, tuple[str, str]] = {}
|
||||
for source, values in layers:
|
||||
for key, raw in values.items():
|
||||
value = str(raw or "").strip()
|
||||
if value:
|
||||
effective[key] = (value, source)
|
||||
else:
|
||||
effective.pop(key, None)
|
||||
return effective
|
||||
|
||||
|
||||
def claude_auth_conflict_sources(
|
||||
*layers: tuple[str, Mapping[str, object]],
|
||||
) -> dict[str, str] | None:
|
||||
@@ -236,21 +254,9 @@ def claude_auth_conflict_sources(
|
||||
inherited value, matching environment overlay semantics. Credential values
|
||||
are deliberately never returned so callers cannot leak them in diagnostics.
|
||||
"""
|
||||
effective: dict[str, str] = {}
|
||||
sources: dict[str, str] = {}
|
||||
for source, values in layers:
|
||||
for key in CLAUDE_AUTH_KEYS:
|
||||
if key not in values:
|
||||
continue
|
||||
value = str(values.get(key) or "").strip()
|
||||
if value:
|
||||
effective[key] = value
|
||||
sources[key] = source
|
||||
else:
|
||||
effective.pop(key, None)
|
||||
sources.pop(key, None)
|
||||
effective = claude_effective_env(*layers)
|
||||
if all(key in effective for key in CLAUDE_AUTH_KEYS):
|
||||
return {key: sources[key] for key in CLAUDE_AUTH_KEYS}
|
||||
return {key: effective[key][1] for key in CLAUDE_AUTH_KEYS}
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -15,3 +15,14 @@ import pytest
|
||||
@pytest.fixture(autouse=True)
|
||||
def _tokensave_offline(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("HEADROOM_BINARIES_OFFLINE", "1")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_host_claude_managed_settings(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path_factory: pytest.TempPathFactory
|
||||
) -> None:
|
||||
"""Keep the machine's own Claude managed-settings file out of wrap tests."""
|
||||
from headroom.cli import wrap as wrap_mod
|
||||
|
||||
missing = tmp_path_factory.mktemp("managed") / "managed-settings.json"
|
||||
monkeypatch.setattr(wrap_mod, "_claude_managed_settings_path", lambda: missing)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"""Claude wrap Vertex upstream handoff tests."""
|
||||
"""Claude wrap cloud-provider (Vertex, Foundry, Bedrock) handoff tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -10,6 +12,7 @@ from click.testing import CliRunner
|
||||
|
||||
from headroom.cli import wrap as wrap_mod
|
||||
from headroom.cli.main import main
|
||||
from headroom.providers.claude.runtime import claude_effective_env
|
||||
from headroom.providers.registry import DEFAULT_VERTEX_API_URL
|
||||
|
||||
|
||||
@@ -95,6 +98,7 @@ def _invoke_wrap_claude(
|
||||
def fake_ensure_proxy(*args: object, **kwargs: object) -> tuple[None, int]:
|
||||
captured["ensure_args"] = args
|
||||
captured["ensure_kwargs"] = kwargs
|
||||
captured["proxy_environ"] = dict(os.environ)
|
||||
if actual_port is not None:
|
||||
return None, actual_port
|
||||
return None, args[0] if args else 8787
|
||||
@@ -712,3 +716,271 @@ def test_ensure_proxy_restarts_idle_proxy_to_clear_vertex_api_url(
|
||||
assert calls[1][0] == "start"
|
||||
assert calls[1][2]["vertex_api_url"] is None
|
||||
assert calls[1][2]["clear_vertex_api_url"] is True
|
||||
|
||||
|
||||
def _bedrock_settings(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
*,
|
||||
user_env: dict[str, str] | None = None,
|
||||
managed: str | None = None,
|
||||
) -> None:
|
||||
"""Point the user and managed settings at temp files, and undo AWS env lifts."""
|
||||
user = tmp_path / "user-settings.json"
|
||||
user.write_text(json.dumps({"env": user_env or {}}), encoding="utf-8")
|
||||
managed_path = tmp_path / "managed-settings.json"
|
||||
if managed is not None:
|
||||
managed_path.write_text(managed, encoding="utf-8")
|
||||
monkeypatch.setattr(wrap_mod, "claude_user_settings_path", lambda: user)
|
||||
monkeypatch.setattr(wrap_mod, "_claude_managed_settings_path", lambda: managed_path)
|
||||
for key in (*wrap_mod._CLAUDE_BEDROCK_AWS_KEYS, "HEADROOM_REGION", "HEADROOM_BACKEND"):
|
||||
monkeypatch.setenv(key, "unset") # record the original so the lift is undone
|
||||
monkeypatch.delenv(key)
|
||||
|
||||
|
||||
def _session_override(child_cmd: list[str]) -> dict[str, str]:
|
||||
"""The env block of the --settings override wrap put first, or {}."""
|
||||
if child_cmd[1:2] != ["--settings"]:
|
||||
return {}
|
||||
try:
|
||||
return json.loads(child_cmd[2])["env"]
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
return {}
|
||||
|
||||
|
||||
def _assert_routed_override(captured: dict, *, placeholder: bool) -> None:
|
||||
override = _session_override(captured["child_cmd"])
|
||||
expected = {
|
||||
"CLAUDE_CODE_USE_BEDROCK": "0",
|
||||
"CLAUDE_CODE_USE_VERTEX": "0",
|
||||
"CLAUDE_CODE_USE_FOUNDRY": "0",
|
||||
"ANTHROPIC_BASE_URL": captured["child_env"]["ANTHROPIC_BASE_URL"],
|
||||
}
|
||||
if placeholder:
|
||||
expected["ANTHROPIC_AUTH_TOKEN"] = "headroom-bedrock"
|
||||
assert override == expected
|
||||
assert override["ANTHROPIC_BASE_URL"].startswith("http://127.0.0.1:")
|
||||
|
||||
|
||||
def _claude_sees(captured: dict, user_env: dict[str, str]) -> dict[str, str]:
|
||||
"""The env Claude Code resolves: child env < user settings < --settings override."""
|
||||
effective = claude_effective_env(
|
||||
("shell", captured["child_env"]),
|
||||
("user", user_env),
|
||||
("--settings", _session_override(captured["child_cmd"])),
|
||||
)
|
||||
return {key: value for key, (value, _source) in effective.items()}
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_from_shell_routes_through_the_bedrock_backend(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path)
|
||||
captured, output = _invoke_wrap_claude(
|
||||
runner, monkeypatch, env={"CLAUDE_CODE_USE_BEDROCK": "1", "AWS_REGION": "us-west-2"}
|
||||
)
|
||||
|
||||
assert captured["ensure_kwargs"]["backend"] == "bedrock"
|
||||
assert captured["ensure_kwargs"]["region"] == "us-west-2"
|
||||
child = captured["child_env"]
|
||||
assert child["CLAUDE_CODE_USE_BEDROCK"] == "0"
|
||||
assert child["ANTHROPIC_BASE_URL"].startswith("http://127.0.0.1:")
|
||||
assert child["ANTHROPIC_AUTH_TOKEN"]
|
||||
_assert_routed_override(captured, placeholder=True)
|
||||
assert len(captured["child_cmd"]) == 3
|
||||
assert "Bedrock mode" in output
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_set_in_user_settings_is_overridden_for_the_session(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
# The flag and AWS settings live only in ~/.claude/settings.json, which
|
||||
# Claude Code obeys over the shell.
|
||||
_bedrock_settings(
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
user_env={
|
||||
"CLAUDE_CODE_USE_BEDROCK": "true",
|
||||
"AWS_PROFILE": "bedrock-sso",
|
||||
"AWS_REGION": "us-west-2",
|
||||
"ANTHROPIC_API_KEY": "sk-ant-dummy",
|
||||
},
|
||||
)
|
||||
captured, output = _invoke_wrap_claude(runner, monkeypatch, env={})
|
||||
|
||||
assert captured["ensure_kwargs"]["backend"] == "bedrock"
|
||||
assert captured["ensure_kwargs"]["region"] == "us-west-2"
|
||||
assert captured["proxy_environ"]["AWS_PROFILE"] == "bedrock-sso"
|
||||
_assert_routed_override(captured, placeholder=False)
|
||||
# A credential is already configured; adding another would conflict.
|
||||
assert "ANTHROPIC_AUTH_TOKEN" not in captured["child_env"]
|
||||
assert "CLAUDE_CODE_USE_BEDROCK=true from" in output
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_aws_key_cleared_in_settings_is_cleared_for_the_proxy(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(
|
||||
monkeypatch, tmp_path, user_env={"CLAUDE_CODE_USE_BEDROCK": "1", "AWS_PROFILE": ""}
|
||||
)
|
||||
captured, _output = _invoke_wrap_claude(
|
||||
runner, monkeypatch, env={"AWS_PROFILE": "shell-profile"}
|
||||
)
|
||||
|
||||
assert "AWS_PROFILE" not in captured["proxy_environ"]
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_region_flag_beats_aws_region(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path)
|
||||
captured, _output = _invoke_wrap_claude(
|
||||
runner,
|
||||
monkeypatch,
|
||||
env={"CLAUDE_CODE_USE_BEDROCK": "1", "AWS_REGION": "us-west-2"},
|
||||
extra_args=("--region", "eu-west-1"),
|
||||
)
|
||||
|
||||
assert captured["ensure_kwargs"]["region"] == "eu-west-1"
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_wins_over_vertex_like_claude_code(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path, user_env={"CLAUDE_CODE_USE_BEDROCK": "1"})
|
||||
captured, output = _invoke_wrap_claude(runner, monkeypatch, env={"CLAUDE_CODE_USE_VERTEX": "1"})
|
||||
|
||||
assert captured["ensure_kwargs"]["backend"] == "bedrock"
|
||||
assert "ANTHROPIC_VERTEX_BASE_URL" not in captured["child_env"]
|
||||
assert "Bedrock mode" in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("env", "extra_args", "managed", "reason"),
|
||||
[
|
||||
({}, (), '{"env":{"CLAUDE_CODE_USE_BEDROCK":"1"}}', "ask your admin"),
|
||||
({"ANTHROPIC_BEDROCK_BASE_URL": "https://gw.example"}, (), None, "gateway"),
|
||||
({"CLAUDE_CODE_SKIP_BEDROCK_AUTH": "1"}, (), None, "gateway"),
|
||||
({}, ("--no-proxy",), None, "--no-proxy"),
|
||||
({}, ("--backend", "anthropic"), None, "'anthropic'"),
|
||||
({"HEADROOM_BACKEND": "anyllm"}, (), None, "'anyllm'"),
|
||||
({}, ("--", "--settings", "mine.json"), None, "your own --settings"),
|
||||
({}, (), '{"env":{"CLAUDE_CODE_USE_VERTEX":"1"}}', "CLAUDE_CODE_USE_VERTEX is set"),
|
||||
({}, (), '{"env":{"ANTHROPIC_BASE_URL":"https://x.test"}}', "ANTHROPIC_BASE_URL is set"),
|
||||
],
|
||||
)
|
||||
def test_wrap_claude_bedrock_it_cannot_route_is_left_alone_with_a_warning(
|
||||
runner: CliRunner,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
env: dict[str, str],
|
||||
extra_args: tuple[str, ...],
|
||||
managed: str | None,
|
||||
reason: str,
|
||||
) -> None:
|
||||
managed_sets_bedrock = managed is not None and "CLAUDE_CODE_USE_BEDROCK" in managed
|
||||
_bedrock_settings(
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
user_env={} if managed_sets_bedrock else {"CLAUDE_CODE_USE_BEDROCK": "1"},
|
||||
managed=managed,
|
||||
)
|
||||
captured, output = _invoke_wrap_claude(runner, monkeypatch, env=env, extra_args=extra_args)
|
||||
|
||||
assert _session_override(captured["child_cmd"]) == {}
|
||||
assert "CLAUDE_CODE_USE_BEDROCK" not in captured["child_env"]
|
||||
assert "Headroom will see none of its traffic" in output
|
||||
assert reason in output
|
||||
|
||||
|
||||
def test_wrap_claude_unreadable_managed_settings_warns_instead_of_failing(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path, managed="{not json")
|
||||
captured, output = _invoke_wrap_claude(runner, monkeypatch, env={})
|
||||
|
||||
assert captured["child_cmd"] == ["/usr/bin/claude"]
|
||||
assert "could not read" in output
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_skips_project_settings(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path, user_env={"CLAUDE_CODE_USE_BEDROCK": "1"})
|
||||
captured, output = _invoke_wrap_claude(
|
||||
runner, monkeypatch, env={}, extra_args=("--project-settings",)
|
||||
)
|
||||
|
||||
assert "write_base_url_args" not in captured
|
||||
assert "Skipping project-local Claude settings in Bedrock mode" in output
|
||||
|
||||
|
||||
def test_wrap_claude_bedrock_flag_cleared_by_settings_is_not_bedrock(
|
||||
runner: CliRunner, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path, user_env={"CLAUDE_CODE_USE_BEDROCK": "0"})
|
||||
captured, output = _invoke_wrap_claude(
|
||||
runner, monkeypatch, env={"CLAUDE_CODE_USE_BEDROCK": "1"}
|
||||
)
|
||||
|
||||
assert captured["ensure_kwargs"]["backend"] is None
|
||||
assert captured["child_cmd"] == ["/usr/bin/claude"]
|
||||
assert "Bedrock" not in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("shell_env", "user_env"),
|
||||
[
|
||||
# Vertex or Foundry left on in any layer would win once Bedrock is off.
|
||||
({"CLAUDE_CODE_USE_VERTEX": "1"}, {"CLAUDE_CODE_USE_BEDROCK": "1"}),
|
||||
({}, {"CLAUDE_CODE_USE_BEDROCK": "1", "CLAUDE_CODE_USE_FOUNDRY": "1"}),
|
||||
# A settings base URL outranks the shell's proxy URL.
|
||||
({}, {"CLAUDE_CODE_USE_BEDROCK": "1", "ANTHROPIC_BASE_URL": "https://x.invalid"}),
|
||||
],
|
||||
ids=["shell_vertex", "settings_foundry", "settings_base_url"],
|
||||
)
|
||||
def test_wrap_claude_bedrock_session_override_beats_every_lower_layer(
|
||||
runner: CliRunner,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
shell_env: dict[str, str],
|
||||
user_env: dict[str, str],
|
||||
) -> None:
|
||||
_bedrock_settings(monkeypatch, tmp_path, user_env=user_env)
|
||||
captured, output = _invoke_wrap_claude(runner, monkeypatch, env=shell_env)
|
||||
|
||||
assert captured["ensure_kwargs"]["backend"] == "bedrock"
|
||||
_assert_routed_override(captured, placeholder=True)
|
||||
assert captured["child_env"]["CLAUDE_CODE_USE_VERTEX"] == "0"
|
||||
assert captured["child_env"]["CLAUDE_CODE_USE_FOUNDRY"] == "0"
|
||||
assert "Bedrock mode" in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("shell_env", "cleared"),
|
||||
[
|
||||
({"ANTHROPIC_API_KEY": "sk-ant-shell"}, {"ANTHROPIC_API_KEY": ""}),
|
||||
({"ANTHROPIC_AUTH_TOKEN": "shell-token"}, {"ANTHROPIC_AUTH_TOKEN": ""}),
|
||||
(
|
||||
{"ANTHROPIC_API_KEY": "sk-ant-shell"},
|
||||
{"ANTHROPIC_API_KEY": "", "ANTHROPIC_AUTH_TOKEN": ""},
|
||||
),
|
||||
],
|
||||
ids=["api_key_cleared", "auth_token_cleared", "both_keys_cleared"],
|
||||
)
|
||||
def test_wrap_claude_bedrock_credential_cleared_by_settings_still_gets_the_placeholder(
|
||||
runner: CliRunner,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
tmp_path: Path,
|
||||
shell_env: dict[str, str],
|
||||
cleared: dict[str, str],
|
||||
) -> None:
|
||||
user_env = {"CLAUDE_CODE_USE_BEDROCK": "1", **cleared}
|
||||
_bedrock_settings(monkeypatch, tmp_path, user_env=user_env)
|
||||
captured, _output = _invoke_wrap_claude(runner, monkeypatch, env=shell_env)
|
||||
|
||||
sees = _claude_sees(captured, user_env)
|
||||
assert sees["ANTHROPIC_AUTH_TOKEN"] == "headroom-bedrock"
|
||||
assert "ANTHROPIC_API_KEY" not in sees
|
||||
assert "ANTHROPIC_API_KEY" not in captured["child_env"]
|
||||
_assert_routed_override(captured, placeholder=True)
|
||||
|
||||
Reference in New Issue
Block a user