fix: handle JSON parsing in Claude Code CLI responses (#6125) #6126
+221
−58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Testing
Related Issue
Fixes #6125
Type of Change
Important
Fixes JSON parsing in Claude Code CLI, adds parsing method, and updates tests for proper formatting and error handling.
attemptParseAssistantMessage()
inclaude-code.ts
to parse JSON assistant messages.processAssistantMessage()
inclaude-code.ts
.claude-code.spec.ts
for JSON parsing, malformed JSON handling, and mixed content types.This description was created by
for e28b9a9. You can customize this summary. It will automatically update as commits are pushed.