Skip to content

Feature Request: Configurable clear_thinking API feature #443

@Zeng-WH

Description

@Zeng-WH

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:

  1. Add an environment variable like USE_API_CLEAR_THINKING to enable/disable this feature
  2. Or add an option in ClaudeAgentOptions to 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

Additional Context

This is similar to the existing clear_tool_results feature which allows users to manage context by clearing tool result content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions