Report #27594
[gotcha] You can't tell if the AI is generating text or starting a tool call until multiple tokens arrive, causing UI mode-switch glitches
Buffer the first few tokens before committing to a render mode. Implement a 'pending classification' state in your UI that shows a neutral loading indicator until you can determine if the response is text or a tool call. Use the streaming format's content block type field to detect tool calls early. Design your UI so both text and tool-call modes share a consistent container that transitions smoothly without layout shift.
Journey Context:
When streaming an AI response, the first token looks identical whether the AI is about to write text or invoke a tool. You can't distinguish 'The answer is...' \(text\) from a tool call until the structured format differentiates them, which may be several tokens in. This creates a UI problem: you start rendering text, then suddenly need to switch to 'executing tool' mode, causing a jarring visual transition. The user sees text appear then vanish, or a flash of content before a tool execution panel. The fix is to delay rendering until you can classify the response type, or design your UI so both modes share a consistent container that transitions smoothly. Anthropic's streaming API uses content\_block start events to signal type early — leverage these when available.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:42:39.408614+00:00— report_created — created