Thank you for your interest in contributing to the Claude Code SDK! This guide will help you get started.
- Python 3.10 or higher
- Node.js (for Claude Code CLI)
- Git
- Fork and clone the repository:
git clone https://github.com/YOUR_USERNAME/claude-code-sdk-python.git
cd claude-code-sdk-python- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install development dependencies:
make install-dev
# Or manually:
pip install -e ".[dev,websocket]"- Install pre-commit hooks:
pre-commit install- Install Claude Code CLI:
npm install -g @anthropic-ai/claude-code# Run all tests
make test
# Run with coverage
make test-cov
# Run specific test file
python -m pytest tests/test_client.py -v
# Run WebSocket tests
make test-websocket# Run all checks
make check-all
# Run linting
make lint
# Format code
make format
# Type checking
make type-check- Create a new branch:
git checkout -b feature/your-feature-name-
Make your changes, following the coding standards
-
Add tests for new functionality
-
Run tests and quality checks:
make check-all- Commit your changes:
git add .
git commit -m "feat: add new feature"- Follow PEP 8
- Use type hints for all functions
- Maximum line length: 88 characters (Black default)
- Use descriptive variable names
from typing import Optional, List, Dict, Any
async def process_data(
data: Dict[str, Any],
options: Optional[List[str]] = None
) -> Dict[str, Any]:
"""Process data with optional filters.
Args:
data: Input data to process
options: Optional list of processing options
Returns:
Processed data dictionary
"""
...Use Google-style docstrings:
def example_function(param1: str, param2: int) -> bool:
"""Brief description of function.
More detailed description if needed. Can span
multiple lines.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
Raises:
ValueError: When param1 is empty
TypeError: When param2 is not an integer
"""
...from claude_code_sdk import ClaudeSDKError
try:
result = await risky_operation()
except SpecificError as e:
# Handle specific error
logger.error(f"Operation failed: {e}")
raise ClaudeSDKError("User-friendly message") from eimport pytest
from unittest.mock import AsyncMock
class TestFeature:
"""Test suite for specific feature."""
@pytest.fixture
def mock_client(self):
"""Create mock client for testing."""
return AsyncMock()
async def test_happy_path(self, mock_client):
"""Test normal operation."""
# Arrange
mock_client.query.return_value = "expected"
# Act
result = await function_under_test(mock_client)
# Assert
assert result == "expected"
mock_client.query.assert_called_once()
async def test_error_handling(self, mock_client):
"""Test error scenarios."""
# Test specific error cases
...- Aim for >80% code coverage
- Test both happy paths and error cases
- Include integration tests for complex features
- Add docstrings to all public functions and classes
- Include usage examples in docstrings
- Document exceptions that can be raised
When adding new features:
- Update the README.md with usage examples
- Add detailed documentation in
docs/ - Update the API reference if needed
Follow conventional commits:
feat:New featurefix:Bug fixdocs:Documentation changesstyle:Code style changes (formatting, etc.)refactor:Code refactoringtest:Test additions or changeschore:Build process or auxiliary tool changes
Examples:
feat: add WebSocket server for real-time communication
fix: handle timeout errors in subprocess transport
docs: update README with WebSocket examples
- Update documentation for any new features
- Add tests for new functionality
- Ensure all tests pass
- Update the CHANGELOG.md if applicable
- Submit PR with clear description
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Tests added/updated
- [ ] All tests pass
- [ ] Coverage maintained/improved
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No new warningsclaude-code-sdk-python/
├── src/
│ └── claude_code_sdk/
│ ├── __init__.py # Public API
│ ├── types.py # Type definitions
│ ├── websocket_server.py # WebSocket server
│ └── _internal/ # Internal implementation
├── tests/ # Test files
├── docs/ # Documentation
├── examples/ # Usage examples
├── agent_system/ # Agent system (separate package)
└── Makefile # Development commands
- Check existing issues and discussions
- Ask questions in discussions
- Join our community chat (if available)
- Be respectful and inclusive
- Welcome newcomers and help them get started
- Focus on constructive feedback
- Follow the project's code of conduct
Thank you for contributing!