-
Notifications
You must be signed in to change notification settings - Fork 5k
[FEATURE] Add Anthropic Advanced Tool Use beta support #7390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
[FEATURE] Add Anthropic Advanced Tool Use beta support #7390
Conversation
Adds support for Anthropic's Advanced Tool Use beta features via feature flag. Features enabled by this beta: - Tool Search Tool: On-demand tool discovery (85% token reduction) - Programmatic Tool Calling: Code-based tool orchestration - Tool Use Examples: Example-based learning for better accuracy Usage: export OPENCODE_ADVANCED_TOOL_USE=true opencode When enabled, adds 'advanced-tool-use-2025-11-20' to the anthropic-beta header. When disabled, OpenCode behaves exactly as before. This is the foundation for implementing: 1. defer_loading config for MCP tools 2. Code execution sandbox for tool orchestration 3. input_examples for tool schemas Related: - Issue anomalyco#4713 - Anthropic docs: https://www.anthropic.com/engineering/advanced-tool-use Tested: - Typecheck passes - No breaking changes - Feature flag defaults to off
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for Anthropic's Advanced Tool Use beta features through a feature flag OPENCODE_ADVANCED_TOOL_USE. When enabled, it includes the advanced-tool-use-2025-11-20 beta header in Anthropic API requests, providing foundation for future token reduction features.
Key Changes:
- Adds
OPENCODE_ADVANCED_TOOL_USEenvironment variable support - Refactors hardcoded beta headers into a dynamic array
- Conditionally includes advanced tool use beta based on feature flag
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const CUSTOM_LOADERS: Record<string, CustomLoader> = { | ||
| async anthropic() { | ||
| // Add advanced tool use beta if feature flag is enabled | ||
| const advancedToolUseEnabled = Env.all()["OPENCODE_ADVANCED_TOOL_USE"] === "true" |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature flag should be defined in the Flag namespace (flag/flag.ts) using the truthy() helper function, consistent with other feature flags in the codebase. This approach provides a centralized location for all flags, makes them easier to discover, and follows the established pattern used by flags like OPENCODE_ENABLE_EXPERIMENTAL_MODELS, OPENCODE_DISABLE_CLAUDE_CODE, etc.
| const advancedToolUseEnabled = Env.all()["OPENCODE_ADVANCED_TOOL_USE"] === "true" | |
| const advancedToolUseEnabled = Flag.truthy("OPENCODE_ADVANCED_TOOL_USE") |
| "fine-grained-tool-streaming-2025-05-14", | ||
| ] | ||
|
|
||
| // Add advanced tool use beta if enabled |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is redundant with the comment on line 76. Consider removing one of them to reduce duplication.
| // Add advanced tool use beta if enabled |
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:
This PR adds the foundation for these capabilities.
Changes
Beta Header Support
Added
OPENCODE_ADVANCED_TOOL_USEfeature flag that enables theadvanced-tool-use-2025-11-20beta:Usage
export OPENCODE_ADVANCED_TOOL_USE=true opencodeBreaking Changes
None. Feature flag defaults to
false. Without the flag, OpenCode behaves exactly as before.Testing
Next Steps
This PR lays the foundation for:
defer_loadingconfig for MCP toolsinput_examplesin tool schemasI can implement these in follow-up PRs if this approach is approved.
References
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! 🚀