Repository navigation
Description
Environment
Where are you using Unsloth?
-
Unsloth desktop application
-
Unsloth web UI (
unsloth studio) -
Unsloth CLI (Claude Code subagent bridge,
unsloth_cli.claude_subagent_mcp) -
Unsloth version: 2026.8.21 (unsloth_zoo 2026.8.15)
-
OS: macOS 26.6.2 (Apple Silicon)
-
Claude Code version: 2.1.247
-
Model served:
unsloth/Qwen3.8-Flash-Next-GGUF(UD-Q4_K_XL), loaded and reachable on a LAN Unsloth Studio server -
Cloud Claude Code provider: Azure AI Foundry behind a corporate AI gateway (Azure API Management), configured with
CLAUDE_CODE_USE_FOUNDRY=1+ANTHROPIC_FOUNDRY_BASE_URL
Describe the bug
Setup: our normal (cloud) Claude Code usage runs through Azure AI Foundry, fronted by a corporate AI gateway (Azure API Management). Claude Code is pointed at it the documented way, via CLAUDE_CODE_USE_FOUNDRY=1 + ANTHROPIC_FOUNDRY_BASE_URL exported in the shell profile. Alongside that, we use Unsloth Studio's Claude Code subagent bridge to delegate tasks to a locally served model.
The subagent MCP bridge (unsloth_cli/claude_subagent_mcp.py) spawns a child claude process pointed at the local Unsloth server via ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN (built in _claude_local_env). Before launching, it only strips _CLAUDE_ENV_UNSET = ("ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN") from the inherited environment (unsloth_cli/commands/start.py, ~line 165).
However, Claude Code's Foundry/provider routing variables take precedence over ANTHROPIC_BASE_URL. The child inherits the Foundry config, e.g.:
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_BASE_URL="https://<corporate-gateway>.azure-api.net/anthropic-stream"and silently sends all "local agent" traffic to the Azure AI Foundry gateway instead of the local Unsloth server. Foundry has no deployment matching the local model id, so every unsloth_agent / unsloth_plan_agent tool call fails with:
[claude-code:unrecognized_model] {"model":"unsloth/Qwen3.8-Flash-Next-GGUF:UD-Q4_K_XL","query_source":"sdk"}
(HTTP 404, x-ms-error-code: DeploymentNotFound from the Azure gateway.)
The error is misleading — it looks like the local server doesn't know the model, when in fact the request never reached the local server at all. The same presumably applies to the Bedrock/Vertex routing toggles (CLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX).
Beyond the breakage, this is also a mild privacy/data-flow surprise: prompts the user intended to keep on-device get sent to a remote gateway.
Steps to reproduce
- Configure Claude Code for Azure AI Foundry in the shell profile:
CLAUDE_CODE_USE_FOUNDRY=1andANTHROPIC_FOUNDRY_BASE_URL=<Foundry endpoint or gateway in front of it>(any Foundry/Bedrock/Vertex routing config should reproduce it). - Start Unsloth Studio serving any model, and launch Claude Code with the Unsloth local-agent plugin (claude-subagent integration).
- Invoke the
unsloth_agentMCP tool with any task. - The tool call fails with
unrecognized_model/ 404;claude --debugon the reproduced child command shows POSTs going to the Foundry gateway URL, not toANTHROPIC_BASE_URL.
Direct curl to the local server's /v1/messages with the same model id succeeds, confirming the local server is healthy.
Expected behavior
The local subagent child should always talk to the local Unsloth server, regardless of any gateway/provider routing configured in the parent environment.
Suggested fix
Extend _CLAUDE_ENV_UNSET in unsloth_cli/commands/start.py to strip the provider-routing overrides:
_CLAUDE_ENV_UNSET = (
"ANTHROPIC_API_KEY",
"CLAUDE_CODE_OAUTH_TOKEN",
# Gateway/provider routing overrides ANTHROPIC_BASE_URL, so an inherited
# Foundry/Bedrock/Vertex setup silently sends local-agent traffic to the
# remote gateway instead of the local server.
"CLAUDE_CODE_USE_FOUNDRY",
"ANTHROPIC_FOUNDRY_BASE_URL",
"ANTHROPIC_FOUNDRY_RESOURCE",
"CLAUDE_CODE_USE_BEDROCK",
"CLAUDE_CODE_USE_VERTEX",
)I patched this locally and the subagent then works end-to-end against the local model. Since _CLAUDE_ENV_UNSET is shared with the main unsloth claude launch path, that flow benefits too.
Workaround
Unset CLAUDE_CODE_USE_FOUNDRY / ANTHROPIC_FOUNDRY_BASE_URL (or Bedrock/Vertex equivalents) in the shell before launching the Unsloth claude integration.
Activity
Shed inherited provider routing before spawning the local Claude suba…
strip inherited claude provider routing from local agent launches (un…