ToolSearch tool_reference content type causes API 400 error in long conversations
Bug Description
When ToolSearch returns a result with type: "tool_reference" in a tool_result content block, it causes a 400 error from the Anthropic API in subsequent turns as the conversation history grows.
Error Message
messages.166.content.0.tool_result.content.0: Input tag 'tool_reference' found using 'type' does not match any of the expected tags: 'document', 'image', 'search_result', 'text'
Steps to Reproduce
- In a Claude Code session, trigger a
ToolSearchcall (e.g.,select:Skill) - The tool returns a result containing:
``json``
{
"type": "tool_result",
"content": [{"type": "tool_reference", "tool_name": "Skill"}]
}
- Continue using the session for many turns
- Eventually the API returns a 400 error because
tool_referenceis not a valid content type intool_resultmessages
Expected Behavior
ToolSearch results should be serialized into API-compatible content types (e.g., text) before being included in conversation history sent to the API.
Actual Behavior
The raw tool_reference type is included in the conversation history, which the API rejects with a 400 error since it only accepts text, image, document, and search_result content types.
Workaround
Starting a new conversation clears the problematic message history.
Environment
- Platform: Linux (WSL2)
- Claude Code: latest
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗