Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions src/claude_agent_sdk/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"""Type definitions for Claude SDK."""
"""Type definitions for Claude SDK.

This module contains two kinds of types:

- **@dataclass types** (e.g., ``AgentDefinition``, ``TextBlock``) support attribute
access: ``obj.field_name``.
- **TypedDict types** (e.g., ``ThinkingConfigEnabled``, ``SyncHookJSONOutput``) are
plain ``dict`` objects at runtime. Use bracket access: ``obj["field_name"]``,
**not** ``obj.field_name`` (which raises ``AttributeError``).
"""

import sys
from collections.abc import Awaitable, Callable
Expand Down Expand Up @@ -393,6 +402,9 @@ class PermissionRequestHookSpecificOutput(TypedDict):
class AsyncHookJSONOutput(TypedDict):
"""Async hook output that defers hook execution.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``output["async_"]``, not ``output.async_``.

Fields:
async_: Set to True to defer hook execution. Note: This is converted to
"async" when sent to the CLI - use "async_" in your Python code.
Expand All @@ -411,6 +423,9 @@ class SyncHookJSONOutput(TypedDict):
This defines the structure for hook callbacks to control execution and provide
feedback to Claude.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``output["continue_"]``, not ``output.continue_``.

Common Control Fields:
continue_: Whether Claude should proceed after hook execution (default: True).
Note: This is converted to "continue" when sent to the CLI.
Expand Down Expand Up @@ -492,7 +507,11 @@ class HookMatcher:

# MCP Server config
class McpStdioServerConfig(TypedDict):
"""MCP stdio server configuration."""
"""MCP stdio server configuration.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["command"]``, not ``config.command``.
"""

type: NotRequired[Literal["stdio"]] # Optional for backwards compatibility
command: str
Expand All @@ -501,15 +520,23 @@ class McpStdioServerConfig(TypedDict):


class McpSSEServerConfig(TypedDict):
"""MCP SSE server configuration."""
"""MCP SSE server configuration.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["url"]``, not ``config.url``.
"""

type: Literal["sse"]
url: str
headers: NotRequired[dict[str, str]]


class McpHttpServerConfig(TypedDict):
"""MCP HTTP server configuration."""
"""MCP HTTP server configuration.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["url"]``, not ``config.url``.
"""

type: Literal["http"]
url: str
Expand Down Expand Up @@ -653,6 +680,9 @@ class SdkPluginConfig(TypedDict):
class SandboxNetworkConfig(TypedDict, total=False):
"""Network configuration for sandbox.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["allowLocalBinding"]``, not ``config.allowLocalBinding``.

Attributes:
allowUnixSockets: Unix socket paths accessible in sandbox (e.g., SSH agents).
allowAllUnixSockets: Allow all Unix sockets (less secure).
Expand Down Expand Up @@ -686,6 +716,9 @@ class SandboxSettings(TypedDict, total=False):
This controls how Claude Code sandboxes bash commands for filesystem
and network isolation.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``settings["enabled"]``, not ``settings.enabled``.

**Important:** Filesystem and network restrictions are configured via permission
rules, not via these sandbox settings:
- Filesystem read restrictions: Use Read deny rules
Expand Down Expand Up @@ -957,15 +990,33 @@ class SessionMessage:


class ThinkingConfigAdaptive(TypedDict):
"""Adaptive thinking configuration.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["type"]``, not ``config.type``.
"""

type: Literal["adaptive"]


class ThinkingConfigEnabled(TypedDict):
"""Enabled thinking configuration with a token budget.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["budget_tokens"]``, not ``config.budget_tokens``.
"""

type: Literal["enabled"]
budget_tokens: int


class ThinkingConfigDisabled(TypedDict):
"""Disabled thinking configuration.

Note: This is a TypedDict. Instances are plain dicts at runtime.
Use ``config["type"]``, not ``config.type``.
"""

type: Literal["disabled"]


Expand Down