Thread: how I wired streaming tool-use with the Claude API in 40 lines. The trick is buffering partial JSON until the block closes.
typescript6 lines
for await (const ev of stream) { if (ev.type === 'content_block_delta') buf += ev.delta.partial_json ?? ''; if (ev.type === 'content_block_stop') handleTool(JSON.parse(buf)), buf = '';}