-
Notifications
You must be signed in to change notification settings - Fork 503
Description
Feature Request
Problem
The Claude API supports a clear_thinking_20250115 beta feature that clears thinking block content from previous turns to reduce token usage. However, this feature is currently controlled by a server-side Statsig feature flag (preserve_thinking) and cannot be configured by SDK users.
Requested Feature
Add support for users to configure the clear_thinking API feature, similar to how clear_tool_results can be enabled/disabled.
Specifically:
- Add an environment variable like
USE_API_CLEAR_THINKINGto enable/disable this feature - Or add an option in
ClaudeAgentOptionsto control this behavior
Use Case
When running long agentic tasks with extended thinking enabled, thinking blocks can consume significant tokens. Being able to clear thinking content from previous turns would help:
- Reduce token costs
- Stay within context limits for longer conversations
- Only preserve thinking when needed for debugging
Current Workaround
None available - the preserve_thinking flag is controlled via Statsig and the keep parameter in clear_thinking_20250115 is hardcoded to "all".
References
- Anthropic API documentation: https://docs.anthropic.com/en/api/beta-headers
- TypeScript SDK implementation preserves thinking by default via Statsig flag
Additional Context
This is similar to the existing clear_tool_results feature which allows users to manage context by clearing tool result content.