Problem
Anthropic's API natively supports defer_loading: true on tool definitions (docs). When set:
- Deferred tools are excluded from the system-prompt prefix (zero tokens upfront)
- Discovered tools are injected inline as
tool_reference blocks
- Prompt caching is preserved — the prefix is untouched
opencode currently has no way to pass defer_loading: true through to the Anthropic API, neither from config nor from the tool.definition plugin hook.
Proposed solution
Option A: Plugin hook field
Add deferLoading?: boolean to the tool.definition hook output:
"tool.definition"?: (input: {
toolID: string;
}, output: {
description: string;
parameters: any;
deferLoading?: boolean; // NEW — passed through to Anthropic API as defer_loading
}) => Promise<void>;
Option B: Config-level setting
Allow per-tool or per-MCP-server deferLoading in opencode.jsonc (similar to what the fork implements):
Option C: Both (recommended)
Config sets defaults, hook allows plugin overrides.
Why this is better than client-side filtering
- Prompt caching: Anthropic's server-side deferral preserves the cached prefix. Client-side filtering (like the fork's
continue in resolveTools()) changes the tool list every time a tool is discovered, busting the cache.
- Native integration:
tool_reference blocks are handled by Anthropic's infrastructure — no need to rebuild the tool list on discovery.
- Provider-agnostic path: The hook field can be ignored for non-Anthropic providers, making it a progressive enhancement.
Related
Problem
Anthropic's API natively supports
defer_loading: trueon tool definitions (docs). When set:tool_referenceblocksopencode currently has no way to pass
defer_loading: truethrough to the Anthropic API, neither from config nor from thetool.definitionplugin hook.Proposed solution
Option A: Plugin hook field
Add
deferLoading?: booleanto thetool.definitionhook output:Option B: Config-level setting
Allow per-tool or per-MCP-server
deferLoadinginopencode.jsonc(similar to what the fork implements):{ "mcp": { "some-server": { "command": "...", "deferLoading": true // all tools from this server are deferred } }, "toolSearch": { "alwaysLoad": ["read", "write", "edit", "bash"] } }Option C: Both (recommended)
Config sets defaults, hook allows plugin overrides.
Why this is better than client-side filtering
continueinresolveTools()) changes the tool list every time a tool is discovered, busting the cache.tool_referenceblocks are handled by Anthropic's infrastructure — no need to rebuild the tool list on discovery.Related
hiddenfield totool.definitionhook output for tool suppression #23297 — Addhiddenfield totool.definitionhook (complementary —hiddenfor client-side suppression,deferLoadingfor server-side)