Skip to content

Studio: honor Claude Code's thinking-off setting on /v1/messages - #17557

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
oobabooga:studio-claude-code-thinking-off
Nov 12, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
oobabooga:studio-claude-code-thinking-off

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Turning thinking off in Claude Code does not stop a local model from thinking when Claude Code talks to Studio. With MAX_THINKING_TOKENS=0, or with thinking turned off in /config, a model whose template thinks by default (Qwen3, GLM and similar) still reasons on every turn. This was reported on Discord.

Cause

Claude Code only sends thinking: {"type": "disabled"} for Claude model ids it knows. For any other id, which is every model Studio serves, it sends thinking: {"type": "adaptive"} when thinking is on and leaves thinking out when thinking is off. The review capture in #9941 showed this on 2.1.251, and it is the same on 2.1.322:

Claude Code setting Model id thinking sent
default unsloth/Qwen3-0.6B-GGUF {"type": "adaptive"}
MAX_THINKING_TOKENS=0 unsloth/Qwen3-0.6B-GGUF absent
alwaysThinkingEnabled: false unsloth/Qwen3-0.6B-GGUF absent
MAX_THINKING_TOKENS=0 claude-sonnet-4-6 {"type": "disabled"}

AnthropicMessagesRequest.resolved_enable_thinking() reads a missing thinking as "use the model default", so the template default applies and the model thinks.

Fix

  • When a /v1/messages request comes from Claude Code, a missing or null thinking now resolves to off. Claude Code is recognized by its claude-cli/ User-Agent or its claude-code-* entry in anthropic-beta. Both are present under the environment unsloth start claude sets.
  • /v1/messages/count_tokens applies the same rule, so counting renders the same prompt as generation.

Behavior boundaries

  • Other clients are unchanged: a missing thinking still means the model default. This matches Anthropic's API, where the default depends on the model (per-model table), and llama.cpp's and vLLM's /v1/messages, which also leave the template default in place. Making a missing field mean off for every client would break clients that rely on that default.
  • enable_thinking and reasoning_effort sent in the body still take precedence over thinking, so unsloth start claude --reasoning on keeps thinking on.
  • Claude Code's CLAUDE_CODE_DISABLE_THINKING=1 sends the same request shape, so it now also turns thinking off. Claude Code's docs say the two settings behave the same on third-party providers.
  • output_config.effort, which Claude Code sends even with thinking off, still does not turn thinking back on.

Testing

Live, with Claude Code 2.1.322 (claude -p) against Studio on CPU with unsloth/Qwen3-0.6B-GGUF Q4_K_M, a model that thinks by default. Main is 5d5c1381b0.

Claude Code setting main this PR
default thinking block, 187 output tokens thinking block, 182 output tokens
MAX_THINKING_TOKENS=0 thinking block, 165 output tokens no thinking block, 13 output tokens
alwaysThinkingEnabled: false thinking block, 112 output tokens no thinking block, 12 output tokens

A direct /v1/messages request without thinking and with an Anthropic/Python User-Agent returns a thinking block on both main and this PR.

Automated:

  • 13 new tests in test_anthropic_messages.py. They cover header detection, precedence against explicit controls, and the generation and count paths through the real route handlers. 12 of them fail on main.
  • The 21 backend test files that cover the Anthropic path pass (5,183 passed, 1 skipped).

The in-session thinking toggle (Alt+T) was not tested.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T21:25:19.169114Z ae2784c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: ae2784c640

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Nov 12, 2026
danielhanchen added a commit that referenced this pull request Nov 12, 2026
…#17592)

## Summary

`Repo tests (CPU, studio)` fails on main since #17213, and on every PR
based on it (seen in staging runs for #17496 and #17557):

```
tests/studio/test_desktop_reliability_frontend_contract.py::test_fixed_sheets_start_below_the_custom_titlebar
E   assert 'set("--studio-custom-titlebar-height", usesCustomTitlebar ? "34px" : null)' in '...'
```

#17213 (F11 fullscreen) hides the custom titlebar in fullscreen, so the
`<html>` mirror in `provider.tsx` now reads:

```ts
const customTop = customTitlebarHidden ? "0px" : "34px";
set("--studio-custom-titlebar-height", usesCustomTitlebar ? customTop : null);
```

That is correct: in fullscreen the titlebar band is gone, and portalled
sheets should start at the top edge. The test pinned the old line
character for character, so it failed on a change that keeps everything
it was written to protect. The mirror is still there, and it still gives
34px whenever the titlebar shows.

## Change

`tests/studio/test_desktop_reliability_frontend_contract.py`:

- `_mirrored_titlebar_heights()` finds the
`set("--studio-custom-titlebar-height", usesCustomTitlebar ? <value> :
null)` call and resolves `<value>`. A string literal is read directly; a
local such as `customTop` is read from its `const` declaration.
- `test_fixed_sheets_start_below_the_custom_titlebar` now asserts that
the mirror exists, that it yields `34px`, and that it yields nothing
other than `34px` or the fullscreen `0px`. The rest of the test is
unchanged.
- `test_the_titlebar_mirror_reader_follows_a_local` covers the reader:
the old literal form, the new local form, and a different property that
must not match.

No app code changes.

## Testing

- `tests/studio/test_desktop_reliability_frontend_contract.py`: 46
passed (1 failed on main).
- With the mirror line removed from `provider.tsx`, the test fails. With
the shown height changed from `34px` to `30px`, it also fails.
@danielhanchen
danielhanchen merged commit 53eca64 into unslothai:main Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants