claude-code - 💡(How to fix) Fix [DOCS] `Build a streaming UI` miss the the check for in_tool

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

elif event_type == "content_block_delta":
      delta = event.get("delta", {})
      # Only stream text when not executing a tool
      if delta.get("type") == "text_delta" and not in_tool:
          sys.stdout.write(delta.get("text", ""))
          sys.stdout.flush()

---

elif event_type == "content_block_delta":
      delta = event.get("delta", {})
      delta_type = delta.get("type")

      if delta_type == "text_delta" and not in_tool:
          # Streaming text from Claude's response
          sys.stdout.write(delta.get("text", ""))
          sys.stdout.flush()

      elif delta_type == "input_json_delta" and in_tool:
          # ✅ Accumulate tool input JSON as it streams in
          tool_input += delta.get("partial_json", "")
elif event_type == "content_block_stop":
    if in_tool:
        # Tool call finished — tool_input now has the complete JSON
        print(f" done (input: {tool_input})", flush=True)
        in_tool = False
        tool_input = ""
RAW_BUFFERClick to expand / collapse

Documentation Type

Missing documentation (feature not documented)

Documentation Location

https://code.claude.com/docs/en/agent-sdk/streaming-output#build-a-streaming-ui

Section/Topic

build-a-streaming-ui

Current Documentation

The docs current show:

elif event_type == "content_block_delta":
      delta = event.get("delta", {})
      # Only stream text when not executing a tool
      if delta.get("type") == "text_delta" and not in_tool:
          sys.stdout.write(delta.get("text", ""))
          sys.stdout.flush()

What's Wrong or Missing?

The code miss the in_tool case process.

Suggested Improvement

elif event_type == "content_block_delta":
      delta = event.get("delta", {})
      delta_type = delta.get("type")

      if delta_type == "text_delta" and not in_tool:
          # Streaming text from Claude's response
          sys.stdout.write(delta.get("text", ""))
          sys.stdout.flush()

      elif delta_type == "input_json_delta" and in_tool:
          # ✅ Accumulate tool input JSON as it streams in
          tool_input += delta.get("partial_json", "")
elif event_type == "content_block_stop":
    if in_tool:
        # Tool call finished — tool_input now has the complete JSON
        print(f" done (input: {tool_input})", flush=True)
        in_tool = False
        tool_input = ""

Impact

Medium - Makes feature difficult to understand

Additional Context

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING