Skip to content

Commit 2a3f65e

Browse files
bloisclaude
andcommitted
feat: add max_thinking_tokens option to ClaudeAgentOptions
Add support for controlling the maximum number of tokens allocated to extended thinking blocks via the max_thinking_tokens parameter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fd4e33d commit 2a3f65e

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ venv/
2626
ENV/
2727
env/
2828
.venv
29+
uv.lock
2930

3031
# IDEs
3132
.vscode/

src/claude_agent_sdk/_internal/transport/subprocess_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ def _build_command(self) -> list[str]:
216216
# String mode: use --print with the prompt
217217
cmd.extend(["--print", "--", str(self._prompt)])
218218

219+
if self._options.max_thinking_tokens is not None:
220+
cmd.extend(
221+
["--max-thinking-tokens", str(self._options.max_thinking_tokens)]
222+
)
223+
219224
# Check if command line is too long (Windows limitation)
220225
cmd_str = " ".join(cmd)
221226
if len(cmd_str) > _CMD_LENGTH_LIMIT and self._options.agents:

src/claude_agent_sdk/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ class ClaudeAgentOptions:
554554
setting_sources: list[SettingSource] | None = None
555555
# Plugin configurations for custom plugins
556556
plugins: list[SdkPluginConfig] = field(default_factory=list)
557+
# Max tokens for thinking blocks
558+
max_thinking_tokens: int | None = None
557559

558560

559561
# SDK Control Protocol

tests/test_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ def test_build_command_with_options(self):
129129
assert "--max-turns" in cmd
130130
assert "5" in cmd
131131

132+
def test_build_command_with_max_thinking_tokens(self):
133+
"""Test building CLI command with max_thinking_tokens option."""
134+
transport = SubprocessCLITransport(
135+
prompt="test",
136+
options=make_options(max_thinking_tokens=5000),
137+
)
138+
139+
cmd = transport._build_command()
140+
assert "--max-thinking-tokens" in cmd
141+
assert "5000" in cmd
142+
132143
def test_build_command_with_add_dirs(self):
133144
"""Test building CLI command with add_dirs option."""
134145
from pathlib import Path

0 commit comments

Comments
 (0)