Skip to content

Improve tool result rendering for multiple text items#179

Open
jancurn wants to merge 1 commit intomainfrom
claude/update-render-call-tool-WP9X7
Open

Improve tool result rendering for multiple text items#179
jancurn wants to merge 1 commit intomainfrom
claude/update-render-call-tool-WP9X7

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented Apr 16, 2026

Summary

This PR enhances the rendering of tool call results by:

  1. Renaming extractSingleTextContent to extractAllTextContent to better reflect its new behavior
  2. Extending the function to handle multiple text content items (joining them with newlines) instead of only single items
  3. Hiding the _meta field in human-mode output to reduce noise while keeping it available in --json mode
  4. Improving documentation and test coverage

Key Changes

  • Function rename and behavior change: extractSingleTextContent()extractAllTextContent()

    • Now returns all text content joined with newlines when content is an array of only type: "text" items
    • Previously only worked with single text items
    • Returns undefined if content mixes text and non-text items (stricter validation)
  • Output filtering: Tool result rendering now strips the _meta field in human mode

    • Reduces protocol noise in CLI output
    • Full payload remains available via --json flag
    • Applied in renderCallToolResult() for both tools-call and tasks-result commands
  • Documentation improvements:

    • Updated JSDoc comments to clarify the new behavior
    • Added note that structuredContent is skipped when text content is rendered
    • Updated comments in output.ts and tools.ts to explain the rationale
  • Test updates:

    • Updated all test cases to use the new function name
    • Added test for mixed content types (text + non-text) returning undefined
    • Changed test expectation for multiple text items from undefined to joined text

Implementation Details

The refactored extractAllTextContent() uses early returns for validation, then iterates through all content items to collect text values. If any item is not a text type, the function returns undefined immediately, ensuring the caller only uses this path when all content is text.

https://claude.ai/code/session_011WvveGQ76Mq6vapAWxamVt

In human mode, hide the `_meta` field (still included in --json) and
treat any `content` array consisting of only `type: "text"` items the
same way a single text item was treated: print the joined texts inside
quadruple backticks and skip `structuredContent`. This gives LLMs and
humans a cleaner, unambiguous view when servers split text output across
multiple text blocks.

https://claude.ai/code/session_011WvveGQ76Mq6vapAWxamVt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants