mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
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:
parent
fd4e33d4b9
commit
7be296f12e
4 changed files with 19 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -26,6 +26,7 @@ venv/
|
|||
ENV/
|
||||
env/
|
||||
.venv
|
||||
uv.lock
|
||||
|
||||
# IDEs
|
||||
.vscode/
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue