[BUG] CLAUDE_CODE_USE_FOUNDRY=1 misdetects context budget as 200k → MCP tools deferred → 3-4x request inflation on agentic workloads (Foundry sibling of #51064; root cause matches #77247)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment
Claude Code v2.1.217 (latest), macOS · Backend: Microsoft Foundry, claude-sonnet-5 v2 (Hosted on Azure) GlobalStandard deployment, Sweden Central resource · Workload: non-interactive claude -p agentic pipeline with 4 MCP servers (~24 tools), compared A/B against api.anthropic.com with request capture.
Summary
On the Foundry path, the CLI budgets the context window at 200k for a natively-1M sonnet-5 deployment (the gateway misdetection described in #77247). With our toolset this crosses the tool-search deferral threshold, so MCP tool schemas are deferred behind DeferredToolPlaceholder/ToolSearch instead of sent inline — and the tool-starved agent inflates: same task needs 3–4x the requests and cannot converge. This is the Foundry instance of the Bedrock pattern in #51064.
Receipts
What Should Happen?
The Foundry path should (a) inherit the correct model context budget (sonnet-5 v2 serves 1M — verified via parity docs and direct API probes), and (b) fall under the same non-first-party tool-search default-off rule as other gateways. Happy to provide full capture logs and session timelines.
Error Messages/Logs
Steps to Reproduce
- /context, same machine/repo/tools, minutes apart:
api.anthropic.com (claude-sonnet-5): Tokens: 31.1k / 967k (3%)
Foundry (<sonnet-5 v2 deployment>): Tokens: 29.3k / 200k (15%)
Same payload: 3% of budget on first-party, 15% on Foundry — straddling the deferral threshold.
- Request capture (local logging relay), request #1 of the identical workload:
- api.anthropic.com: 30 inline tool definitions (all MCP tools present)
- Foundry: 6 tools only — Agent, DeferredToolPlaceholder, ReportFindings, Skill, ToolSearch, Workflow
- Flight numbers, identical task (support-ticket triage, dry run):
│ Backend │ Requests │ Tool calls │ Output tokens │ Result │
│ api.anthropic.com │ 18 │ 43 │ 48.6k │ ✅ completed 776s │
│ Foundry (tools deferred) │ 66–79 │ 108–132 │ 111–122k │ ❌ exceeded 1500s │
│ Foundry + workaround below │ 30 │ 58 │ 89k │ (separate serving stalls remained) │
- Workaround verified: ENABLE_TOOL_SEARCH=false restores 31 inline tools on the Foundry path and cut inflation ~60%. Note the env-vars docs say tool search should default OFF for non-first-party base URLs — the ANTHROPIC_FOUNDRY_BASE_URL/CLAUDE_CODE_USE_FOUNDRY path appears to escape that detection.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
v2.1.217
Platform
Other
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗