CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/API & SDK
API & SDK/2026-03-31Advanced

Claude API Streaming × Real-Time Chat UI: Production Implementation Guide

A practical guide to running Claude API streaming with Server-Sent Events in Next.js App Router at production grade, with measured latency, recovery patterns, and Cloudflare Workers edge-relay details from real indie operation

streaming21api38realtime3chat-uinext-jssse2production111

Premium Article

What Streaming Actually Solves

Claude API's streaming capabilities transform the traditional "request → wait for full response → display" paradigm into a dynamic "request → receive partial responses in real-time → update UI" experience. For chat applications, watching the AI respond as it "thinks" dramatically boosts user engagement and trust.

However, streaming introduces complexity. Mid-stream disconnections, timeouts, Tool Use state management, rate limit monitoring, and other non-functional requirements multiply rapidly.

I have been shipping iOS and Android apps as an indie developer since 2014, and the portfolio has accumulated more than 50 million downloads. Across that span I have implemented many flavors of real-time network experiences, and Claude API streaming sits on that continuum — with one twist: the AI's "thinking" can pause mid-flight, and a Tool Use can interrupt the flow. This guide attacks those rough edges from a real operations point of view, not a textbook one.

How Claude API Streaming Works

Server-Sent Events (SSE) Protocol

Claude API streaming uses the HTTP standard Server-Sent Events (SSE) protocol. SSE maintains an HTTP connection while continuously streaming multiple events from server to client.

SSE characteristics:

  • Text-based HTTP/1.1 standard protocol
  • Browser's EventSource API handles automatic reconnection with heartbeat
  • Simpler than WebSocket (but unidirectional only)
  • Excellent compatibility with firewalls, proxies, and CDNs

Claude API Event Stream Structure

A Claude streaming response consists of this event sequence:

event: message_start
data: {"type": "message_start", "message": {"id": "msg_...", "model": "claude-3-5-sonnet-20241022", "usage": {"input_tokens": 100}}}

event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello! I'm"}}

event: content_block_delta
data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": " Claude."}}

event: content_block_stop
data: {"type": "content_block_stop", "index": 0}

event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn"}, "usage": {"output_tokens": 42}}

event: message_stop
data: {"type": "message_stop"}

Event roles:

  • message_start: Stream initialization with model ID and input token count
  • content_block_start: Begin a text or Tool Use block
  • content_block_delta: Incremental text or Tool Use input data
  • content_block_stop: Block completion
  • message_delta: Message-level updates (stop reason, output tokens)
  • message_stop: Complete stream termination (safe to close connection)

Critical Implementation Details

Never assume event order: Implementations relying on arrival order are fragile. Always reconstruct content based on the index field.

Tool Use phases: When Tool Use appears during streaming, the flow is: Tool Use received completely → tool execution → continue streaming. This differs from text-only responses.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Measured numbers from indie operation: TTFB P50/P95, connection-hold rate, cache hit ratio, and stop-reason distribution that actually drive cost decisions
A connection-loss recovery design that uses conversation-history replay instead of resume-from-offset, surviving mid-Tool-Use disconnects without confusing the user
Cloudflare Workers × EventSource buffering pitfalls and the exact response headers, TransformStream tick, and heartbeat cadence that keep tokens flowing smoothly
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-06-27
When Claude API Streaming Stops Without an Error: Detecting Silent Stalls and Resuming Mid-Stream
How to catch the 'silent stall' where Claude API streaming stops with no exception at all, using a content-level watchdog that times the gap between tokens, plus a resume path that carries received text forward as an assistant prefill, and a four-layer timeout budget for long-running automation.
API & SDK2026-04-26
Building a Scalable Real-Time AI Chat Server with Claude API × WebSocket × Redis Pub/Sub — Node.js Production Architecture, Multi-User Management, and Cost Control
Running a real-time AI chat server on Claude API, WebSocket, and Redis Pub/Sub in production. SSE trade-offs, multi-instance routing, and how stop latency quietly corrupts per-user budgets — with the instrumentation code to measure it.
API & SDK2026-07-03
How Many Concurrent Claude API Requests Can You Actually Hold? Sizing Production Infrastructure with Little's Law and Measured Memory
Concurrency, queue depth, and memory are numbers you can derive, not guess. A working method for sizing Claude API production deployments with Little's Law, a memory probe, and a 30-minute load check — learned the hard way from an OOM crash.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →