handling-stop-reasons changedbuild-with-claude/handling-stop-reasons
Nearest release: v2.1.310, published 11 hours after 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+2added
Lines−2removed
From line
24
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits23to this page, all time
The whole hunk
from line 24, old and new numbered
/
from line 24
2424
2525The `stop_reason` field is part of every successful Messages API response. Unlike errors, which indicate failures in processing your request, `stop_reason` tells you why Claude completed its response generation.
2626
27```text Example response wrap
27```json Example response
2828{
2929 "id": "msg_01234",
3030 "type": "message",
from line 1484
14841484 With [programmatic tool calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling), the same response shape means something different. The client `tool_use` block comes from code that is running in the `code_execution` tool rather than from Claude directly, and its `caller` field names the `code_execution` block that called it. That code has already started: it is paused waiting for your `tool_result` blocks, and sending them resumes the execution instead of starting a deferred tool. The `code_execution` block's own result block arrives once the code completes, which can take more than one round of tool results. The follow-up user message itself is the same in both cases; with programmatic tool calling, also pass back the `id` from the response's `container` field, as that page shows.
14851485</Note>
14861486
1487```text A mixed tool_use response wrap
1487```json A mixed tool_use response
14881488{
14891489 "stop_reason": "tool_use",
14901490 "content": [
No line in this hunk matches that.