Rename ClaudeCodeOptions to ClaudeAgentOptions (#185)
Some checks failed
Lint / lint (push) Has been cancelled
Test / test (3.10) (push) Has been cancelled
Test / test (3.11) (push) Has been cancelled
Test / test (3.12) (push) Has been cancelled
Test / test (3.13) (push) Has been cancelled
Test / test-e2e (3.10) (push) Has been cancelled
Test / test-e2e (3.11) (push) Has been cancelled
Test / test-e2e (3.12) (push) Has been cancelled
Test / test-e2e (3.13) (push) Has been cancelled
Test / test-examples (3.10) (push) Has been cancelled
Test / test-examples (3.11) (push) Has been cancelled
Test / test-examples (3.12) (push) Has been cancelled
Test / test-examples (3.13) (push) Has been cancelled

This commit is contained in:
Dickson Tsai 2025-09-26 21:38:05 -07:00 committed by GitHub
parent dbb153b1f6
commit 0d2404e5d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 137 additions and 135 deletions

View file

@ -31,7 +31,7 @@ anyio.run(main)
`query()` is an async function for querying Claude Code. It returns an `AsyncIterator` of response messages. See [src/claude_code_sdk/query.py](src/claude_code_sdk/query.py).
```python
from claude_code_sdk import query, ClaudeCodeOptions, AssistantMessage, TextBlock
from claude_code_sdk import query, ClaudeAgentOptions, AssistantMessage, TextBlock
# Simple query
async for message in query(prompt="Hello Claude"):
@ -41,7 +41,7 @@ async for message in query(prompt="Hello Claude"):
print(block.text)
# With options
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt="You are a helpful assistant",
max_turns=1
)
@ -53,7 +53,7 @@ async for message in query(prompt="Tell me a joke", options=options):
### Using Tools
```python
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write", "Bash"],
permission_mode='acceptEdits' # auto-accept file edits
)
@ -71,7 +71,7 @@ async for message in query(
```python
from pathlib import Path
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
cwd="/path/to/project" # or Path("/path/to/project")
)
```
@ -94,7 +94,7 @@ For an end-to-end example, see [MCP Calculator](examples/mcp_calculator.py).
#### Creating a Simple Tool
```python
from claude_code_sdk import tool, create_sdk_mcp_server, ClaudeCodeOptions, ClaudeSDKClient
from claude_code_sdk import tool, create_sdk_mcp_server, ClaudeAgentOptions, ClaudeSDKClient
# Define a tool using the @tool decorator
@tool("greet", "Greet a user", {"name": str})
@ -113,7 +113,7 @@ server = create_sdk_mcp_server(
)
# Use it with Claude
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"tools": server},
allowed_tools=["mcp__tools__greet"]
)
@ -138,7 +138,7 @@ async with ClaudeSDKClient(options=options) as client:
```python
# BEFORE: External MCP server (separate process)
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={
"calculator": {
"type": "stdio",
@ -156,7 +156,7 @@ calculator = create_sdk_mcp_server(
tools=[add, subtract]
)
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"calculator": calculator}
)
```
@ -166,7 +166,7 @@ options = ClaudeCodeOptions(
You can use both SDK and external MCP servers together:
```python
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={
"internal": sdk_server, # In-process SDK server
"external": { # External subprocess server
@ -186,7 +186,7 @@ For more examples, see examples/hooks.py.
#### Example
```python
from claude_code_sdk import ClaudeCodeOptions, ClaudeSDKClient, HookMatcher
from claude_code_sdk import ClaudeAgentOptions, ClaudeSDKClient, HookMatcher
async def check_bash_command(input_data, tool_use_id, context):
tool_name = input_data["tool_name"]
@ -206,7 +206,7 @@ async def check_bash_command(input_data, tool_use_id, context):
}
return {}
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Bash"],
hooks={
"PreToolUse": [
@ -233,7 +233,7 @@ async with ClaudeSDKClient(options=options) as client:
## Types
See [src/claude_code_sdk/types.py](src/claude_code_sdk/types.py) for complete type definitions:
- `ClaudeCodeOptions` - Configuration options
- `ClaudeAgentOptions` - Configuration options
- `AssistantMessage`, `UserMessage`, `SystemMessage`, `ResultMessage` - Message types
- `TextBlock`, `ToolUseBlock`, `ToolResultBlock` - Content blocks

View file

@ -7,7 +7,7 @@ import pytest
from claude_code_sdk import (
AgentDefinition,
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
SystemMessage,
)
@ -17,7 +17,7 @@ from claude_code_sdk import (
@pytest.mark.asyncio
async def test_agent_definition():
"""Test that custom agent definitions work."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
agents={
"test-agent": AgentDefinition(
description="A test agent for verification",
@ -60,7 +60,7 @@ async def test_setting_sources_default():
settings_file.write_text('{"outputStyle": "local-test-style"}')
# Don't provide setting_sources - should default to no settings
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
cwd=project_dir,
max_turns=1,
)
@ -102,7 +102,7 @@ This is a test command.
)
# Use setting_sources=["user"] to exclude project settings
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
setting_sources=["user"],
cwd=project_dir,
max_turns=1,
@ -136,7 +136,7 @@ async def test_setting_sources_project_included():
settings_file.write_text('{"outputStyle": "local-test-style"}')
# Use setting_sources=["user", "project", "local"] to include local settings
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
setting_sources=["user", "project", "local"],
cwd=project_dir,
max_turns=1,

View file

@ -11,7 +11,7 @@ import pytest
from claude_code_sdk import ClaudeSDKClient
from claude_code_sdk.types import (
ClaudeCodeOptions,
ClaudeAgentOptions,
StreamEvent,
AssistantMessage,
SystemMessage,
@ -26,7 +26,7 @@ from claude_code_sdk.types import (
async def test_include_partial_messages_stream_events():
"""Test that include_partial_messages produces StreamEvent messages."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
include_partial_messages=True,
model="claude-sonnet-4-20250514",
max_turns=2,
@ -92,7 +92,7 @@ async def test_include_partial_messages_stream_events():
async def test_include_partial_messages_thinking_deltas():
"""Test that thinking content is streamed incrementally via deltas."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
include_partial_messages=True,
model="claude-sonnet-4-20250514",
max_turns=2,
@ -130,7 +130,7 @@ async def test_include_partial_messages_thinking_deltas():
async def test_partial_messages_disabled_by_default():
"""Test that partial messages are not included when option is not set."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
# include_partial_messages not set (defaults to False)
model="claude-sonnet-4-20250514",
max_turns=2,

View file

@ -9,7 +9,7 @@ from typing import Any
import pytest
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
create_sdk_mcp_server,
tool,
@ -34,7 +34,7 @@ async def test_sdk_mcp_tool_execution():
tools=[echo_tool],
)
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"test": server},
allowed_tools=["mcp__test__echo"],
)
@ -73,7 +73,7 @@ async def test_sdk_mcp_permission_enforcement():
tools=[echo_tool, greet_tool],
)
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"test": server},
disallowed_tools=["mcp__test__echo"], # Block echo tool
allowed_tools=["mcp__test__greet"], # But allow greet
@ -116,7 +116,7 @@ async def test_sdk_mcp_multiple_tools():
tools=[echo_tool, greet_tool],
)
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"multi": server},
allowed_tools=["mcp__multi__echo", "mcp__multi__greet"],
)
@ -153,7 +153,7 @@ async def test_sdk_mcp_without_permissions():
)
# No allowed_tools specified
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"noperm": server},
)

View file

@ -3,7 +3,7 @@
import pytest
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
PermissionResultAllow,
PermissionResultDeny,
@ -27,7 +27,7 @@ async def test_permission_callback_gets_called():
callback_invocations.append(tool_name)
return PermissionResultAllow()
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
can_use_tool=permission_callback,
)

View file

@ -13,7 +13,7 @@ import anyio
from claude_code_sdk import (
AgentDefinition,
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ResultMessage,
TextBlock,
query,
@ -24,7 +24,7 @@ async def code_reviewer_example():
"""Example using a custom code reviewer agent."""
print("=== Code Reviewer Agent Example ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
agents={
"code-reviewer": AgentDefinition(
description="Reviews code for best practices and potential issues",
@ -54,7 +54,7 @@ async def documentation_writer_example():
"""Example using a documentation writer agent."""
print("=== Documentation Writer Agent Example ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
agents={
"doc-writer": AgentDefinition(
description="Writes comprehensive documentation",
@ -83,7 +83,7 @@ async def multiple_agents_example():
"""Example with multiple custom agents."""
print("=== Multiple Agents Example ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
agents={
"analyzer": AgentDefinition(
description="Analyzes code structure and patterns",

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python
"""Example of using hooks with Claude Code SDK via ClaudeCodeOptions.
"""Example of using hooks with Claude Code SDK via ClaudeAgentOptions.
This file demonstrates various hook patterns using the hooks parameter
in ClaudeCodeOptions instead of decorator-based hooks.
in ClaudeAgentOptions instead of decorator-based hooks.
Usage:
./examples/hooks.py - List the examples
@ -15,7 +15,7 @@ import logging
import sys
from typing import Any
from claude_code_sdk import ClaudeCodeOptions, ClaudeSDKClient
from claude_code_sdk import ClaudeAgentOptions, ClaudeSDKClient
from claude_code_sdk.types import (
AssistantMessage,
HookContext,
@ -86,8 +86,8 @@ async def example_pretooluse() -> None:
print("=== PreToolUse Example ===")
print("This example demonstrates how PreToolUse can block some bash commands but not others.\n")
# Configure hooks using ClaudeCodeOptions
options = ClaudeCodeOptions(
# Configure hooks using ClaudeAgentOptions
options = ClaudeAgentOptions(
allowed_tools=["Bash"],
hooks={
"PreToolUse": [
@ -125,7 +125,7 @@ async def example_userpromptsubmit() -> None:
print("=== UserPromptSubmit Example ===")
print("This example shows how a UserPromptSubmit hook can add context.\n")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
hooks={
"UserPromptSubmit": [
HookMatcher(matcher=None, hooks=[add_custom_instructions]),

View file

@ -16,7 +16,7 @@ messages will include StreamEvent messages interspersed with regular messages.
import asyncio
from claude_code_sdk import ClaudeSDKClient
from claude_code_sdk.types import (
ClaudeCodeOptions,
ClaudeAgentOptions,
StreamEvent,
AssistantMessage,
UserMessage,
@ -27,7 +27,7 @@ from claude_code_sdk.types import (
async def main():
# Enable partial message streaming
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
include_partial_messages=True,
model="claude-sonnet-4-20250514",
max_turns=2,

View file

@ -13,7 +13,7 @@ import asyncio
from typing import Any
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
create_sdk_mcp_server,
tool,
)
@ -155,7 +155,7 @@ async def main():
# Configure Claude to use the calculator server with allowed tools
# Pre-approve all calculator MCP tools so they can be used without permission prompts
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"calc": calculator},
allowed_tools=[
"mcp__calc__add",

View file

@ -5,7 +5,7 @@ import anyio
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ResultMessage,
TextBlock,
query,
@ -28,7 +28,7 @@ async def with_options_example():
"""Example with custom options."""
print("=== With Options Example ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt="You are a helpful assistant that explains things simply.",
max_turns=1,
)
@ -47,7 +47,7 @@ async def with_tools_example():
"""Example using tools."""
print("=== With Tools Example ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write"],
system_prompt="You are a helpful file assistant.",
)

View file

@ -30,7 +30,7 @@ import sys
from pathlib import Path
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
SystemMessage,
)
@ -52,7 +52,7 @@ async def example_default():
sdk_dir = Path(__file__).parent.parent
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
cwd=sdk_dir,
)
@ -81,7 +81,7 @@ async def example_user_only():
# Use the SDK repo directory which has .claude/commands/commit.md
sdk_dir = Path(__file__).parent.parent
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
setting_sources=["user"],
cwd=sdk_dir,
)
@ -112,7 +112,7 @@ async def example_project_and_user():
sdk_dir = Path(__file__).parent.parent
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
setting_sources=["user", "project"],
cwd=sdk_dir,
)

View file

@ -21,7 +21,7 @@ import sys
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
CLIConnectionError,
ResultMessage,
@ -211,15 +211,15 @@ async def example_manual_message_handling():
async def example_with_options():
"""Use ClaudeCodeOptions to configure the client."""
"""Use ClaudeAgentOptions to configure the client."""
print("=== Custom Options Example ===")
# Configure options
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write"], # Allow file operations
system_prompt="You are a helpful coding assistant.",
env={
"ANTHROPIC_MODEL": "claude-3-7-sonnet-20250219",
"ANTHROPIC_MODEL": "claude-sonnet-4-20250514",
},
)

View file

@ -11,7 +11,7 @@ import trio
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
ResultMessage,
SystemMessage,
@ -46,7 +46,7 @@ def display_message(msg):
async def multi_turn_conversation():
"""Example of a multi-turn conversation using trio."""
async with ClaudeSDKClient(
options=ClaudeCodeOptions(model="claude-3-5-sonnet-20241022")
options=ClaudeAgentOptions(model="claude-3-5-sonnet-20241022")
) as client:
print("=== Multi-turn Conversation with Trio ===\n")

View file

@ -5,7 +5,7 @@ import anyio
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
TextBlock,
query,
)
@ -27,7 +27,7 @@ async def string_system_prompt():
"""Example with system_prompt as a string."""
print("=== String System Prompt ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt="You are a pirate assistant. Respond in pirate speak.",
)
@ -43,7 +43,7 @@ async def preset_system_prompt():
"""Example with system_prompt preset (uses default Claude Code prompt)."""
print("=== Preset System Prompt (Default) ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt={"type": "preset", "preset": "claude_code"},
)
@ -59,7 +59,7 @@ async def preset_with_append():
"""Example with system_prompt preset and append."""
print("=== Preset System Prompt with Append ===")
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt={
"type": "preset",
"preset": "claude_code",

View file

@ -10,7 +10,7 @@ import json
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
PermissionResultAllow,
PermissionResultDeny,
@ -107,7 +107,7 @@ async def main():
print("=" * 60)
# Configure options with our callback
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
can_use_tool=my_permission_callback,
# Use default permission mode to ensure callbacks are invoked
permission_mode="default",

View file

@ -19,7 +19,7 @@ from .types import (
AgentDefinition,
AssistantMessage,
CanUseTool,
ClaudeCodeOptions,
ClaudeAgentOptions,
ContentBlock,
HookCallback,
HookContext,
@ -144,7 +144,7 @@ def create_sdk_mcp_server(
Returns:
McpSdkServerConfig: A configuration object that can be passed to
ClaudeCodeOptions.mcp_servers. This config contains the server
ClaudeAgentOptions.mcp_servers. This config contains the server
instance and metadata needed for the SDK to route tool calls.
Example:
@ -164,7 +164,7 @@ def create_sdk_mcp_server(
... )
>>>
>>> # Use with Claude
>>> options = ClaudeCodeOptions(
>>> options = ClaudeAgentOptions(
... mcp_servers={"calc": calculator},
... allowed_tools=["add", "multiply"]
... )
@ -191,7 +191,7 @@ def create_sdk_mcp_server(
See Also:
- tool(): Decorator for creating tool functions
- ClaudeCodeOptions: Configuration for using servers with query()
- ClaudeAgentOptions: Configuration for using servers with query()
"""
from mcp.server import Server
from mcp.types import TextContent, Tool
@ -293,7 +293,7 @@ __all__ = [
"SystemMessage",
"ResultMessage",
"Message",
"ClaudeCodeOptions",
"ClaudeAgentOptions",
"TextBlock",
"ThinkingBlock",
"ToolUseBlock",

View file

@ -5,7 +5,7 @@ from dataclasses import replace
from typing import Any
from ..types import (
ClaudeCodeOptions,
ClaudeAgentOptions,
HookEvent,
HookMatcher,
Message,
@ -41,7 +41,7 @@ class InternalClient:
async def process_query(
self,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions,
options: ClaudeAgentOptions,
transport: Transport | None = None,
) -> AsyncIterator[Message]:
"""Process a query through transport and Query."""

View file

@ -18,7 +18,7 @@ from anyio.streams.text import TextReceiveStream, TextSendStream
from ..._errors import CLIConnectionError, CLINotFoundError, ProcessError
from ..._errors import CLIJSONDecodeError as SDKJSONDecodeError
from ..._version import __version__
from ...types import ClaudeCodeOptions
from ...types import ClaudeAgentOptions
from . import Transport
logger = logging.getLogger(__name__)
@ -32,7 +32,7 @@ class SubprocessCLITransport(Transport):
def __init__(
self,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions,
options: ClaudeAgentOptions,
cli_path: str | Path | None = None,
):
self._prompt = prompt

View file

@ -7,7 +7,7 @@ from dataclasses import replace
from typing import Any
from ._errors import CLIConnectionError
from .types import ClaudeCodeOptions, HookEvent, HookMatcher, Message, ResultMessage
from .types import ClaudeAgentOptions, HookEvent, HookMatcher, Message, ResultMessage
class ClaudeSDKClient:
@ -51,10 +51,10 @@ class ClaudeSDKClient:
exist.
"""
def __init__(self, options: ClaudeCodeOptions | None = None):
def __init__(self, options: ClaudeAgentOptions | None = None):
"""Initialize Claude SDK client."""
if options is None:
options = ClaudeCodeOptions()
options = ClaudeAgentOptions()
self.options = options
self._transport: Any | None = None
self._query: Any | None = None

View file

@ -6,13 +6,13 @@ from typing import Any
from ._internal.client import InternalClient
from ._internal.transport import Transport
from .types import ClaudeCodeOptions, Message
from .types import ClaudeAgentOptions, Message
async def query(
*,
prompt: str | AsyncIterable[dict[str, Any]],
options: ClaudeCodeOptions | None = None,
options: ClaudeAgentOptions | None = None,
transport: Transport | None = None,
) -> AsyncIterator[Message]:
"""
@ -52,7 +52,7 @@ async def query(
"parent_tool_use_id": None,
"session_id": "..."
}
options: Optional configuration (defaults to ClaudeCodeOptions() if None).
options: Optional configuration (defaults to ClaudeAgentOptions() if None).
Set options.permission_mode to control tool execution:
- 'default': CLI prompts for dangerous tools
- 'acceptEdits': Auto-accept file edits
@ -77,7 +77,7 @@ async def query(
# Code generation with specific settings
async for message in query(
prompt="Create a Python web server",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
system_prompt="You are an expert Python developer",
cwd="/home/user/project"
)
@ -114,7 +114,7 @@ async def query(
"""
if options is None:
options = ClaudeCodeOptions()
options = ClaudeAgentOptions()
os.environ["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py"

View file

@ -300,7 +300,7 @@ Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage | Strea
@dataclass
class ClaudeCodeOptions:
class ClaudeAgentOptions:
"""Query options for Claude SDK."""
allowed_tools: list[str] = field(default_factory=list)

View file

@ -4,7 +4,7 @@ from unittest.mock import AsyncMock, Mock, patch
import anyio
from claude_code_sdk import AssistantMessage, ClaudeCodeOptions, query
from claude_code_sdk import AssistantMessage, ClaudeAgentOptions, query
from claude_code_sdk.types import TextBlock
@ -52,7 +52,7 @@ class TestQueryFunction:
mock_process.return_value = mock_generator()
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write"],
system_prompt="You are helpful",
permission_mode="acceptEdits",
@ -109,7 +109,7 @@ class TestQueryFunction:
mock_transport.write = AsyncMock()
mock_transport.is_ready = Mock(return_value=True)
options = ClaudeCodeOptions(cwd="/custom/path")
options = ClaudeAgentOptions(cwd="/custom/path")
messages = []
async for msg in query(prompt="test", options=options):
messages.append(msg)

View file

@ -10,7 +10,7 @@ import pytest
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
CLINotFoundError,
ResultMessage,
query,
@ -132,7 +132,7 @@ class TestIntegration:
messages = []
async for msg in query(
prompt="Read /test.txt",
options=ClaudeCodeOptions(allowed_tools=["Read"]),
options=ClaudeAgentOptions(allowed_tools=["Read"]),
):
messages.append(msg)
@ -202,7 +202,7 @@ class TestIntegration:
messages = []
async for msg in query(
prompt="Continue",
options=ClaudeCodeOptions(continue_conversation=True),
options=ClaudeAgentOptions(continue_conversation=True),
):
messages.append(msg)

View file

@ -9,7 +9,7 @@ from typing import Any
import pytest
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
create_sdk_mcp_server,
tool,
)
@ -159,7 +159,7 @@ async def test_mixed_servers():
# Create configuration with both SDK and external servers
external_server = {"type": "stdio", "command": "echo", "args": ["test"]}
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
mcp_servers={"sdk": sdk_server, "external": external_server}
)

View file

@ -12,7 +12,7 @@ import pytest
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ClaudeSDKClient,
CLIConnectionError,
ResultMessage,
@ -471,7 +471,7 @@ class TestClaudeSDKClientStreaming:
"""Test client initialization with options."""
async def _test():
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
cwd="/custom/path",
allowed_tools=["Read", "Write"],
system_prompt="Be helpful",

View file

@ -13,7 +13,7 @@ from claude_code_sdk._internal.transport.subprocess_cli import (
_MAX_BUFFER_SIZE,
SubprocessCLITransport,
)
from claude_code_sdk.types import ClaudeCodeOptions
from claude_code_sdk.types import ClaudeAgentOptions
class MockTextReceiveStream:
@ -51,7 +51,7 @@ class TestSubprocessBuffering:
buffered_line = json.dumps(json_obj1) + "\n" + json.dumps(json_obj2)
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -86,7 +86,7 @@ class TestSubprocessBuffering:
buffered_line = json.dumps(json_obj1) + "\n" + json.dumps(json_obj2)
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -116,7 +116,7 @@ class TestSubprocessBuffering:
buffered_line = json.dumps(json_obj1) + "\n\n\n" + json.dumps(json_obj2)
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -162,7 +162,7 @@ class TestSubprocessBuffering:
part3 = complete_json[250:]
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -210,7 +210,7 @@ class TestSubprocessBuffering:
]
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -240,7 +240,7 @@ class TestSubprocessBuffering:
huge_incomplete = '{"data": "' + "x" * (_MAX_BUFFER_SIZE + 1000)
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()
@ -282,7 +282,7 @@ class TestSubprocessBuffering:
]
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
mock_process = MagicMock()

View file

@ -3,7 +3,7 @@
import pytest
from claude_code_sdk import (
ClaudeCodeOptions,
ClaudeAgentOptions,
HookContext,
HookMatcher,
PermissionResultAllow,
@ -258,8 +258,8 @@ class TestHookCallbacks:
assert '"processed": true' in last_response
class TestClaudeCodeOptionsIntegration:
"""Test that callbacks work through ClaudeCodeOptions."""
class TestClaudeAgentOptionsIntegration:
"""Test that callbacks work through ClaudeAgentOptions."""
def test_options_with_callbacks(self):
"""Test creating options with callbacks."""
@ -274,7 +274,7 @@ class TestClaudeCodeOptionsIntegration:
) -> dict:
return {}
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
can_use_tool=my_callback,
hooks={
"tool_use_start": [

View file

@ -8,7 +8,7 @@ import anyio
import pytest
from claude_code_sdk._internal.transport.subprocess_cli import SubprocessCLITransport
from claude_code_sdk.types import ClaudeCodeOptions
from claude_code_sdk.types import ClaudeAgentOptions
class TestSubprocessCLITransport:
@ -23,14 +23,14 @@ class TestSubprocessCLITransport:
patch("pathlib.Path.exists", return_value=False),
pytest.raises(CLINotFoundError) as exc_info,
):
SubprocessCLITransport(prompt="test", options=ClaudeCodeOptions())
SubprocessCLITransport(prompt="test", options=ClaudeAgentOptions())
assert "Claude Code requires Node.js" in str(exc_info.value)
def test_build_command_basic(self):
"""Test building basic CLI command."""
transport = SubprocessCLITransport(
prompt="Hello", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="Hello", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
cmd = transport._build_command()
@ -46,7 +46,7 @@ class TestSubprocessCLITransport:
transport = SubprocessCLITransport(
prompt="Hello",
options=ClaudeCodeOptions(),
options=ClaudeAgentOptions(),
cli_path=Path("/usr/bin/claude"),
)
@ -56,7 +56,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with system prompt as string."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
system_prompt="Be helpful",
),
cli_path="/usr/bin/claude",
@ -70,7 +70,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with system prompt preset."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
system_prompt={"type": "preset", "preset": "claude_code"},
),
cli_path="/usr/bin/claude",
@ -84,7 +84,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with system prompt preset and append."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
system_prompt={
"type": "preset",
"preset": "claude_code",
@ -103,7 +103,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with options."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
allowed_tools=["Read", "Write"],
disallowed_tools=["Bash"],
model="claude-3-5-sonnet",
@ -131,7 +131,7 @@ class TestSubprocessCLITransport:
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
add_dirs=["/path/to/dir1", Path("/path/to/dir2")]
),
cli_path="/usr/bin/claude",
@ -147,7 +147,9 @@ class TestSubprocessCLITransport:
"""Test session continuation options."""
transport = SubprocessCLITransport(
prompt="Continue from before",
options=ClaudeCodeOptions(continue_conversation=True, resume="session-123"),
options=ClaudeAgentOptions(
continue_conversation=True, resume="session-123"
),
cli_path="/usr/bin/claude",
)
@ -177,7 +179,7 @@ class TestSubprocessCLITransport:
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(),
options=ClaudeAgentOptions(),
cli_path="/usr/bin/claude",
)
@ -195,7 +197,7 @@ class TestSubprocessCLITransport:
# This test is simplified to just test the transport creation
# The full async stream handling is tested in integration tests
transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
prompt="test", options=ClaudeAgentOptions(), cli_path="/usr/bin/claude"
)
# The transport now just provides raw message reading via read_messages()
@ -210,7 +212,7 @@ class TestSubprocessCLITransport:
async def _test():
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(cwd="/this/directory/does/not/exist"),
options=ClaudeAgentOptions(cwd="/this/directory/does/not/exist"),
cli_path="/usr/bin/claude",
)
@ -225,7 +227,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with settings as file path."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(settings="/path/to/settings.json"),
options=ClaudeAgentOptions(settings="/path/to/settings.json"),
cli_path="/usr/bin/claude",
)
@ -238,7 +240,7 @@ class TestSubprocessCLITransport:
settings_json = '{"permissions": {"allow": ["Bash(ls:*)"]}}'
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(settings=settings_json),
options=ClaudeAgentOptions(settings=settings_json),
cli_path="/usr/bin/claude",
)
@ -250,7 +252,7 @@ class TestSubprocessCLITransport:
"""Test building CLI command with extra_args for future flags."""
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
options=ClaudeAgentOptions(
extra_args={
"new-flag": "value",
"boolean-flag": None,
@ -288,7 +290,7 @@ class TestSubprocessCLITransport:
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(mcp_servers=mcp_servers),
options=ClaudeAgentOptions(mcp_servers=mcp_servers),
cli_path="/usr/bin/claude",
)
@ -311,7 +313,7 @@ class TestSubprocessCLITransport:
# Test with string path
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(mcp_servers="/path/to/mcp-config.json"),
options=ClaudeAgentOptions(mcp_servers="/path/to/mcp-config.json"),
cli_path="/usr/bin/claude",
)
@ -323,7 +325,7 @@ class TestSubprocessCLITransport:
# Test with Path object
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(mcp_servers=Path("/path/to/mcp-config.json")),
options=ClaudeAgentOptions(mcp_servers=Path("/path/to/mcp-config.json")),
cli_path="/usr/bin/claude",
)
@ -337,7 +339,7 @@ class TestSubprocessCLITransport:
json_config = '{"mcpServers": {"server": {"type": "stdio", "command": "test"}}}'
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(mcp_servers=json_config),
options=ClaudeAgentOptions(mcp_servers=json_config),
cli_path="/usr/bin/claude",
)
@ -355,7 +357,7 @@ class TestSubprocessCLITransport:
"MY_TEST_VAR": test_value,
}
options = ClaudeCodeOptions(env=custom_env)
options = ClaudeAgentOptions(env=custom_env)
# Mock the subprocess to capture the env argument
with patch(
@ -402,7 +404,7 @@ class TestSubprocessCLITransport:
async def _test():
custom_user = "claude"
options = ClaudeCodeOptions(user=custom_user)
options = ClaudeAgentOptions(user=custom_user)
# Mock the subprocess to capture the env argument
with patch(

View file

@ -2,7 +2,7 @@
from claude_code_sdk import (
AssistantMessage,
ClaudeCodeOptions,
ClaudeAgentOptions,
ResultMessage,
)
from claude_code_sdk.types import (
@ -78,7 +78,7 @@ class TestOptions:
def test_default_options(self):
"""Test Options with default values."""
options = ClaudeCodeOptions()
options = ClaudeAgentOptions()
assert options.allowed_tools == []
assert options.system_prompt is None
assert options.permission_mode is None
@ -87,7 +87,7 @@ class TestOptions:
def test_claude_code_options_with_tools(self):
"""Test Options with built-in tools."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
allowed_tools=["Read", "Write", "Edit"], disallowed_tools=["Bash"]
)
assert options.allowed_tools == ["Read", "Write", "Edit"]
@ -95,35 +95,35 @@ class TestOptions:
def test_claude_code_options_with_permission_mode(self):
"""Test Options with permission mode."""
options = ClaudeCodeOptions(permission_mode="bypassPermissions")
options = ClaudeAgentOptions(permission_mode="bypassPermissions")
assert options.permission_mode == "bypassPermissions"
options_plan = ClaudeCodeOptions(permission_mode="plan")
options_plan = ClaudeAgentOptions(permission_mode="plan")
assert options_plan.permission_mode == "plan"
options_default = ClaudeCodeOptions(permission_mode="default")
options_default = ClaudeAgentOptions(permission_mode="default")
assert options_default.permission_mode == "default"
options_accept = ClaudeCodeOptions(permission_mode="acceptEdits")
options_accept = ClaudeAgentOptions(permission_mode="acceptEdits")
assert options_accept.permission_mode == "acceptEdits"
def test_claude_code_options_with_system_prompt_string(self):
"""Test Options with system prompt as string."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt="You are a helpful assistant.",
)
assert options.system_prompt == "You are a helpful assistant."
def test_claude_code_options_with_system_prompt_preset(self):
"""Test Options with system prompt preset."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt={"type": "preset", "preset": "claude_code"},
)
assert options.system_prompt == {"type": "preset", "preset": "claude_code"}
def test_claude_code_options_with_system_prompt_preset_and_append(self):
"""Test Options with system prompt preset and append."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
system_prompt={
"type": "preset",
"preset": "claude_code",
@ -138,13 +138,13 @@ class TestOptions:
def test_claude_code_options_with_session_continuation(self):
"""Test Options with session continuation."""
options = ClaudeCodeOptions(continue_conversation=True, resume="session-123")
options = ClaudeAgentOptions(continue_conversation=True, resume="session-123")
assert options.continue_conversation is True
assert options.resume == "session-123"
def test_claude_code_options_with_model_specification(self):
"""Test Options with model specification."""
options = ClaudeCodeOptions(
options = ClaudeAgentOptions(
model="claude-3-5-sonnet-20241022", permission_prompt_tool_name="CustomTool"
)
assert options.model == "claude-3-5-sonnet-20241022"