diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py index 04a7d0c137..327ca5773e 100644 --- a/hermes_cli/auth.py +++ b/hermes_cli/auth.py @@ -127,6 +127,7 @@ PROVIDER_REGISTRY: Dict[str, ProviderConfig] = { auth_type="api_key", inference_base_url=DEFAULT_GITHUB_MODELS_BASE_URL, api_key_env_vars=("COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"), + base_url_env_var="COPILOT_API_BASE_URL", ), "copilot-acp": ProviderConfig( id="copilot-acp", diff --git a/hermes_cli/copilot_auth.py b/hermes_cli/copilot_auth.py index 0db8637057..24859da1a7 100644 --- a/hermes_cli/copilot_auth.py +++ b/hermes_cli/copilot_auth.py @@ -117,14 +117,30 @@ def _gh_cli_candidates() -> list[str]: def _try_gh_cli_token() -> Optional[str]: - """Return a token from ``gh auth token`` when the GitHub CLI is available.""" + """Return a token from ``gh auth token`` when the GitHub CLI is available. + + When COPILOT_GH_HOST is set, passes ``--hostname`` so gh returns the + correct host's token. Also strips GITHUB_TOKEN / GH_TOKEN from the + subprocess environment so ``gh`` reads from its own credential store + (hosts.yml) instead of just echoing the env var back. + """ + hostname = os.getenv("COPILOT_GH_HOST", "").strip() + + # Build a clean env so gh doesn't short-circuit on GITHUB_TOKEN / GH_TOKEN + clean_env = {k: v for k, v in os.environ.items() + if k not in ("GITHUB_TOKEN", "GH_TOKEN")} + for gh_path in _gh_cli_candidates(): + cmd = [gh_path, "auth", "token"] + if hostname: + cmd += ["--hostname", hostname] try: result = subprocess.run( - [gh_path, "auth", "token"], + cmd, capture_output=True, text=True, timeout=5, + env=clean_env, ) except (FileNotFoundError, subprocess.TimeoutExpired) as exc: logger.debug("gh CLI token lookup failed (%s): %s", gh_path, exc)