session_stop
Request termination of a terminal session started via session_start, optionally waiting for a result. Use it to stop running work and then poll session_read for final output.
Instructions
Request termination of a terminal session created by session_start. Requires its session_id and, with management access (including stdio and no-password mode), its owning client_token; it cannot stop a session owned by another token. Stopping can interrupt writes and lose unsaved work, and cannot undo completed side effects. wait_ms defaults to 1000 and can be 0-20000: 0 returns immediately after sending the request, otherwise wait up to that many milliseconds for a terminal result. accepted=true means a stop request was sent or is already pending, not that termination is confirmed. status=stopping and done=false require polling session_read until done=true; use its output/cursor to collect final output. status=stopped requires a terminal canceled=true report. status=finished means the session ended for another reason; inspect canceled, timed_out, exit_code and error, especially on disconnect. Repeating a stop is safe: an already-ended session returns already_done=true and accepted=false without sending another request. Unknown or unauthorized session IDs are errors. Use session_read to observe progress and session_write for input; stopping does not revoke the device token or disconnect other sessions.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wait_ms | No | How long to wait for a terminal result after requesting cancellation (0-20000 ms, default 1000). 0 returns a status snapshot immediately; stopping requires subsequent session_read polling. | |
| session_id | Yes | Session identifier | |
| client_token | Yes | Target client connection token, required with management access (including stdio and no-password mode). Device-scoped bearer access implicitly selects its own token. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| done | Yes | True once this session has a terminal result or its device connection closed. Check status, canceled and error to distinguish confirmed cancellation from other endings. | |
| error | No | Optional execution or connection error. A disconnect does not prove the remote process completed successfully. | |
| status | Yes | stopping: request pending; poll session_read. stopped: terminal cancellation confirmed. finished: ended for another reason; inspect terminal fields and error. | |
| accepted | Yes | True if a cancellation request was sent or is pending. False for a session already ended before this call. This alone never confirms termination. | |
| canceled | No | True only when the target reported cancellation; a disconnect alone does not confirm cancellation. | |
| exit_code | No | Reported process exit code: 0 means success; -1 means execution failed, was interrupted, or the device disconnected before a normal exit report. | |
| timed_out | No | True if the target reported that the process execution timeout elapsed. | |
| session_id | Yes | Identifier of the owned session; retain it for subsequent read, write and stop calls. | |
| next_action | No | Next step to perform. Invitation creation returns the exact tool call and deadline; other tools return human-readable guidance. | |
| already_done | Yes | True if the session was already ended when this stop call began; no new cancellation request is sent. |