Commit 07b46c6
feat: surface terminal_reason on ResultMessage (#1142)
Surfaces `ResultMessage.terminal_reason` on the Python SDK. The CLI
already emits `terminal_reason` on the result frame (`"completed"`,
`"max_turns"`, `"aborted_streaming"`, `"aborted_tools"`, …); the Python
SDK was dropping it. A value of `"aborted_streaming"` /
`"aborted_tools"` indicates the turn was cancelled via
`ClaudeSDKClient.interrupt()`, giving callers an explicit cancelled
marker without a new result subtype. Mirrors the TypeScript SDK's
`SDKResultMessage.terminal_reason`.
Companion docs PR: anthropics/claude-code-docs#4360 (should land no
earlier than the SDK release that ships this).
CHANGELOG entry (for the release cutter to place under the version
header — kept out of this diff because `tests/test_changelog.py` rejects
`## Unreleased`):
```
### Features
- **terminal_reason on ResultMessage**: `ResultMessage.terminal_reason` now
surfaces why the query loop ended (`"completed"`, `"max_turns"`,
`"aborted_streaming"`, `"aborted_tools"`, etc.). A value of
`"aborted_streaming"` or `"aborted_tools"` means the turn was cancelled
via `ClaudeSDKClient.interrupt()`. Mirrors the TypeScript SDK's
`SDKResultMessage.terminal_reason`.
```
**Verification:** ruff check + format clean; `pytest
tests/test_message_parser.py` 75 passed (2 new); full `pytest tests/`
1302 passed, 4 skipped.
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: benlehrburger-ant <benlehrburger-ant@users.noreply.github.com>1 parent ab3b09c commit 07b46c6
3 files changed
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
317 | 318 | | |
318 | 319 | | |
319 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1224 | 1233 | | |
1225 | 1234 | | |
1226 | 1235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
837 | 869 | | |
838 | 870 | | |
839 | 871 | | |
| |||
0 commit comments