[FEATURE] Add Anthropic Advanced Tool Use beta support
Summary
Adds support for Anthropic's Advanced Tool Use beta features via feature flag.
Closes #4713
Motivation
OpenCode currently loads all MCP tool definitions upfront. For power users with multiple MCP servers, this creates high token costs (50K-100K+ tokens before any work begins).
Anthropic released beta features specifically designed to address this:
- 85% token reduction with Tool Search Tool
- 37% token reduction with Programmatic Tool Calling
- Significant accuracy improvements with Tool Use Examples
This PR adds the foundation for these capabilities.
Changes
Beta Header Support
Added OPENCODE_ADVANCED_TOOL_USE feature flag that enables the advanced-tool-use-2025-11-20 beta:
// packages/opencode/src/provider/provider.ts
const advancedToolUseEnabled = Env.all()["OPENCODE_ADVANCED_TOOL_USE"] === "true"
const betaFeatures = [
"claude-code-20250219",
"interleaved-thinking-2025-05-14",
"fine-grained-tool-streaming-2025-05-14",
]
if (advancedToolUseEnabled) {
betaFeatures.push("advanced-tool-use-2025-11-20")
}
Usage
export OPENCODE_ADVANCED_TOOL_USE=true
opencode
Breaking Changes
None. Feature flag defaults to false. Without the flag, OpenCode behaves exactly as before.
Testing
- ✅ Typecheck passes
- ✅ No breaking changes introduced
- ✅ Feature flag defaults to off (safe to merge)
Next Steps
This PR lays the foundation for:
-
Tool Search Tool -
defer_loadingconfig for MCP tools - Programmatic Tool Calling - Code execution sandbox
-
Tool Use Examples -
input_examplesin tool schemas
I can implement these in follow-up PRs if this approach is approved.
References
- Anthropic docs: https://www.anthropic.com/engineering/advanced-tool-use
- Issue #4713: Feature request with community support
- Related: claude-code issue #12836 (100+ upvotes)
Author Notes
I'm a power user running OpenCode with 9+ MCP servers. This feature would save me 50K-70K tokens per session. Happy to implement the full feature set if this foundation is accepted.
Thanks for reviewing! 🚀