# End a session

> End one of your sessions, with an optional reason and result (what it reported when it finished: a subagent's final message, up to 8,000 characters, never a tool's output).

<div class="g1t-endpoint"><span class="g1t-method" data-method="post">POST</span><code>/repos/{owner}/{name}/sessions/{id}/end</code></div>

A session.ended event. Ending one already ended returns it as it is, taking `result` if it had none. Its subagents still going end with it (`parent ended`). Its claims are not released: release them, hand the issue off, or let them expire.

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`session`](/reference/mcp/#session) with `action` `end`, and the same inputs
- **Scope:** An access token needs [`pull_requests:write`](/guides/authentication/#scopes).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `owner` | string | Yes | The workspace that owns the repository. |
| `name` | string | Yes | The repository's name. |
| `id` | string | Yes | The session's id (ses_…), from [`start_session`](/reference/api/sessions/start-session/) or [`list_sessions`](/reference/api/sessions/list-sessions/). |

## Body parameters

Send a JSON object. Names are `snake_case`, as in responses; the `camelCase` spelling is accepted too.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `reason` | string | No | Why it ended, in a few words. "ended" if left out. |
| `result` | string | No | What it reported when it finished: a subagent's final message. Kept up to 8,000 characters. Never a tool's output. |

## Example request

```sh
curl -X POST https://api.g1t.sh/repos/flagon-io/hello/sessions/id/end \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "reason": "done"
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "id": "ses_01m4b2c3d4e5f6g7h8j9k0m1n2",
  "repo_id": "rep_01m3m5q6p0e2qaw6mmjahk0qrr",
  "issue": 12,
  "pull": 14,
  "branch": "greet-caller",
  "actor": {
    "id": "usr_01kkntcg1eeb98j62xjm7eh09p",
    "username": "syntaqx"
  },
  "harness": "claude_code",
  "harness_session_id": "5b0c1f9e-3d2a-4e8b-9f61-0c7d2a9e4b13",
  "title": "Make the greeting name the caller",
  "state": "ended",
  "head_commit": "9f2c4e1a7b3d5f60812a4c6e8b0d2f4a6c8e0b13",
  "started_at": "2026-10-12T14:02:11.204Z",
  "last_seen_at": "2026-10-12T14:40:03.115Z",
  "ended_at": "2026-10-12T14:40:03.115Z",
  "end_reason": "done"
}
```

## Errors

A failed request answers with one of these statuses and a body like `{"error": {"code": "not_found", "message": "Repository not found."}}`. See [errors](/reference/api/#errors).

| Status | Code | When |
| --- | --- | --- |
| 401 | `unauthenticated` | A token is required, or the one sent is not valid. |
| 403 | `forbidden` | The token is valid but not allowed to do this, such as a member-only change, or a token without the scope it needs. |
| 404 | `not_found` | It does not exist, or you cannot see it. |
| 409 | `conflict` | The request conflicts with the current state. |
| 422 | `invalid` | The input is not valid. `message` says which field and why. |
