Claude 4.6 recommends using a new adaptive thinking mode, where Claude automatically determines whether to think and the depth of thinking based on the complexity of the question:
Copy
Ask AI
thinking={"type": "adaptive"}
thinking: {type: "enabled", budget_tokens: N} has been deprecated in 4.6 and will be removed in future versions.
When conversations approach the context window limit, Claude 4.6 can automatically perform server-side summary compaction of earlier content.Advantages:
Supports ultra-long conversations
No need for client-side summarization
Enhances agent’s ability for continuous dialogues
Note:
Automatic compaction may lose some details
It is recommended to evaluate tests in scenarios requiring strong consistency
Removed interleaved-thinking-2025-05-14 Beta Header: In 4.6, adaptive thinking now automatically supports interleaved thinking, and there is no need to add extra_headers. If still added, this header will be safely ignored.
Once extended thinking is enabled, the Claude 4 model’s Messages API will return a summary of Claude’s complete thought process. The summary provides all the intelligent advantages of extended thinking while preventing abuse.While the API remains consistent between Claude 3.7 and 4 models, the streaming response for extended thinking may return in a “chunked” mode, with possible delays between streaming events.The summary is processed by a model different from the one specified in your request. The thinking model will not see the summary output.
Claude 4 model supports interleaving tool usage with extended thinking, allowing for more natural conversations where tool usage and responses can be mixed with regular messages.Interleaved thinking is currently in testing. To enable interleaved thinking, add the test header interleaved-thinking-2025-05-14 in your API request:
{ "id": "msg_013Uf6CwwyjSe35n3yVaPbLM", "type": "message", "role": "assistant", "model": "claude-3-5-sonnet-20241022", "content": [ { "type": "text", "text": "That's one of humanity's most enduring and complex philosophical questions! While there's no universal answer, I aim to explore such questions thoughtfully while acknowledging their complexity. I try to focus on having meaningful conversations and helping where I can. What does meaning in life mean to you?" } ], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 14, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "output_tokens": 61 }}
Update your application to handle the new refusal stop reason:
Copy
Ask AI
if response.stop_reason == "refusal": print("Claude refuses to generate this content")elif response.stop_reason == "end_turn": print("Completed normally")
Claude can use text editing tools defined by Anthropic to view and modify text files, helping you debug, fix, and improve code or other text documents. This enables Claude to interact directly with your files, providing practical operational assistance rather than just suggestions.
Select compatible models. Anthropic’s text editing tools support the following Claude models:
Claude 4 Series Models (claude-opus-4-20250514, claude-sonnet-4-20250514): text_editor_20250429
Claude 3.7 Sonnet (claude-3-7-sonnet-20250219): text_editor_20250124
Claude 3.5 Sonnet (claude-3-5-sonnet-20241022): text_editor_20241022
Claude 4 models use a brand new text editing tool that is not compatible with older versions. Please ensure you are using the correct tool type and name.
Provide Claude with text editing tools (named str_replace_editor) through the Messages API: You need to install the anthropic package:
Copy
Ask AI
pip install anthropic
Invocation Examples:
Copy
Ask AI
import anthropicclient = anthropic.Anthropic( api_key="sk-***", # Replace with the key generated on AiHubMix base_url="https://aihubmix.com")response = client.messages.create( model="claude-sonnet-4-20250514", # or claude-opus-4-20250514 max_tokens=1024, tools=[ { "type": "text_editor_20250429", "name": "str_replace_based_edit_tool" } ], messages=[ { "role": "user", "content": "There's a syntax error in my primes.py file. Can you help me fix it?" } ])print("Response content:")for message in response.content: print(message.text)
undo_edit command: The Claude 4 model no longer supports the undo edit functionality.
Please remove any logic that depends on undo_edit from your code.
Response Example:
Copy
Ask AI
{ "id": "msg_bdrk_012xyNaFCQg4zsVcTk5VkDAe", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "I'd be happy to help you fix the syntax error in your `primes.py` file. First, let me take a look at the file to identify the issue." }, { "type": "tool_use", "text": "", "id": "toolu_bdrk_01P6jQG6suDSsDjzugqGVHWC", "name": "str_replace_based_edit_tool", "input": { "command": "view", "path": "/repo/primes.py" } } ], "model": "claude-sonnet-4-20250514", "stop_reason": "tool_use", "usage": { "input_tokens": 1042, "output_tokens": 115 }}