Add option to return raw JSON from query in ClaudeCode SDK#1
Draft
Add option to return raw JSON from query in ClaudeCode SDK#1
Conversation
- Added `return_raw_json` boolean option to ClaudeCodeOptions to control output format. - Modified `query` function to yield raw JSON dicts when `return_raw_json` is true. - Added `process_query_raw` method in InternalClient to stream raw JSON data. - Updated type hints to reflect possible return of raw JSON or parsed messages. - Added tests and validation scripts for the new raw JSON feature. This feature enables users to receive unparsed JSON data directly from the query, providing more flexibility for downstream processing. Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
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
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.
Summary
return_raw_jsonoption inClaudeCodeOptionsto allow returning raw JSON data from queries instead of parsed messages.process_query_rawinInternalClientto handle raw JSON streaming.queryfunction to conditionally yield either parsed messages or raw JSON based on the new option.Changes
Core Functionality
return_raw_json: bool = FalsetoClaudeCodeOptions.process_query_rawasync generator method inInternalClientto stream raw JSON data.AsyncIterator[Union[Message, dict[str, Any]]]and added logic to yield raw JSON ifreturn_raw_jsonis enabled.Testing & Validation
test_raw_json.pyto test both raw JSON and normal parsed message modes.validate_code.pyandvalidate_implementation.pyto verify imports, types, syntax, and implementation correctness.Environment
test_envfor consistent testing environment.Test plan
test_raw_json.pyto verify that queries return raw JSON data when enabled and parsed messages otherwise.validate_code.pyandvalidate_implementation.pyto ensure code correctness and adherence to new feature requirements.queryfunction with both modes.This enhancement provides users with flexibility to access raw JSON responses directly, facilitating advanced use cases and debugging.
🌿 Generated by Terry
ℹ️ Tag @terragon-labs to ask questions and address PR feedback
📎 Task: https://www.terragonlabs.com/task/e150d50e-edb1-4c1c-bd5a-f9c50c4dea04