Follow Discord
Sweep 22 Oct 2026 · 21:04Z Build v2.1.309 528 read Stable v2.1.308 Latest v2.1.309 Next v2.1.309 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

handling-stop-reasons changedbuild-with-claude/handling-stop-reasons

Nearest release: v2.1.309, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+60added
Lines−52removed
From line 262 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits21to this page, all time

The whole hunk

from line 262, old and new numbered
/
lines
from line 262
262262 "content": [
263263 {"type": "tool_result", "tool_use_id": "toolu_123", "content": "6912"}
264264 ],
265 }, # Just the tool_result, no additional text
265 }, # Only the tool_result, no additional text
266266 ]
267267 ```
268268 
from line 306
306306 },
307307 {
308308 role: "user",
309 // Just the tool_result, no additional text
309 // Only the tool_result, no additional text
310310 content: [{ type: "tool_result", tool_use_id: "toolu_123", content: "6912" }]
311311 }
312312 ];
from line 354
354354 },
355355 new UserMessageParam
356356 {
357 // Just the tool_result, no additional text
357 // Only the tool_result, no additional text
358358 Content = new List<ContentBlockParam>
359359 {
360360 new ToolResultBlockParam { ToolUseID = "toolu_123", Content = "6912" }
from line 384
384384 anthropic.NewAssistantMessage(
385385 anthropic.NewToolUseBlock("toolu_123", input, "calculator"),
386386 ),
387 // Just the tool_result, no additional text
387 // Only the tool_result, no additional text
388388 anthropic.NewUserMessage(
389389 anthropic.NewToolResultBlock("toolu_123", "6912", false),
390390 ),
from line 408
408408 MessageParam.ofAssistantOfContentBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))),
409409 MessageParam.ofUserOfContentBlockParams(List.of(
410410 ContentBlockParam.ofToolResult(
411 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build()),
411 ToolResultBlockParam.builder()
412 .toolUseId("toolu_123")
413 .content("6912")
414 .build()),
412415 // Don't add text after tool_result
413 ContentBlockParam.ofText(TextBlockParam.builder().text("Here's the result").build())
416 ContentBlockParam.ofText(TextBlockParam.builder()
417 .text("Here's the result")
418 .build())
414419 ))
415420 );
416421 
from line 423
418423 messages = List.of(
419424 MessageParam.ofUser("Calculate the sum of 1234 and 5678"),
420425 MessageParam.ofAssistantOfContentBlockParams(List.of(ContentBlockParam.ofToolUse(toolUse))),
421 // Just the tool_result, no additional text
426 // Only the tool_result, no additional text
422427 MessageParam.ofUserOfContentBlockParams(List.of(
423428 ContentBlockParam.ofToolResult(
424 ToolResultBlockParam.builder().toolUseId("toolu_123").content("6912").build())
429 ToolResultBlockParam.builder()
430 .toolUseId("toolu_123")
431 .content("6912")
432 .build())
425433 ))
426434 );
427435 ```
from line 475
467475 ],
468476 [
469477 'role' => 'user',
470 // Just the tool_result, no additional text
478 // Only the tool_result, no additional text
471479 'content' => [
472480 ['type' => 'tool_result', 'tool_use_id' => 'toolu_123', 'content' => '6912'],
473481 ],
from line 524
516524 },
517525 {
518526 role: "user",
519 # Just the tool_result, no additional text
527 # Only the tool_result, no additional text
520528 content: [
521529 { type: "tool_result", tool_use_id: "toolu_123", content: "6912" }
522530 ]
from line 855
847855 $response = $client->messages->create(
848856 maxTokens: 10,
849857 messages: [['role' => 'user', 'content' => 'Explain quantum physics']],
850 model: 'claude-opus-5-5',
858 model: Model::CLAUDE_OPUS_5_5,
851859 );
852860 
853861 if ($response->stopReason === 'max_tokens') {
from line 1159
11511159 $response = $client->messages->create(
11521160 maxTokens: 1024,
11531161 messages: [['role' => 'user', 'content' => 'Generate text until you say END']],
1154 model: 'claude-opus-5-5',
1162 model: Model::CLAUDE_OPUS_5_5,
11551163 stopSequences: ['END', 'STOP'],
11561164 );
11571165 
from line 1248
12401248 
12411249 
12421250 def execute_tool(name, tool_input):
1243 """Execute a tool and return the result."""
1251 """Run a tool and return the result."""
12441252 return f"Weather in {tool_input.get('location', 'unknown')}: 72°F"
12451253 
12461254 
from line 1260
12521260 )
12531261 
12541262 if response.stop_reason == "tool_use":
1255 # Extract and execute the tool
1263 # Extract and run the tool
12561264 for block in response.content:
12571265 if block.type == "tool_use":
12581266 result = execute_tool(block.name, block.input)
from line 1293
12851293 });
12861294 
12871295 if (response.stop_reason === "tool_use") {
1288 // Extract and execute the tool
1296 // Extract and run the tool
12891297 for (const block of response.content) {
12901298 if (block.type === "tool_use") {
12911299 const result = executeTool(block.name, block.input as Record<string, string>);
from line 1332
13241332 
13251333 if (response.StopReason == "tool_use")
13261334 {
1327 // Extract and execute the tool
1335 // Extract and run the tool
13281336 foreach (var block in response.Content)
13291337 {
13301338 if (block.TryPickToolUse(out var toolUse))
13311339 {
1332 // Execute toolUse.Name with toolUse.Input and return the result to Claude
1340 // Run toolUse.Name with toolUse.Input and return the result to Claude
13331341 }
13341342 }
13351343 }
from line 1370
13621370 }
13631371 
13641372 if response.StopReason == "tool_use" {
1365 // Extract and execute the tool
1373 // Extract and run the tool
13661374 for _, block := range response.Content {
13671375 if toolUse, ok := block.AsAny().(anthropic.ToolUseBlock); ok {
13681376 fmt.Println(toolUse.Name, toolUse.Input)
from line 1405
13971405 );
13981406 
13991407 if (response.stopReason().map(StopReason.TOOL_USE::equals).orElse(false)) {
1400 // Extract and execute the tool
1408 // Extract and run the tool
14011409 for (ContentBlock block : response.content()) {
14021410 block.toolUse().ifPresent(toolUse -> {
1403 // Execute toolUse.name() with toolUse.input() and return the result to Claude
1411 // Run toolUse.name() with toolUse.input() and return the result to Claude
14041412 });
14051413 }
14061414 }
from line 1437
14291437 );
14301438 
14311439 if ($response->stopReason === 'tool_use') {
1432 // Extract and execute the tool
1440 // Extract and run the tool
14331441 foreach ($response->content as $block) {
14341442 if ($block->type === 'tool_use') {
1435 // Execute $block->name with $block->input and return the result to Claude
1443 // Run $block->name with $block->input and return the result to Claude
14361444 }
14371445 }
14381446 }
from line 1469
14611469 )
14621470 
14631471 if response.stop_reason == :tool_use
1464 # Extract and execute the tool
1472 # Extract and run the tool
14651473 response.content.each do |block|
14661474 next unless block.type == :tool_use
1467 # Execute block.name with block.input and return the result to Claude
1475 # Run block.name with block.input and return the result to Claude
14681476 end
14691477 end
14701478 ```
from line 1866
18581866 $response = $client->messages->create(
18591867 maxTokens: 1024,
18601868 messages: [['role' => 'user', 'content' => '[Unsafe request]']],
1861 model: 'claude-opus-5-5',
1869 model: Model::CLAUDE_OPUS_5_5,
18621870 );
18631871 
18641872 if ($response->stopReason === 'refusal') {
from line 2332
23242332 ```python Python
23252333 def handle_server_tool_conversation(client, user_query, tools, max_continuations=5):
23262334 """
2327 Handle server tool conversations that may require multiple continuations.
2335 Handle server tool conversations that might require multiple continuations.
23282336 
2329 The server runs a sampling loop when executing server tools. If the loop
2337 The server uses a sampling loop to run server tools. If the loop
23302338 reaches its iteration limit, the API returns pause_turn. Continue the
23312339 conversation by sending the response back to let Claude finish.
23322340 """
from line 2349
23412349 )
23422350 
23432351 if response.stop_reason != "pause_turn":
2344 # Claude finished processing - return the final response
2352 # Claude finished processing: return the final response
23452353 return response
23462354 
23472355 # pause_turn: replace the full message list to maintain alternating roles
from line 2358
23502358 {"role": "assistant", "content": response.content},
23512359 ]
23522360 
2353 # Reached max continuations - return the last response
2361 # Reached max continuations: return the last response
23542362 return response
23552363 ```
23562364 
from line 2381
23732381 });
23742382 
23752383 if (response.stop_reason !== "pause_turn") {
2376 // Claude finished processing - return the final response
2384 // Claude finished processing: return the final response
23772385 return response;
23782386 }
23792387 
from line 2392
23842392 ];
23852393 }
23862394 
2387 // Reached max continuations - return the last response
2395 // Reached max continuations: return the last response
23882396 return response!;
23892397 }
23902398 ```
from line 2419
24112419 
24122420 if (response.StopReason != "pause_turn")
24132421 {
2414 // Claude finished processing - return the final response
2422 // Claude finished processing: return the final response
24152423 return response;
24162424 }
24172425 
from line 2434
24262434 ];
24272435 }
24282436 
2429 // Reached max continuations - return the last response
2437 // Reached max continuations: return the last response
24302438 return response;
24312439 }
24322440 ```
from line 2462
24542462 }
24552463 
24562464 if response.StopReason != "pause_turn" {
2457 // Claude finished processing - return the final response
2465 // Claude finished processing: return the final response
24582466 return response, nil
24592467 }
24602468 
from line 2477
24692477 }
24702478 }
24712479 
2472 // Reached max continuations - return the last response
2480 // Reached max continuations: return the last response
24732481 return response, nil
24742482 }
24752483 ```
from line 2505
24972505 response = client.messages().create(params.build());
24982506 
24992507 if (!response.stopReason().map(StopReason.PAUSE_TURN::equals).orElse(false)) {
2500 // Claude finished processing - return the final response
2508 // Claude finished processing: return the final response
25012509 return response;
25022510 }
25032511 // pause_turn: loop again and send the response back
25042512 }
25052513 
2506 // Reached max continuations - return the last response
2514 // Reached max continuations: return the last response
25072515 return response;
25082516 }
25092517 ```
from line 2535
25272535 );
25282536 
25292537 if ($response->stopReason !== 'pause_turn') {
2530 // Claude finished processing - return the final response
2538 // Claude finished processing: return the final response
25312539 return $response;
25322540 }
25332541 
from line 2546
25382546 ];
25392547 }
25402548 
2541 // Reached max continuations - return the last response
2549 // Reached max continuations: return the last response
25422550 return $response;
25432551 }
25442552 ```
from line 2564
25562564 tools: tools
25572565 )
25582566 
2559 # Claude finished processing - return the final response
2567 # Claude finished processing: return the final response
25602568 return response unless response.stop_reason == :pause_turn
25612569 
25622570 # pause_turn: replace the full message list to maintain alternating roles
from line 2574
25662574 ]
25672575 end
25682576 
2569 # Reached max continuations - return the last response
2577 # Reached max continuations: return the last response
25702578 response
25712579 end
25722580 ```
from line 2765
27572765 $response = $client->messages->create(
27582766 maxTokens: 1024,
27592767 messages: [['role' => 'user', 'content' => 'Hello!']],
2760 model: 'claude-opus-5-5',
2768 model: Model::CLAUDE_OPUS_5_5,
27612769 );
27622770 
27632771 // Handle successful response with stop_reason
from line 2814
28062814<CodeGroup>
28072815 ```bash cURL
28082816 # The message_delta event in the SSE stream carries stop_reason.
2809 curl --no-buffer https://api.anthropic.com/v1/messages \
2817 curl -N https://api.anthropic.com/v1/messages \
28102818 -H "x-api-key: $ANTHROPIC_API_KEY" \
28112819 -H "anthropic-version: 2023-06-01" \
28122820 -H "content-type: application/json" \
from line 2940
29322940 $stream = $client->messages->createStream(
29332941 maxTokens: 1024,
29342942 messages: [['role' => 'user', 'content' => 'Hello!']],
2935 model: 'claude-opus-5-5',
2943 model: Model::CLAUDE_OPUS_5_5,
29362944 );
29372945 
29382946 foreach ($stream as $event) {
from line 2989
29812989 )
29822990 
29832991 if response.stop_reason == "tool_use":
2984 # Execute tools and continue
2992 # Run tools and continue
29852993 tool_results = execute_tools(response.content)
29862994 messages.append({"role": "assistant", "content": response.content})
29872995 messages.append({"role": "user", "content": tool_results})
from line 3015
30073015 });
30083016 
30093017 if (response.stop_reason === "tool_use") {
3010 // Execute tools and continue
3018 // Run tools and continue
30113019 const toolResults = executeTools(response.content);
30123020 messages.push({ role: "assistant", content: response.content });
30133021 messages.push({ role: "user", content: toolResults });
from line 3047
30393047 
30403048 if (response.StopReason == "tool_use")
30413049 {
3042 // Execute tools and continue
3050 // Run tools and continue
30433051 var toolResults = ExecuteTools(response.Content);
30443052 messages.Add(new AssistantMessageParam
30453053 {
from line 3088
30803088 return response, nil
30813089 }
30823090 
3083 // Execute tools and continue
3091 // Run tools and continue
30843092 toolResults := executeTools(response.Content)
30853093 var contentParams []anthropic.ContentBlockParamUnion
30863094 for _, block := range response.Content {
from line 3123
31153123 return response;
31163124 }
31173125 
3118 // Execute tools and continue
3126 // Run tools and continue
31193127 List<ToolResultBlockParam> toolResults = executeTools(response.content());
31203128 messages.add(response.toParam());
31213129 messages.add(MessageParam.ofUserOfContentBlockParams(
from line 3150
31423150 return $response;
31433151 }
31443152 
3145 // Execute tools and continue
3153 // Run tools and continue
31463154 $toolResults = execute_tools($response->content);
31473155 $messages[] = ['role' => 'assistant', 'content' => $response->content];
31483156 $messages[] = ['role' => 'user', 'content' => $toolResults];
from line 3173
31653173 # Final response
31663174 return response unless response.stop_reason == :tool_use
31673175 
3168 # Execute tools and continue
3176 # Run tools and continue
31693177 tool_results = execute_tools(response.content)
31703178 messages << { role: "assistant", content: response.content }
31713179 messages << { role: "user", content: tool_results }
Feedback