Skip to content

The agent that grows with you

fix(env): strip export prefix in dotenv key scan for cleanup (review fix)

keepConcentration61b2fa7937ff
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.py
index f10da837560..adc1e1ff8f2 100644
--- a/hermes_cli/env_loader.py
+++ b/hermes_cli/env_loader.py
@@ -84,6 +84,8 @@ def _env_keys_defined_in_dotenv(path: Path) -> set[str]:
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
+ if line.startswith("export "):
+ line = line[7:]
key = line.split("=", 1)[0].strip()
if key:
keys.add(key)
diff --git a/tests/hermes_cli/test_env_loader.py b/tests/hermes_cli/test_env_loader.py
index 305d75dbbdf..13503ef7d64 100644
--- a/tests/hermes_cli/test_env_loader.py
+++ b/tests/hermes_cli/test_env_loader.py
@@ -265,3 +265,19 @@ def test_known_key_explicitly_set_in_user_env_is_kept(tmp_path, monkeypatch):
load_hermes_dotenv(hermes_home=home)
assert os.getenv("HERMES_ACP_AUTH_METHOD") == "claude_code_cli"
+
+
+def test_export_prefixed_known_key_in_user_env_is_kept(tmp_path, monkeypatch):
+ """A known Hermes key defined with the bash-compatible ``export KEY=value``
+ form in the profile .env must be recognized as defined and survive the
+ cleanup - mirrors the ``export `` stripping in config.py's load_env()
+ (#6659).
+ """
+ home = tmp_path / "hermes"
+ home.mkdir()
+ (home / ".env").write_text(
+ "export HERMES_ACP_AUTH_METHOD=claude_code_cli\n", encoding="utf-8"
+ )
+ monkeypatch.setenv("HERMES_ACP_AUTH_METHOD", "cursor_login")
+ load_hermes_dotenv(hermes_home=home)
+ assert os.getenv("HERMES_ACP_AUTH_METHOD") == "claude_code_cli"