PRODUCTION SCENARIO
A streamed Claude response contains a text block and a tool_use block. Text fragments and tool-argument fragments arrive as content_block_delta events.
How should the client assemble them?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Buffer each delta under its block index and parse at content_block_stop
Every content_block_delta carries an index tying it to one block, and the arguments are complete when content_block_stop arrives for that index. The tool_use id appears once, on content_block_start, and never on a delta, so there is nothing on the delta to key a buffer on. A tolerant parse of a fragment such as {"location": returns a half-filled input that looks like a success. content_block_start announces the tool with an empty input, so dispatching there calls it with no arguments.
Official Source: https://platform.claude.com/docs/en/build-with-claude/streaming ↗