Skip to content

The agent that grows with you

fix(anthropic): preserve docs URL in OAuth sanitizer

Gaurav Saxenae218f3641c5e
diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py
index aeeed9cfc92..efc88ca2064 100644
--- a/agent/anthropic_adapter.py
+++ b/agent/anthropic_adapter.py
@@ -468,9 +468,11 @@ def _oauth_wire_namer(anthropic_tools: List[Dict[str, Any]]):
_OAUTH_SYSTEM_REPLACEMENTS = (
- ("Hermes Agent", "Claude Code"), ("Hermes agent", "Claude Code"),
- ("hermes-agent", "claude-code"), ("Nous Research", "Anthropic"),
+ ("Hermes Agent", "Claude Code"), ("Hermes agent", "Claude Code"), ("Nous Research", "Anthropic"),
)
+# The slug is rewritten only as a standalone word: inside the docs host it is an address the
+# model will dereference, and ``claude-code.nousresearch.com`` does not resolve (#48860).
+_OAUTH_SLUG_PATTERN = re.compile(r"\bhermes-agent\b(?!\.nousresearch\.com)")
def _apply_claude_code_identity(system, anthropic_tools, anthropic_messages, to_wire):
@@ -487,6 +489,7 @@ def _apply_claude_code_identity(system, anthropic_tools, anthropic_messages, to_
text = block.get("text", "")
for old, new in _OAUTH_SYSTEM_REPLACEMENTS:
text = text.replace(old, new)
+ text = _OAUTH_SLUG_PATTERN.sub("claude-code", text)
block["text"] = _apply_oauth_prose_aliases(text)
for tool in anthropic_tools or []:
if "name" in tool:
diff --git a/tests/agent/test_anthropic_adapter.py b/tests/agent/test_anthropic_adapter.py
index 5af08b5f369..53d185af156 100644
--- a/tests/agent/test_anthropic_adapter.py
+++ b/tests/agent/test_anthropic_adapter.py
@@ -1897,3 +1897,28 @@ class TestFinalPayloadHasNoBlankTextBlocks:
)
image_blocks = [b for b in tool_result_block["content"] if b.get("type") == "image"]
assert len(image_blocks) == 1
+
+
+def test_oauth_system_prompt_sanitizer_preserves_docs_url():
+ kwargs = build_anthropic_kwargs(
+ model="claude-sonnet-4-20250514",
+ messages=[
+ {
+ "role": "system",
+ "content": (
+ "Hermes Agent by Nous Research uses hermes-agent skills. "
+ "Docs: https://hermes-agent.nousresearch.com/docs"
+ ),
+ },
+ {"role": "user", "content": "Hi"},
+ ],
+ tools=None,
+ max_tokens=4096,
+ reasoning_config=None,
+ is_oauth=True,
+ )
+
+ system_text = "\n".join(block["text"] for block in kwargs["system"])
+ assert "Claude Code by Anthropic uses claude-code skills." in system_text
+ assert "https://hermes-agent.nousresearch.com/docs" in system_text
+ assert "claude-code.nousresearch.com" not in system_text