-
Notifications
You must be signed in to change notification settings - Fork 118
fix multi-line buffering issue #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ltawfik
merged 4 commits into
anthropics:main
from
Bradley-Butcher:fix/subprocess-buffering-issue
Jun 27, 2025
Merged
fix multi-line buffering issue #5
ltawfik
merged 4 commits into
anthropics:main
from
Bradley-Butcher:fix/subprocess-buffering-issue
Jun 27, 2025
+159
−10
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106-
added a commit
to 106-/claude-code-sdk-python
that referenced
this pull request
Jun 14, 2025
thanks @Bradley-Butcher . Do you mind re-creating the pr with commit signing as it's a requirement to merge the PR, thank you |
0403bae
to
57b3c70
Compare
Signed-off-by: Bradley-Butcher <[email protected]>
57b3c70
to
87e2699
Compare
Should be good @ltawfik |
- Convert async test to use anyio.run() pattern consistent with other tests - Remove unused CLIJSONDecodeError import - Add tests for JSON with embedded newlines - Add tests for multiple newlines between objects - All tests passing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Fixed formatting in test_subprocess_buffering.py - No functional changes, only code style improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Fixed quotes to use double quotes consistently - Adjusted line breaks per ruff formatter rules - No functional changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
dicksontsai
approved these changes
Jun 27, 2025
This was referenced Jun 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix subprocess transport handling of buffered JSON output
TL;DR
This PR fixes an issue where the SDK fails to parse output from the Claude CLI when multiple JSON objects are concatenated on a single line due to stdout buffering.
Problem
In certain environments, stdout buffering can cause multiple JSON objects to be delivered as a single line with embedded newlines (\n). When this happens, json.loads() successfully parses the first JSON object but then raises a JSONDecodeError: Extra data error because there's additional valid JSON after the first object.
Example of problematic output:
{"type": "message", "id": "msg1", "content": "First message"}\n{"type": "result", "id": "res1", "status": "completed"}
Solution
The fix modifies the receive_messages() method in SubprocessCLITransport to split each received line on newline characters before attempting JSON parsing. This allows multiple concatenated JSON objects to be properly handled.
Changes
Testing