Skip to content

[FEATURE]: Support Anthropic defer_loading passthrough in tool definitions #23298

@M0Rf30

Description

@M0Rf30

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):

{
  "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

  • 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions