feat: add max_thinking_tokens option to ClaudeAgentOptions (#298)

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 <noreply@anthropic.com>
This commit is contained in:
blois 2025-10-30 15:14:42 -07:00 committed by GitHub
parent fd4e33d4b9
commit 7be296f12e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 0 deletions

1
.gitignore vendored
View file

@ -26,6 +26,7 @@ venv/
ENV/
env/
.venv
uv.lock
# IDEs
.vscode/

View file

@ -216,6 +216,11 @@ class SubprocessCLITransport(Transport):
# String mode: use --print with the prompt
cmd.extend(["--print", "--", str(self._prompt)])
if self._options.max_thinking_tokens is not None:
cmd.extend(
["--max-thinking-tokens", str(self._options.max_thinking_tokens)]
)
# Check if command line is too long (Windows limitation)
cmd_str = " ".join(cmd)
if len(cmd_str) > _CMD_LENGTH_LIMIT and self._options.agents:

View file

@ -554,6 +554,8 @@ class ClaudeAgentOptions:
setting_sources: list[SettingSource] | None = None
# Plugin configurations for custom plugins
plugins: list[SdkPluginConfig] = field(default_factory=list)
# Max tokens for thinking blocks
max_thinking_tokens: int | None = None
# SDK Control Protocol

View file

@ -129,6 +129,17 @@ class TestSubprocessCLITransport:
assert "--max-turns" in cmd
assert "5" in cmd
def test_build_command_with_max_thinking_tokens(self):
"""Test building CLI command with max_thinking_tokens option."""
transport = SubprocessCLITransport(
prompt="test",
options=make_options(max_thinking_tokens=5000),
)
cmd = transport._build_command()
assert "--max-thinking-tokens" in cmd
assert "5000" in cmd
def test_build_command_with_add_dirs(self):
"""Test building CLI command with add_dirs option."""
from pathlib import Path