Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 23, 2025

Summary

This PR fixes the issue where Claude Code CLI responses in code mode were displaying unparsed JSON with escaped newlines (\n\n\n) instead of properly formatted text.

Problem

When Claude Code CLI returns responses (especially during errors or when output is truncated), the raw JSON was being displayed to users with escaped newline characters, making the output difficult to read and understand.

Solution

  • Added logic to detect and parse string chunks that contain JSON assistant messages
  • Extract and properly format text content from parsed messages
  • Handle malformed JSON gracefully by displaying it as-is (fallback behavior)
  • Refactored assistant message processing into a reusable method

Testing

  • Added comprehensive tests for the new parsing behavior
  • Tests cover successful parsing, malformed JSON handling, and mixed content types
  • All existing tests continue to pass

Related Issue

Fixes #6125

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Important

Fixes JSON parsing in Claude Code CLI, adds parsing method, and updates tests for proper formatting and error handling.

  • Behavior:
    • Fixes JSON parsing in Claude Code CLI responses to display formatted text instead of raw JSON with escaped newlines.
    • Adds attemptParseAssistantMessage() in claude-code.ts to parse JSON assistant messages.
    • Handles malformed JSON by displaying it as-is.
  • Refactoring:
    • Refactors assistant message processing into processAssistantMessage() in claude-code.ts.
  • Testing:
    • Adds tests in claude-code.spec.ts for JSON parsing, malformed JSON handling, and mixed content types.
    • Ensures all existing tests pass.

This description was created by Ellipsis for e28b9a9. You can customize this summary. It will automatically update as commits are pushed.

- Parse string chunks that contain JSON assistant messages
- Extract and properly format text content from parsed messages
- Handle malformed JSON gracefully by displaying as-is
- Add comprehensive tests for new parsing behavior

Fixes #6125
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 23, 2025 16:25
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 23, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 23, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 24, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 24, 2025
@daniel-lxs
Copy link
Member

The solution is to increase the default max output tokens, closing

@daniel-lxs daniel-lxs closed this Jul 28, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Claude Code CLI - API parsing and response issues

4 participants