Skip to content

The agent that grows with you

fix(anthropic): Opus 5.5 keeps thinking on, Sonnet 5.5 turns it off with between_tools

teknium1765342435609
diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py
index b359f7b4f73..be021eb4f8e 100644
--- a/agent/anthropic_adapter.py
+++ b/agent/anthropic_adapter.py
@@ -100,7 +100,10 @@ _NO_XHIGH_CLAUDE_SUBSTRINGS = ("claude-opus-4-6", "claude-opus-4.6", "claude-son
# Adaptive families where thinking is mandatory: ``thinking: {"type": "disabled"}`` answers HTTP
# 400 (Portal flags them ``reasoning.mandatory``). The failure is asymmetric — a missing entry
# 400s the turn, a spurious one only leaves thinking on — so when in doubt, add the family.
-_MANDATORY_THINKING_CLAUDE_SUBSTRINGS = ("claude-fable",)
+_MANDATORY_THINKING_CLAUDE_SUBSTRINGS = ("claude-fable", "claude-opus-5-5", "claude-opus-5.5")
+# Families whose documented "off" is ``thinking: {"type": "between_tools"}`` (no up-front thinking,
+# short notes between tool calls): ``disabled`` 400s there with a message pointing at it.
+_BETWEEN_TOOLS_OFF_CLAUDE_SUBSTRINGS = ("claude-sonnet-5-5", "claude-sonnet-5.5")
def _is_claude_model(model: str | None) -> bool:
@@ -190,7 +193,7 @@ def _accepts_thinking_disable(model: str) -> bool:
return (
_is_claude_model(model)
and _supports_adaptive_thinking(model)
- and not _model_matches(model, _MANDATORY_THINKING_CLAUDE_SUBSTRINGS)
+ and not _model_matches(model, _MANDATORY_THINKING_CLAUDE_SUBSTRINGS + _BETWEEN_TOOLS_OFF_CLAUDE_SUBSTRINGS)
)
@@ -603,6 +606,8 @@ def _thinking_kwargs(reasoning_config: Dict[str, Any], model: str, effective_max
# Adaptive models think by DEFAULT, so omitting the parameter is not a disable — the user
# silently keeps paying. Mandatory-thinking models 400 on the disable, so they keep the
# omission: a silently-ignored disable beats a dead turn.
+ if _model_matches(model, _BETWEEN_TOOLS_OFF_CLAUDE_SUBSTRINGS):
+ return {"thinking": {"type": "between_tools"}}
return {"thinking": {"type": "disabled"}} if _accepts_thinking_disable(model) else {}
if "haiku" in model.lower():
return {}
diff --git a/tests/agent/test_anthropic_thinking_disable.py b/tests/agent/test_anthropic_thinking_disable.py
index 2ab6b573742..94b8e37ac00 100644
--- a/tests/agent/test_anthropic_thinking_disable.py
+++ b/tests/agent/test_anthropic_thinking_disable.py
@@ -59,11 +59,19 @@ class TestThinkingOffIsSentExplicitly:
assert kwargs["thinking"] == {"type": "disabled"}
assert "output_config" not in kwargs
- def test_mandatory_thinking_models_keep_the_omission(self) -> None:
- """claude-fable answers a disable with HTTP 400, so don't send one."""
- kwargs = _kwargs("anthropic/claude-fable-5", {"enabled": False})
+ @pytest.mark.parametrize("model", ["anthropic/claude-fable-5", "claude-opus-5-5", "anthropic/claude-opus-5.5"])
+ def test_mandatory_thinking_models_keep_the_omission(self, model: str) -> None:
+ """Fable and Opus 5.5 answer a disable with HTTP 400, so don't send one."""
+ kwargs = _kwargs(model, {"enabled": False})
assert "thinking" not in kwargs
+ @pytest.mark.parametrize("model", ["claude-sonnet-5-5", "anthropic/claude-sonnet-5.5"])
+ def test_between_tools_is_the_off_switch_where_disabled_400s(self, model: str) -> None:
+ """Sonnet 5.5 400s on ``disabled``; its documented lowest setting is ``between_tools``.
+ Sonnet 5 still takes the plain disable."""
+ assert _kwargs(model, {"enabled": False})["thinking"] == {"type": "between_tools"}
+ assert _kwargs("claude-sonnet-5", {"enabled": False})["thinking"] == {"type": "disabled"}
+
def test_legacy_manual_thinking_models_keep_the_omission(self) -> None:
"""Pre-4.6 thinking is opt-in via budget_tokens: absence IS off."""
kwargs = _kwargs("claude-sonnet-4-5", {"enabled": False})