Skip to content

Commit 9271e9b

Browse files
ashwin-antclaude
andcommitted
feat: add ThinkingConfig types and effort option to ClaudeAgentOptions
- Add ThinkingConfigAdaptive, ThinkingConfigEnabled, ThinkingConfigDisabled TypedDict types and a ThinkingConfig union type in types.py - Add `thinking: ThinkingConfig | None` field to ClaudeAgentOptions, which takes precedence over the deprecated `max_thinking_tokens` - Add `effort: Literal["low", "medium", "high", "max"] | None` field to ClaudeAgentOptions, passed via --effort CLI flag - Update subprocess_cli.py to resolve thinking config into --max-thinking-tokens: adaptive defaults to 32_000, enabled uses budget_tokens, disabled uses 0 - Export new ThinkingConfig types from the top-level package Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4703cae commit 9271e9b

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/claude_agent_sdk/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
SystemMessage,
6161
TextBlock,
6262
ThinkingBlock,
63+
ThinkingConfig,
64+
ThinkingConfigAdaptive,
65+
ThinkingConfigDisabled,
66+
ThinkingConfigEnabled,
6367
ToolPermissionContext,
6468
ToolResultBlock,
6569
ToolUseBlock,
@@ -334,6 +338,10 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> Any:
334338
"ClaudeAgentOptions",
335339
"TextBlock",
336340
"ThinkingBlock",
341+
"ThinkingConfig",
342+
"ThinkingConfigAdaptive",
343+
"ThinkingConfigEnabled",
344+
"ThinkingConfigDisabled",
337345
"ToolUseBlock",
338346
"ToolResultBlock",
339347
"ContentBlock",

src/claude_agent_sdk/_internal/transport/subprocess_cli.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,23 @@ def _build_command(self) -> list[str]:
297297
# Flag with value
298298
cmd.extend([f"--{flag}", str(value)])
299299

300-
if self._options.max_thinking_tokens is not None:
301-
cmd.extend(
302-
["--max-thinking-tokens", str(self._options.max_thinking_tokens)]
303-
)
300+
# Resolve thinking config → --max-thinking-tokens
301+
# `thinking` takes precedence over the deprecated `max_thinking_tokens`
302+
resolved_max_thinking_tokens = self._options.max_thinking_tokens
303+
if self._options.thinking is not None:
304+
t = self._options.thinking
305+
if t["type"] == "adaptive":
306+
if resolved_max_thinking_tokens is None:
307+
resolved_max_thinking_tokens = 32_000
308+
elif t["type"] == "enabled":
309+
resolved_max_thinking_tokens = t["budget_tokens"]
310+
elif t["type"] == "disabled":
311+
resolved_max_thinking_tokens = 0
312+
if resolved_max_thinking_tokens is not None:
313+
cmd.extend(["--max-thinking-tokens", str(resolved_max_thinking_tokens)])
314+
315+
if self._options.effort is not None:
316+
cmd.extend(["--effort", self._options.effort])
304317

305318
# Extract schema from output_format structure if provided
306319
# Expected: {"type": "json_schema", "schema": {...}}

src/claude_agent_sdk/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,22 @@ class StreamEvent:
696696
Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage | StreamEvent
697697

698698

699+
class ThinkingConfigAdaptive(TypedDict):
700+
type: Literal["adaptive"]
701+
702+
703+
class ThinkingConfigEnabled(TypedDict):
704+
type: Literal["enabled"]
705+
budget_tokens: int
706+
707+
708+
class ThinkingConfigDisabled(TypedDict):
709+
type: Literal["disabled"]
710+
711+
712+
ThinkingConfig = ThinkingConfigAdaptive | ThinkingConfigEnabled | ThinkingConfigDisabled
713+
714+
699715
@dataclass
700716
class ClaudeAgentOptions:
701717
"""Query options for Claude SDK."""
@@ -753,7 +769,12 @@ class ClaudeAgentOptions:
753769
# Plugin configurations for custom plugins
754770
plugins: list[SdkPluginConfig] = field(default_factory=list)
755771
# Max tokens for thinking blocks
772+
# @deprecated Use `thinking` instead.
756773
max_thinking_tokens: int | None = None
774+
# Controls extended thinking behavior. Takes precedence over max_thinking_tokens.
775+
thinking: ThinkingConfig | None = None
776+
# Effort level for thinking depth.
777+
effort: Literal["low", "medium", "high", "max"] | None = None
757778
# Output format for structured outputs (matches Messages API structure)
758779
# Example: {"type": "json_schema", "schema": {"type": "object", "properties": {...}}}
759780
output_format: dict[str, Any] | None = None

0 commit comments

Comments
 (0)