Stop Background Task (Extension)
Request termination of a running task and return its current state.
/agent/v1/sessions/{session_id}/background_tasks/{task_id}/stop● SupportedRequest parameters
session_idstring必填path: Session id (sesn_...), as returned by sessions.create or sessions.list. The same id is also accepted as the session_id query parameter on resource and thread calls, where it must equal the path value.
task_idstring必填path: Background task id (task_...), as listed by sessions.background_tasks.list.
Returns
200
Own-face extension. No request body is required. Uses the same stop implementation as TaskStop: records stop_requested_at and signals the process group. Returns BackgroundTask with the same fields as the list operation. Until termination is observed, status may remain running with cancellable=false. An ended or unsupported task returns 409. Missing or inaccessible sessions or tasks return 404.
Errors follow the Anthropic error format (type / message / request_id) — see error codes
Response
HTTP 200
Current task after stop request
application/json
| Name | Type | Description |
|---|---|---|
| id | string | Identifier of the object, as returned by the API; pass it in the path of follow-up calls on the same resource. |
| kind | string | Kind of background task: bash for a command started with run_in_background, monitor for a Monitor watch. |
| title | string | Short human-readable title of the task or object. |
| thread_id | string | null | Execution thread the task belongs to; null for the primary thread. |
| status | string | Current lifecycle state. |
| started_at | string | RFC 3339 time at which the task started. |
| ended_at | string | null | RFC 3339 time at which the task ended; null while it is running. |
| cancellable | boolean | Whether the task can still be stopped. |
| notified_at | string | null | RFC 3339 time of the latest run that the task's notification started; null while no notification has been delivered. |
| trigger_count | integer | null | For a monitor task, how many times its matches woke the session; null for other kinds or before the first notification. |