forked from anthropics/claude-agent-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Preview #2
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
Draft
rushilpatel0
wants to merge
48
commits into
main
Choose a base branch
from
preview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Preview #2
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
- Uses claude-code-base-action for automated issue triage - Analyzes new issues and applies appropriate labels - Uses GitHub MCP server for issue operations - Requires ANTHROPIC_API_KEY secret to be configured 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Rushil Patel <[email protected]>
Previously was raised as a CLINotFoundError Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
…nthropics#82) * Adds commit signing * Converts sed pattern matching to a script to ensure we don't update version values unrelated to PyPI * Remove the `Publish to Test PyPI first'` step since it no longer works Signed-off-by: Rushil Patel <[email protected]>
This PR updates the version to 0.0.16 after publishing to PyPI. ## Changes - Updated version in `pyproject.toml` - Updated version in `src/claude_code_sdk/__init__.py` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/0.0.16/ - Install with: `pip install claude-code-sdk==0.0.16` 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
## Summary - Replace asyncio.create_task() with anyio task group for trio compatibility - Update client.py docstring example to use anyio.sleep - Add trio example demonstrating multi-turn conversation ## Details The SDK already uses anyio for most async operations, but one line was using asyncio.create_task() which broke trio compatibility. This PR fixes that by using anyio's task group API with proper lifecycle management. ### Changes: 1. **subprocess_cli.py**: Replace asyncio.create_task() with anyio task group, ensuring proper cleanup on disconnect 2. **client.py**: Update docstring example to use anyio.sleep instead of asyncio.sleep 3. **streaming_mode_trio.py**: Add new example showing how to use the SDK with trio ## Test plan - [x] All existing tests pass - [x] Manually tested with trio runtime (created test script that successfully runs multi-turn conversation) - [x] Linting and type checking pass 🤖 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Rushil Patel <[email protected]>
This PR updates the version to 0.0.17 after publishing to PyPI. ## Changes - Updated version in `pyproject.toml` - Updated version in `src/claude_code_sdk/__init__.py` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/0.0.17/ - Install with: `pip install claude-code-sdk==0.0.17` 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
- Add `settings` field to `ClaudeCodeOptions` to expose the `--settings` CLI flag - Allow SDK users to specify custom settings configuration path - Added `settings: str | None = None` field to `ClaudeCodeOptions` dataclass - Added CLI argument conversion logic in `SubprocessCLITransport` to pass `--settings` flag to Claude Code CLI - [x] All existing tests pass - [x] Linting passes (`python -m ruff check`) - [x] Type checking passes (`python -m mypy src/`) 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <[email protected]>
Fixes anthropics#90 Signed-off-by: Rushil Patel <[email protected]>
This PR updates the version to 0.0.18 after publishing to PyPI. ## Changes - Updated version in `pyproject.toml` - Updated version in `src/claude_code_sdk/__init__.py` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/0.0.18/ - Install with: `pip install claude-code-sdk==0.0.18` 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Rushil Patel <[email protected]>
…ropics#103) ## Summary Fixes a critical deadlock issue that occurs when MCP servers produce verbose stderr output. The SDK would hang indefinitely when the stderr pipe buffer filled up. ## The Problem The deadlock occurred due to sequential reading of subprocess streams: 1. SDK reads stdout completely before reading stderr 2. When stderr pipe buffer fills (64KB on Linux, 16KB on macOS), subprocess blocks on write 3. Subprocess can't continue to stdout, parent waits for stdout → **DEADLOCK** 🔒 ## The Solution Redirect stderr to a temporary file instead of a pipe: - **No pipe buffer** = no possibility of deadlock - Temp file can grow as needed (no 64KB limit) - Still capture stderr for error reporting (last 100 lines) - Works consistently across all async backends ## Implementation Details - `stderr=tempfile.NamedTemporaryFile()` instead of `stderr=PIPE` - Use `deque(maxlen=100)` to keep only recent stderr lines in memory - Temp file is automatically cleaned up on disconnect - Add `[stderr truncated, showing last 100 lines]` message when buffer is full ## Testing - Verified no deadlock with 150+ lines of stderr output - Confirmed stderr is still captured for error reporting - All existing tests pass - Works with asyncio, trio, and other anyio backends ## Impact - Fixes consistent hangs in production with MCP servers - No functional regression - stderr handling is preserved - Simpler than concurrent reading alternatives - More robust than pipe-based solutions Fixes the issue reported in Slack where SDK would hang indefinitely when receiving messages from MCP servers with verbose logging. 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <[email protected]> Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
This PR updates the version to 0.0.19 after publishing to PyPI. ## Changes - Updated version in `pyproject.toml` - Updated version in `src/claude_code_sdk/__init__.py` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/0.0.19/ - Install with: `pip install claude-code-sdk==0.0.19` 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Rushil Patel <[email protected]>
the `mcp_tools` field in `ClaudeCodeOptions` seems to have been there since the initial commit but I couldn't find any references in the repo, so I believe it may be vestigial and unused Signed-off-by: Rushil Patel <[email protected]>
…nthropics#111) ## Summary - Adds `extra_args` field to `ClaudeCodeOptions` to support passing arbitrary CLI flags - Enables forward compatibility with future CLI flags without requiring SDK updates - Supports both valued flags (`--flag value`) and boolean flags (`--flag`) ## Changes - Add `extra_args: dict[str, str | None]` field to `ClaudeCodeOptions` - Implement logic in `SubprocessCLITransport` to handle extra args: - `None` values create boolean flags (e.g., `{"verbose": None}` → `--verbose`) - String values create flags with arguments (e.g., `{"output": "json"}` → `--output json`) - Add comprehensive tests for the new functionality ## Test plan - [x] Added unit tests for settings file path handling - [x] Added unit tests for settings JSON object handling - [x] Added unit tests for extra_args with both valued and boolean flags - [x] All tests pass (`python -m pytest tests/`) - [x] Type checking passes (`python -m mypy src/`) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]> Signed-off-by: Rushil Patel <[email protected]>
) `claude`'s `--mcp-config` takes either a JSON file or string, so support this in `ClaudeCodeOptions` ``` --mcp-config <file or string> Load MCP servers from a JSON file or string ``` --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Sam Fu <[email protected]> Signed-off-by: Rushil Patel <[email protected]>
) Co-authored-by: Ashwin Bhat <[email protected]> Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
## 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 <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
Signed-off-by: Rushil Patel <[email protected]>
This PR updates the version to 0.0.20 after publishing to PyPI. ## Changes - Updated version in `pyproject.toml` - Updated version in `src/claude_code_sdk/__init__.py` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/0.0.20/ - Install with: `pip install claude-code-sdk==0.0.20` 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Rushil Patel <[email protected]>
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.
No description provided.