Skip to content

Conversation

@yokomotod
Copy link
Contributor

Summary

Fixes an issue where thinking content blocks in Claude Code responses were not being parsed, resulting in empty AssistantMessage content arrays.

Changes

  • Added ThinkingBlock dataclass to handle thinking content with thinking and signature fields
  • Updated client parsing logic in _internal/client.py to recognize and create ThinkingBlock instances
  • Added comprehensive test coverage for thinking block functionality

Before

# Claude Code response with thinking block resulted in:
AssistantMessage(content=[])  # Empty content!

After

# Now correctly parses to:
AssistantMessage(content=[
    ThinkingBlock(thinking="...", signature="...")
])

Fixes #27

@yokomotod
Copy link
Contributor Author

@ltawfik I fixed types as well, and merged latest main branch. Can you review? thanks.

@Mng-dev-ai
Copy link
Contributor

@dicksontsai @shunfu is there a reason why this pr can't be merged?

@dicksontsai
Copy link
Collaborator

dicksontsai commented Aug 6, 2025

No specific reason, I can fix it up and merge it

@Mng-dev-ai
Copy link
Contributor

thank you!

@dicksontsai dicksontsai requested a review from shunfu August 6, 2025 20:31
@dicksontsai dicksontsai merged commit f1e6dda into anthropics:main Aug 7, 2025
5 checks passed
@yokomotod yokomotod deleted the content-thinking-block branch August 13, 2025 05:30
rushilpatel0 pushed a commit to codegen-sh/claude-code-sdk-python that referenced this pull request Aug 17, 2025
## Summary

Fixes an issue where `thinking` content blocks in Claude Code responses
were not being parsed, resulting in empty `AssistantMessage` content
arrays.

## Changes
- Added `ThinkingBlock` dataclass to handle thinking content with
`thinking` and `signature` fields
- Updated client parsing logic in `_internal/client.py` to recognize and
create `ThinkingBlock` instances
- Added comprehensive test coverage for thinking block functionality

## Before

```python
# Claude Code response with thinking block resulted in:
AssistantMessage(content=[])  # Empty content!
```

## After

```python
# Now correctly parses to:
AssistantMessage(content=[
    ThinkingBlock(thinking="...", signature="...")
])
```

Fixes anthropics#27

---------

Co-authored-by: Dickson Tsai <dickson@anthropic.com>
Signed-off-by: Rushil Patel <rpatel@codegen.com>
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.

Missing support for thinking content blocks

4 participants